Mastering Home Assistant Templates: Intro to Date and Time

preview_player
Показать описание
The next installment of my Mastering Home Assistant Templates Series.
This video is all about time and date. We will be covering:
- How to get the current time and use it in your templates.
- Saving time for use later in templates
- How to do timestamp Math
- the difference between the last_changed and the last_updated timestamps
- When to use as_datetime and as_timestamp
- And how to compare two points in time
- So we know how many days until a date
- If a date was in the past
- if a date is in the future
- Did it happen in the last 24 hours
- Or is it happening today

Lots to cover, so this one is long. So use the chapters below to jump around:

Video Chapters:
00:00 - Introduction to Time and Date Templates in Home Assistant - Intro
01:18 - What to Expect in this video
02:31 - Quick Jinja Recap
04:40 - Using Now() to get the current time
06:20 - Create a TTS Greeting using Now()
08:16 - Saving the current time of events to use later in templates
13:29 - Using Replace() to get a specific point in time based on current time
16:46 - Home Assistant's time and Date Integration provides some helpful entities
19:25 - Using an entity's last changed and last updated timestamp in your templates
21:17 - Intro to Timestamp Math in your Templates
22:51 - The difference between as_datetime and as_timestamp and when to use them
25:49 - Using as_timestamp to get the number of days until a date in the future
28:27 - A Template to check if a timestamp happened in the past
29:57 - A Template to check if an Automation fired in last 24 hours
31:16 - Using relative_time() to get how much time has past since a point in time
32:00 - Check to see if a calendar event is happening today

Resources:

Who am I?

My Name is Jeff. I am an DIY-er and Automator of boring things. And, of course, a huge Home Assistant fan. Oh, I also live in a house that tweets.

Follow Me:

And if you like this video you could always fuel my automation habit -

One Time Donation:
Cash App: $slackerlabs
.

Video Gear:

Рекомендации по теме
Комментарии
Автор

Great video. These types of videos bridge the gap from beginners and experts. Keep them coming.

tsangdanny
Автор

Very informative, thank you! Love these type of videos, super helpful!

blakebowden
Автор

Thank you, Jeff for these useful tips. About using 24h format, and ISO format: that's not a caveat at all, it is the normal and logic way to use. This format avoids any confusion.

horatiuslavescu
Автор

Brilliant, thanks Jeff. You're right, that is enough to be getting on with 😆. It has certainly increased my awareness of date and time entities. Looking forward to the next video in the series.

daveforrester
Автор

Thanks for the video. Just beginning my templating and scripting journey.
Super helpful!! Looking forward to the next one.

phea
Автор

Awesome Video Jeff!!!! I now just need a bit of time to check what I can improve ;)

BeardedTinker
Автор

Nice, saved as a reference for future tinkering. Date time math is always interesting due to formatting differences based upon the systen language. I once added a leap year test for a label applicator program so I could accurately set expiration dates on a bundle label due to Feb 29th and the year 2000 not being a leap year, the math interesting, had fun with it. This was in an Opto 22 Mystic processor.

rickz
Автор

Thank you for doing this series, it's being a great help!

mastweiler
Автор

Super helpful. Thanks. Even as an experienced python programmer I still get quite stuck doing this in home assistant, probably because there are at least three things going on and each has its own way of doing things: python, jinja2 filters, home assistant’s way of thinking about dates (sometimes strings, sometimes ints, sometimes dates, sometimes datetimes).

Besides HA becoming more uniform, what would help me is some easier debugging tools. E.g. a jinja type-tagging filter that would print “datetime(2020-01-01 01:01:01)” or “str(2020-01-01 01:01:01)”. Then I would use this in the template tool to figure out what I have.

davidmankin
Автор

Great video. One thing you should start looking at is the custom_templates directory which allows you to move your macros into a file in that directory. I've been moving a lot of the jinja (especially the ones that are "duplicated" around) into individual files and just calling them when I need them. Works really well.

PatrickBulteel
Автор

Keep it up, you make some really good videos, but I need all your 'Master Home Assistant Template' videos to be grouped together so they're easier to follow when you get in the middle of a series, but really Thank you very much for the good videos.

sekt
Автор

Can't wait to see the entities video !!!

bgable
Автор

Jeff, thanks for the great info (don't worry about video metrics, templates require a bit of effort :). look forward to next one in the template series..

ChrisValcke
Автор

This was a great video, but I have a question for you, is it possible to change a helper date time from within a template? Is it possible to call the set date time service from a template?

tonyseeley
Автор

The main thing I noticed about these templates is that, first and foremost, you have to absolutely know EXACTLY what you intend to display, create or find out. Otherwise it gets very confusing very quickly if the end result is not clearly defined in your head.

MihaiKrieger
Автор

Hey Jeff, I discovered recently your videos and I must say they are really great and super helpfull. Thank you very much for your GREAT work..
Question: You mentioned at 08:30 that You have already done some previous videos with day time helpers, on how to use them to provide an easy way to update trigger time for automations, like your daily announcements. I want to build somthing similar to start my washing machine at a specific (triggered) time on a dashbord card. But I didn't found your viedeo with the day time helpers, could you please give me the link for this videos. Thank you very much.

rag
Автор

I think this may be just what I need.
Is there a difference between a Boolean with a capitalized first letter and a lowercase? You have 'True' and 'true' as your outputs.

TheCelticbeast
Автор

wow, nice video ... very helpful
one Using a template, how to get the max valve reached in a day from one sensor. ex: today's max temperature.
I want to record it in Google sheet, but I don't know how to get it from the template

jagadeeshv
Автор

Thank you Lewis! for the information, Great video! well done i have some media issues and CCTV that i don't know they don't work for me is it possible to get you to have look at for me please much appreciated

adammourad
Автор

I have become so frustrated with getting the ESP32-CAM and ESP32-CAM-mb functioning it has ruined two days of what is supposed to be fun.
I run Home Assistant and ESPhome on my Windows 11 machine. I started by buying a few ESP32-CAM boards along with the motherboard (which contains the serial chip) called the ESP32-cam-MB.
Plugged one into the USB port with my heavy-duty power hub and cable. Now I don't pretend to understand all the htpps security setup part of using serial port but followed the suggestions with in ESPhome.
OK hardware connected was step 1.
Step 2: open Home Assistant in my web browser.
Step 3: Open ESPhome and click on the green button labeled "+ NEW DEVICE".
A screen comes up informing I am not running https so alternatively I can use "ESPHome Web" to prepare a device for being used with ESPHome using this computer."
Step 4: OPEN ESPHOME WEB
This step opens a new window in your browser and says:
ESP Device
Connect the ESP32 or ESP8266 to your computer and click on connect to start managing your device
I select CONNECT (only option is to select is connect)
I am then presented with another screen stating
Web.esphome.io Wanst to connect to a serial port.
Just below the above information is my serial port.
USB2.0-Ser!(com3)-paired
The only option now is to select the port and press CONNECT.
I am presented with another small dialog box stating:
web.esphome.io says:
Failed to execute 'open' on 'SerialPort': Failed to open serial port.

I have tried new drivers, new beefed up USB hub with 5 amps capability, different tested cables and finally multiple ESP-32-cam and ESP32-cam-md's.

If anyone one knows of a solution I would love to hear about it also I have searched via google for videos and write up to no avail.

Thank you.

PS some suggestions were to hold down the boot button while powering on that did not yield any positive results.
While others suggested holding down the boot and IO buttons release one aft the other did nothing to resolve the issue.

MaxGoddur