Mastering Home Assistant Templates: A Beginner's Guide

Поделиться
HTML-код
  • Опубликовано: 15 окт 2024

Комментарии • 109

  • @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 Год назад +18

    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.

  • @AndrewDanne-z3o
    @AndrewDanne-z3o Год назад +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.

  • @singaporepastor
    @singaporepastor Год назад +4

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

  • @chimeranzl9147
    @chimeranzl9147 7 месяцев назад +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!

  • @steveelves3499
    @steveelves3499 5 месяцев назад +1

    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.

  • @PauloAbreu
    @PauloAbreu 5 дней назад

    One year later and this video is still great! Thanks!

  • @samuraiintellectual
    @samuraiintellectual Год назад +11

    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.

  • @OPB682
    @OPB682 Год назад +5

    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.

  • @edwaaij4752
    @edwaaij4752 9 месяцев назад +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.😀

  • @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!

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

  • @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!

  • @StephenEllwood
    @StephenEllwood Год назад +3

    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  Год назад +3

      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 Год назад

      @@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?

  • @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!

  • @philippe5394
    @philippe5394 7 месяцев назад

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

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

  • @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!

  • @k9slover
    @k9slover Месяц назад

    Very good video. Well presented and well explained. I am new to HA and frequently get stuck. I have subscribed.

  • @mastweiler22
    @mastweiler22 Год назад +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. 🙂

  • @lawjamesr
    @lawjamesr Год назад +2

    Super straight forward guide! Thanks Jeff!

  • @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

  • @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!

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

  • @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

  • @brettautrey4117
    @brettautrey4117 6 месяцев назад

    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.

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

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

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

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

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

  • @atabatabaee
    @atabatabaee 10 месяцев назад

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

  • @narshimagoudpalakurla9651
    @narshimagoudpalakurla9651 Год назад

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

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

  • @major_west
    @major_west 6 месяцев назад +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  6 месяцев назад

      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.

  • @ac-fs2dc
    @ac-fs2dc Месяц назад

    Grazie per le spiegazioni sempre molto utili e chiare !
    🤗

  • @gerardschepers3744
    @gerardschepers3744 8 месяцев назад +1

    very useful, would like to see a sequel

    • @SlackerLabs
      @SlackerLabs  8 месяцев назад

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

  • @bat3332
    @bat3332 Год назад

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

  • @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 Год назад +1

      same for me

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

  • @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).

  • @ionbuilds
    @ionbuilds 3 месяца назад

    Is it possible to use SimpliSafe "keypad/control panel" with "Alarmo" as local alarm service. I see all the sensor when I added Alarmo in my HA except for the keypad. (Don't see it in hidden sensors also). Can this be done by creating new template?

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

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

  • @JoshuaNiland
    @JoshuaNiland 3 месяца назад

    Subscription well earned. Great content!

  • @KaiKai-uz4tf
    @KaiKai-uz4tf Год назад

    Wonderful video, thank you!

  • @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

  • @knelletv
    @knelletv 7 месяцев назад

    Such a Teacher ! Thanks ! I definitely subscribe to your RUclips channel ! 👍

    • @SlackerLabs
      @SlackerLabs  7 месяцев назад

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

  • @ppi57
    @ppi57 9 месяцев назад

    @ 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  9 месяцев назад

      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.

  • @matthewfurlong5974
    @matthewfurlong5974 Год назад

    Great tutorial

  • @moontowerdrums
    @moontowerdrums Год назад

    "repeating of course" nice one ;-)

  • @djjaysmith
    @djjaysmith Год назад

    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  9 месяцев назад +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!

  • @mastweiler22
    @mastweiler22 Год назад

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

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

  • @clairerovic
    @clairerovic Год назад

    Thanks, ❤ the greater than sign.

  • @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!

  • @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

  • @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!!!

  • @tiranhay
    @tiranhay Год назад

    Thanks

  • @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')}})

  • @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 ()

  • @mesmyth
    @mesmyth 6 месяцев назад

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