Mastering Home Assistant Templates: A Beginner's Guide

Поділитися
Вставка
  • Опубліковано 6 лип 2024
  • Home Assistant Templates 101
    Let's walk through everything you need to know to get started making templates. I explain the foundational blocks of templates, walk you through how to transform your home assistant data using math, and wrap it up giving to a look at some different ways you can use templates.
    If you feel overwhelmed with #homeassistant templates, dont worry. After this video you will have everything you need to get started.
    Code Examples:
    Example Sensors:
    github.com/thejeffreystone/ho...
    Jinja Examples from Temaplte Panel:
    gist.github.com/thejeffreysto...
    Today Is / Month Is:
    github.com/thejeffreystone/ho...
    Jinja Resources:
    Crash course for Beginners:
    ultraconfig.com.au/blog/jinja...
    Full Jinja Documentation (Use Search when needing syntax for functions):
    jinja.palletsprojects.com/en/...
    Video Chapters:
    00:00 - Home Assistant Templates 101 - Intro
    01:10 - Home Assistant Template Updates as of 2023.4
    01:44 - What is Jinja?
    03:07 - Template Basics: What do those Curly Braces mean?
    06:57 - Home Assistant Entities in Templates
    11:44 - Transform Home Assistant Entities using Templates
    17:22 - Advance Templates - A Quick Look
    23:00 - More to Come
    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...
  • Наука та технологія

