Mastering Home Assistant Templates: A Beginner's Guide

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น • 107

  • @SlackerLabs
    @SlackerLabs  ปีที่แล้ว +3

    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! 😅

  • @chimeranzl9147
    @chimeranzl9147 9 หลายเดือนก่อน +2

    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!

  • @singaporepastor
    @singaporepastor ปีที่แล้ว +5

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

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

  • @vicb2389
    @vicb2389 ปีที่แล้ว +20

    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.

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

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

  • @PauloAbreu
    @PauloAbreu 2 หลายเดือนก่อน

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

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

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

  • @philippe5394
    @philippe5394 10 หลายเดือนก่อน

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

  • @edwaaij4752
    @edwaaij4752 11 หลายเดือนก่อน +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.😀

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

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

    • @SlackerLabs
      @SlackerLabs  ปีที่แล้ว +2

      That’s good feedback.

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

  • @lawjamesr
    @lawjamesr ปีที่แล้ว +2

    Super straight forward guide! Thanks Jeff!

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

  • @ppi57
    @ppi57 ปีที่แล้ว

    @ 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  ปีที่แล้ว

      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.

  • @k9slover
    @k9slover 3 หลายเดือนก่อน

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

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

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

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

  • @brettautrey4117
    @brettautrey4117 8 หลายเดือนก่อน

    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.

  • @ionbuilds
    @ionbuilds 5 หลายเดือนก่อน

    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?

  • @atabatabaee
    @atabatabaee ปีที่แล้ว

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

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

  • @markvk42
    @markvk42 2 หลายเดือนก่อน

    How do you save the template that you make in the template section of developer tools?

  • @gerardschepers3744
    @gerardschepers3744 10 หลายเดือนก่อน +1

    very useful, would like to see a sequel

    • @SlackerLabs
      @SlackerLabs  10 หลายเดือนก่อน

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

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

  • @steveelves3499
    @steveelves3499 8 หลายเดือนก่อน +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.

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

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

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

  • @narshimagoudpalakurla9651
    @narshimagoudpalakurla9651 ปีที่แล้ว

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

  • @ac-fs2dc
    @ac-fs2dc 4 หลายเดือนก่อน

    Grazie per le spiegazioni sempre molto utili e chiare !
    🤗

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

  • @johnny-d8o8m
    @johnny-d8o8m ปีที่แล้ว +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.

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

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

  • @bat3332
    @bat3332 ปีที่แล้ว

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

  • @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 9 หลายเดือนก่อน +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  9 หลายเดือนก่อน

      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.

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

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

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

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

  • @mastweiler22
    @mastweiler22 ปีที่แล้ว

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

  • @kasianchukandrii4471
    @kasianchukandrii4471 10 วันที่ผ่านมา

    This is a great video. Thanks.

  • @JoshuaNiland
    @JoshuaNiland 6 หลายเดือนก่อน

    Subscription well earned. Great content!

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

  • @moontowerdrums
    @moontowerdrums ปีที่แล้ว

    "repeating of course" nice one ;-)

  • @knelletv
    @knelletv 9 หลายเดือนก่อน

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

    • @SlackerLabs
      @SlackerLabs  9 หลายเดือนก่อน

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

  • @KaiKai-uz4tf
    @KaiKai-uz4tf ปีที่แล้ว

    Wonderful video, thank you!

  • @matthewfurlong5974
    @matthewfurlong5974 ปีที่แล้ว

    Great tutorial

  • @clairerovic
    @clairerovic ปีที่แล้ว

    Thanks, ❤ the greater than sign.

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

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

  • @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 8 หลายเดือนก่อน

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