Mastering Home Assistant Templates: Intro to Date and Time

Поділитися
Вставка
  • Опубліковано 15 лип 2024
  • 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:
    Home Assistant Docs on Time/Date Templating: www.home-assistant.io/docs/co...
    Python Time String Formatting Options: docs.python.org/3/library/dat...
    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:
    Github - github.com/thejeffreystone
    Twitter - / thejeffreystone / / slackerlabs
    On the Web - slacker-labs.com/
    Discord - / discord
    And if you like this video you could always fuel my automation habit -
    Grab SlackerLabs Merch: slackerlabsmerch.square.site
    One Time Donation:
    Paypal: www.paypal.com/paypalme/Slack...
    Cash App: $slackerlabs
    Buy me a coffee: www.buymeacoffee.com/icE6DeBut
    .
    Or use my Amazon affiliate link which provides a small commission on things you buy without additional cost to you - www.amazon.com/s/ref=as_li_ss...
    Video Gear:
    Canon m50: amzn.to/3ftldPH
    Desk Mic: amzn.to/3wkum40
    Camera Mic: amzn.to/3tXk1cp
    Newer 660: amzn.to/3fwwejd
    Dazzne D50: amzn.to/3oGBK5y
    Audio Interface: amzn.to/3u07chK
    Gimble: amzn.to/3ouKAoe
    Music - Epidemic Sound: www.epidemicsound.com/referra...
    Video Assets - LenoFx: i.refs.cc/CJXU6Da9?smile_ref=e...
  • Наука та технологія

КОМЕНТАРІ • 35

  • @tsangdanny
    @tsangdanny 11 місяців тому +4

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

  • @mastweiler22
    @mastweiler22 11 місяців тому

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

  • @michaelhallmann1259
    @michaelhallmann1259 11 місяців тому

    Awesome! Thanks for this video!

  • @daveforrester61
    @daveforrester61 11 місяців тому

    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.

  • @phea0001
    @phea0001 11 місяців тому

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

  • @Joseph-ko2kl
    @Joseph-ko2kl 11 місяців тому +1

    THIS IS VERY HELPFUL! THANKS

  • @bgable7707
    @bgable7707 11 місяців тому

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

  • @BeardedTinker
    @BeardedTinker Рік тому +1

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

  • @dickvanwoudenberg2919
    @dickvanwoudenberg2919 Рік тому

    Great job Jeff, it was very helpfull to me

  • @NunoSoares22
    @NunoSoares22 Рік тому

    Superb Jeff!

  • @horatiuslavescu
    @horatiuslavescu 11 місяців тому +4

    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.

  • @rickz6006
    @rickz6006 11 місяців тому +1

    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.

    • @SlackerLabs
      @SlackerLabs  11 місяців тому

      Yea. And I think the way home assistant does sensors makes harder since it’s not always clear when you are working with an actual date value that you can use date functions in versus a string of text that needs to be converted

  • @davidmankin4500
    @davidmankin4500 11 місяців тому

    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.

  • @ChrisValcke
    @ChrisValcke 8 місяців тому

    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..

  • @davidmankin4500
    @davidmankin4500 11 місяців тому

    Thanks!

  • @sekt1953
    @sekt1953 7 місяців тому +1

    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.

  • @PatrickBulteel
    @PatrickBulteel Рік тому +1

    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.

    • @SlackerLabs
      @SlackerLabs  Рік тому

      Yeah, I definitely need to take some time taking advantage of all the new stuff. So many recent improvements that will make life easier.

  • @MihaiKrieger
    @MihaiKrieger 11 місяців тому +1

    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.

  • @niklasb2007
    @niklasb2007 11 місяців тому

    Thanks

  • @adammourad1873
    @adammourad1873 Рік тому

    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

  • @rag7628
    @rag7628 6 місяців тому

    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.

  • @jagadeeshv2763
    @jagadeeshv2763 11 місяців тому +1

    wow, nice video ... very helpful
    one help...... 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

  • @TheCelticbeast
    @TheCelticbeast 11 місяців тому

    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.

    • @SlackerLabs
      @SlackerLabs  11 місяців тому +1

      In terms of what home assistant sees as true no. It does matter when testing the values in a if statement. Because case matters. But {{ 1==1}} would output as True but if I did it the long way and used an if statement and if 1==1 then true it wouldn’t technically be a Boolean type. Just a string that said “true” but in terms of a binary sensor either could be the output of a template and turn the binary sensor on.
      I prolly just made that more confusion. In python terms boolean types can only be True or False. Home assistant is a little more forgiving.

  • @MaxGoddur
    @MaxGoddur 11 місяців тому

    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.

  • @jmr
    @jmr Рік тому +2

    I should have saw that "now" clip coming. 🤦‍♂️
    Now is complicated subject. He could have spent 8 hours on this and not covered everything. Excellent starter though.

    • @SlackerLabs
      @SlackerLabs  Рік тому +1

      So the original script had way more references to that... haha

    • @jmr
      @jmr Рік тому +2

      @@SlackerLabs I told Franck Nijhof his " Swartz is as big as mine" the other day on the live. He was clueless what that meant. 😆

    • @SlackerLabs
      @SlackerLabs  Рік тому

      Haha. I thought everyone knew Mel Brooks’ Movies word for word?
      Maybe it’s just me. I prolly shouldn’t mention my shop vac is named MegaMaid. Cause I can switch her from suck to blow…