КОМЕНТАРІ • 103

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

    What parts of home assistant templates are giving you the most trouble?

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

      What is giving me trouble is how can I use templating to send a custom notification message?

    • @mrxmry3264
      @mrxmry3264 Рік тому +4

      My problem was understanding how to use them, but I think this video got me started.

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

      Time calculations. working with datetime helpers, timers. working out percentage of time remaining. determining difference betweeen two input_Datetime helpers etc

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

      @@ByStand3R this. Dealing with templates (or automations) that are predicated on prior events e.g. "if the door sensor was activated less than 30 seconds ago".

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

      ​@@eugsmiley That's a pain but a really important use case. I still have to go back and reference code for that. Notifications can get really complicated with icons, actions, urls, persistence, priority, retries, sounds,............... Don't worry though! You don't need to include all those things! 😅

  • @vicb2389
    @vicb2389 Рік тому +16

    Dark mode may be good when you are on the box but in this video light mode would've been better I think. The change in colour helped but the original colours were difficult.

  • @chimeranzl9147
    @chimeranzl9147 3 місяці тому +1

    Dude you're a legend, I only needed 10 mins of your video to make complete sense of a template sensor I was struggling with!

  • @user-gn2ll7ds9s
    @user-gn2ll7ds9s Рік тому +11

    Jeff, you are an awesome educator! I have struggled with templates for ages spending so much time getting my head around things in the template development panel testing and retesting until I understood why things didn't or by some fluke worked. In this one video you broke through 3 years of my lack of understanding of some very simple basic format rules eg: {{ }} {% %} and | int and also the >. I have to also admit that your Github pages are awesome examples. I take my hat off to your presentation and education magic. Thankyou.

  • @samuraiintellectual
    @samuraiintellectual Рік тому +10

    Great Video! It could be improved by using a different color scheme for your console (maybe that's not even possible). It was really hard to read.

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

    This is the jinja video I always wanted when starting out. Great work!

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

    Super straight forward guide! Thanks Jeff!

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

    Thanks for the simple guide to templates. Although I am already using them, I copied most of the code without fully taking in what they did. You have clarified the usage in an easily understandable way. I am looking forward to the next video!

  • @OPB682
    @OPB682 Рік тому +4

    Excellent job.
    More Jinja videos please. A whole series (4-5) would be great

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

      Right on! I had planned just one other. Then I got scripting and realized I have more to cover. So I suspect it will be a few more. And I am going to try to make them shorter. Focus on a specific thing with each one.

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

    Thanks so much Jeff - this is the most helpful Templates video I have seen. I have managed to cobble together 1 on my own, but did not fully understand why it worked when the 22 non-working attempts preceding the success failed. This explains it for me. Well done!

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

    This is the best video I've ever seen on templating! It really unlocks the potential of HA, and it's always where I struggle the most in my projects. Well done!

  • @philippe5394
    @philippe5394 4 місяці тому

    Hello,
    You've just shown me just how powerful and interesting these templates can be! Many thanks!

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

    Thanks! This video was awesome and helped clear a few things up for me. And I love your solution for Day of Week / Month of year - excellent implementation.

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

    I created a notification for when each member of my household is home based on some stuff you did before, and it was a pain to try to get it to be generic enough to not repeat a lot of code. I was able to convert it over to a macro easily and it makes things smoother. As a programmer, I hate duplicating stuff, even yaml. Can't wait to see your video on macros for more ideas to automate my home!

  • @Joseph-ko2kl
    @Joseph-ko2kl Рік тому

    Thank you! Been looking for a primer like this. I really hope you continue on with follow on vid's on this.

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

    Jeff, your videos and GitHub repo have given me so many ideas on things I can do in HomeAssistant. Keep up the great work!
    BTW, everyone loves my “Automate the boring stuff” t-shirt

  • @atabatabaee
    @atabatabaee 7 місяців тому

    Thank you for creating such an insightful and engaging video, I really enjoyed and learned a lot from it

  • @edwaaij4752
    @edwaaij4752 5 місяців тому +1

    Clear explanation. The added yaml code and the sequel are important reasons to continue following this series of videos. Thank you very much. I have learned a lot and hope for more. Tip: the yaml code on the video is difficult to read. Better contrast letters and background color will help.😀

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

    This is Amazing start for templates, always scared to look at temples, but not anymore 😮

  • @gerardschepers3744
    @gerardschepers3744 4 місяці тому +1

    very useful, would like to see a sequel

    • @SlackerLabs
      @SlackerLabs  4 місяці тому

      I got 3-4 videos in this series. Should be a playlist of them.

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

    I really appreciate the effort to make this tutorial and the effort it took to figure out where to start to help those of us who have no formal education in coding. I have used cut/paste then trial/error coding for HA for years, now I already have way more understanding of what I am doing and how to do it.

  • @KaiKai-uz4tf
    @KaiKai-uz4tf Рік тому

    Wonderful video, thank you!

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

    Great tutorial

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

    useful I was shying away from templates now i think I can try atelast. Need more of these type

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

    Jeff - Love it... Looking forward to the next video... I am looking to build templates that bridge my Accurite sensors (rain in particular) to my Home Assistant dashboard... Really linking your SDR video on sensors to tracking things like rain on a day, week, month basis...

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

      I'm slowly getting back to it. Bronchitis has made my voice pretty rough so I just got to the point where I think it wont sound too bad.

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

    Let's get that next video on this topic!!! Great info!
    One way I use templates a lot is in automations. I'll create an automation and then need another one very similar. I duplicate the automation and edit the yaml of the copy.
    Sometimes it's also easier to write logic for an automation in yaml. Then I select template as a condition in the automation and slap the yaml in there. I did that last night because I needed a true or false based on a bunch of math.
    Also .. as mentioned.. notifications! HA still doesn't have a good gui to create dynamic notifications.

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

    another great video. I am looking forward to the next video with the advance templates in it. would love it to work more with the TTS side and your scripts macros. still unable to get my head around your old videos. its like the initial step or a middle step or section of knowledge is missing for me and I struggle to continue

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

    Thank you, I think I need to hunt through your other YAML videos so I've a better grasp of the fundamentals... Then I'll research getting the mean value of a very spiky "uv" sensor that I might be able to use when it's darker rather than using sunset. 🙂

  • @JoshuaNiland
    @JoshuaNiland 11 днів тому

    Subscription well earned. Great content!

  • @steveelves3499
    @steveelves3499 2 місяці тому

    Good information, Jeff. May I make a small suggestion: don't use the dark theme for showing code, since red lettering almost disappears on an black background.

  • @knelletv
    @knelletv 3 місяці тому

    Such a Teacher ! Thanks ! I definitely subscribe to your UA-cam channel ! 👍

    • @SlackerLabs
      @SlackerLabs  3 місяці тому

      Thank you! I see paces I need to improve, but I'm glad even with my fumbles it helps!

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

    Thank you Jeff!!!!!

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

      I hope it helps and doesn't make things more confusing. I debated just walking though different types of templates. So if I missed something let me know.

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

      @@SlackerLabs This is a great start and is helpful! Thank you

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

    I always avoided templates because jinja isn’t my favorite but your advanced templates definitely gave me some awesome ideas I may try out.🙌🏾
    Question: does hone assistant allow you to create sensors dynamically? Let’s say …as part of an automation?

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

      well, I am not sure it does, in the way I think you are asking. But a pattern I used a lot is I create a MQTT sensor that is simply watching a MQTT topic, and then I have an automation that does a lot of this jinja stuff and simply published the result to the MQTT topic. It doesn't have a way to actually create the sensor. But I do some stuff like have a sensor that the value is lets say the record high temp for my house in a year, and each night an automation kicks off and does some jinja math to figure out if the day's high temp is greater than the current record, and if it is updates the record high sensor.

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

    I started using Chatgpt to write templates for automations in home assistant. It has been a really big improvement for a lot of my automations, since I don't know how to write them.

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

      I haven't played with ChatGPT yet...at least not in terms of smart home. But given that Python and jinja2 is pretty widely used I suspect it might be pretty good at it.

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

    Thanks, ❤ the greater than sign.

  • @tiranhay
    @tiranhay 9 місяців тому

    Thanks

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

    "repeating of course" nice one ;-)

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

    Great video. Hope the advanced template video will follow soon. Question:is there a way to include template in lovelace entity cards eg to change the icon color?

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

      I’m not sure on the color change. I know you can change icons if you are using something like the markdown card. But I’m
      Not sure on color.

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

    I've learned a lot by going through your config and this clears things even more. I have a question though, how often do you have to go back to maintain these due to upgrades? For example, sensors can have a device class, units, etc.

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

      For most of them it’s a set it and forget it. But I did find some as I was working on gathering examples for my next video that were pointed to entities that didn’t exist anymore. So I definitely need to come up with a way to notify me on those. But honestly most I don’t have anything to do once they are built. Only when source entities change.

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

    i'm really hoping you have something in the advanced video regarding the alexa media player stuff... cuz i've been trying forever to create sensors for a bluetooth device connected (attribute "connected_bluetooth") to each one.... but apparently there's no way i can find to disclude the 'null' value which exists when nothing is connected...

  • @brettautrey4117
    @brettautrey4117 2 місяці тому

    Very good at instructing. Thanks. I found this very helpful to get started on templating. BTW, you are wearing a Dallas Stars hat, are you in Dallas area? I am thanks again.

  • @russellmm
    @russellmm Рік тому +3

    I was watching your new video so had to go back to this one first. Great introduction but for someone new to HASS the actual process of going from the template editor to an actual file (I see you use sensor.yaml but have no idea of the creation process and how to ensure HASS even knows it exists) and how HASS starts using that template file. For example, I on the YAML tab you had the Sensor reload option, I do not. I realize its because I don't have a sensor.yaml file. Is it as simple as creating the file and then HASS knows it exists or do I need to do some kind of include in the configuration.yaml file?

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

      You can really do it one of three ways, and it comes down to how you want to lay out your configuration files. You could just add it to your configuration.yaml file. Where your just drop a sensor: heading and then start adding it under that. Or you could fancier with your organization. I threw together a gist that shows the different ways to set them up. But yeah you will have to manually add a line so that home assistant includes it. gist.github.com/thejeffreystone/3f11aaf75fd95175b674f98e030507af

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

      @@SlackerLabs thanks!

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

    You've set-up a nice video teaching templates. The problem is you are teaching the traditional style templates that are no longer supported. The new standard was installed a couple of years ago and HA Docs say that you should not use the old standard, and should use the new format.
    The good news is that the new standard makes a lot more sense logically. Instead of templates inside of a bunch of other integrations, it has it's own integration. Your next video should be showing everyone how to convert from the old format to the new format.
    Then one of the templates you wrote here would look like this:
    template:
    sensor:
    name: basement_temp_celsius
    unique_id: randomchrshere
    state: >
    {{ ((states('sensor.basement_air_device_temperature') | int - 32) / 1.8) | round }}
    unit_of_measurement: "°C"
    icon: "mdi:thermometer
    attributes:
    friendly_name: Basement Temp C
    Availability is there as well if you want it. There is a much richer option set and a much more logical location of the info. Please look at the HA Template docs for more details, YT will not let me post links here.

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

      Dont worry. There is a method to my madness.

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

    Has something changed in HA as the example you used to show a TypeError when converting F to C now works and returns a number in the Template editor?

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

      In my current system nope. It still gives me a type error if I try to subtract 32 from my temp sensors without the | int

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

    @ 10:25 you mention saving the template. How is this done? I don't see a save button, nor do I see a "template entities" line, (under the "YAML" tab)

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

      Yeah, I can't remember what got me here, but the beginner's guide is missing some things. The YAML I am referring to is the YAML configuration files. And the save ability is based on whatever tool you use to edit those YAML files.

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

    Thanks!!! I've been wanting to learn about templating and now I know!!
    How does the "energy" part of the light work? Is this part of a particular light you have or is this a new feature in HA that I haven't run across?

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

      Yea, it's an attribute as part of that light bulb. I think it's a Sylvania zigbee bulb.

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

      @@SlackerLabs you forgot the unit (kWh).

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

    Hmm... I've been looking for a way to display wind chill.

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

    So "Template Entities" is not an option under "YAML configuration reloading" and if I reload "ALL YAML CONFIGURATION" my template still doesn't show up in the states tab?

    • @jdb6284
      @jdb6284 10 місяців тому +1

      same for me

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

    Liked - and implemented - your counter stats idea but didn’t like the fact those were not numeric sensors. Today you showed a way to change this in your latest video: add an empty unit (unit_of_measurement: “”)

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

      What are you doing with the sensors that you need them to be numeric? I am only using mine in the dashboard, but curious what other use cases for that data might be.

  • @StephenEllwood
    @StephenEllwood 11 місяців тому +2

    You seem to make a big jump from writing a script to storing the script. You suddenly say that you can open sensor.yaml but where is this stored? I am using docker on a NAS and can see the file system but sensor.yaml does not exist. Can I created it and if so where in the filesystem should I do this?

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

      Yep. You are right. Holy crap. 🤦‍♂️
      Yes you can just create it. Then you will need to tell home assistant that you are going to use it. So in your configuration.yaml file you will need a line like:
      sensor: !include sensor.yaml

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

      @@SlackerLabs So I did this and created a sensor but it does not show up. Code is:
      - platform: template
      sensors:
      gas_usage_total_kwh:
      friendly_name: "Total Gas Used kWh"
      value_template: "{{( states('sensor.gas_meter_gas_consumption') | int/1000*11.36267) | round(2)}}"
      but I see nothing. How can I tell if it is there?

  • @major_west
    @major_west 3 місяці тому +1

    Great tutorial, but isn't this the "legacy" way of coding templates? Should I be using the modern template format going forward and start converting my legacy templates to the new format?

    • @SlackerLabs
      @SlackerLabs  3 місяці тому

      Yea. I would use the more modern one if nothing more than it's organized better. I talk about the more modern format in later videos in that series.
      But given the amount of tutorials out there and how stuff on the internet lasts for ever knowing the legacy format will be good too.

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

    Hi, do you know why for weekday it is with () => {{ now().weekday() }} and for month without () => {{ now().month }} ? Thanks for your videos.

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

      Well, I am not a computer science guy, so I may get this technically wrong. But it is a python thing. So weekday() is a function from the date time python library that returns the numeric value of the week day based on a date. So Monday = 0 and Sunday = 7. But the date time library also lets us access each element of the date time using that dot notation. So now().month just returns the month from whatever date time is passed to it. now().day would return the day of the month of the current time , so if now() = 2023-04-29 12:15:45 the now().day would get 29. I always considered it a short hand method for splitting up a timestamp. So I didn't have to do some crazy stuff if I just wanted to get part of it for a condition check. now().month, now().day, now().year, now().hour, now().minute, and now().second all work to get a single part.

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

    I’m not quite sure what happened to the chapters in the video, but it seems that those didn’t quite come through in the video player’s UI?

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

      It looks like Jeff only did them as text in the video description.
      Video Chapters:
      00:00 - Home Assistant Templates 101 - Intro
      01:10 - Home Assistant Template Updates as of 2023.4
      01:49 - What is Jinja?
      03:07 - Template Basics: What do those Curly Braces mean?
      06:57 - Home Assistant Entities in Templates
      11:44 - Transform Home Assistant Entities using Templates
      17:22 - Advance Templates - A Quick Look
      23:00 - More to Come

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

      Oh. Nice. Copy paste for the win

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

      @@SlackerLabs Ah, right on!

  • @djjaysmith
    @djjaysmith 9 місяців тому

    Thanks, very useful, but I wish you wouldn't use dark theme for such demos. When viewing the video not full screen then it is very difficult to read the dark red text on a black background. Even in full screen it is often not totally clear, which is not helped by video compression.

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

      Yeah, I updated it later based on feedback like this. I love feedback like this, so if you notice any other areas where it could be made easier to understand let me know!

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

    21:30 the month of July is missing. Why?

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

      Typo from when I was adding it back in....didn't even miss it evidently...

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

      @@SlackerLabs love your vids!!!

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

    So the order of operations for pipe is before math. Who's have guessed it. I bet all my calculating templates are wrong

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

      Well it simply breaks takes the value before it and passes it directly to the function after. So if you need to do a bunch of math prior to passing the value to a function you will
      Need to wrap everything before it in ()

  • @jean-francoiscyr8515
    @jean-francoiscyr8515 Рік тому

    For those interested, here is the template coding to display a clickable Google Maps link of a device_tracker object in a Markdown Tile
    {% set fLat = state_attr('device_tracker.jf_cell', 'latitude')|float %}
    {% set iLatEnt = (fLat|int) %}
    {% set iLatMEnt = (((fLat - iLatEnt)|float * 60)|int) %}
    {% set fLatS = '{:04}'.format('%.1f'|format(((((fLat - iLatEnt)|float * 60) - iLatMEnt)|float) * 60)|float) %}
    {% set fLon = state_attr('device_tracker.jf_cell', 'longitude')|float %}
    {% set fLon2 = 0 - fLon %}
    {% set iLonEnt = (fLon2|int) %}
    {% set iLonMEnt = (((fLon2 - iLonEnt)|float * 60)|int) %}
    {% set fLonS = '{:04}'.format('%.1f'|format(((((fLon2 - iLonEnt)|float * 60) - iLonMEnt)|float) * 60)|float) %}
    {% set iLonMEnt = '{:02}'.format(iLonMEnt) %}
    Position : [Google Maps](www.google.ca/maps/place/{{iLatEnt}}%C2%B0{{iLatMEnt}}'{{fLatS}}%22N+{{iLonEnt}}%C2%B0{{iLonMEnt}}'{{fLonS}}%22W/@{{fLat}},{{fLon}},18z) ({{state_attr('device_tracker.jf_cell', 'latitude')}}, {{state_attr('device_tracker.jf_cell', 'longitude')}})

  • @user-te1go5ll3m
    @user-te1go5ll3m 2 місяці тому

    can i get an email for you jeff. i am from the bahamas and need a direct contact from you for a step by step guide

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

    For getting the weekday or things like that I've used now().strftime('%B'). There's a list of all the % arguments out there, but that's how I conveniently desplay time and date on my dashboard is a '%A, %B %d %Y' which gets me Weekday, Month Day Year

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

      Yeah and for anyone reading this, you could totally use that in that template sensor instead of the craziness I did if you want to create a sensor to use everywhere so you dont have to remember all the string from time function arguments..