Time calculations. working with datetime helpers, timers. working out percentage of time remaining. determining difference betweeen two input_Datetime helpers etc
@@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".
@@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! 😅
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.
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.
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.
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!
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!
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!
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.
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.😀
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!
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
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...
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.
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.
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.
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.
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?
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
@@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?
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. 🙂
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.
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?
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
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
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.
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?
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.
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?
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...
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.
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.
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?
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.
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?
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.
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.
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?
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?
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
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')}})
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.
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: “”)
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.
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.
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 ()
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
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..
What parts of home assistant templates are giving you the most trouble?
What is giving me trouble is how can I use templating to send a custom notification message?
My problem was understanding how to use them, but I think this video got me started.
Time calculations. working with datetime helpers, timers. working out percentage of time remaining. determining difference betweeen two input_Datetime helpers etc
@@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".
@@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! 😅
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!
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.
This is the jinja video I always wanted when starting out. Great work!
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.
Hello,
You've just shown me just how powerful and interesting these templates can be! Many thanks!
Excellent job.
More Jinja videos please. A whole series (4-5) would be great
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.
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!
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!
One year later and this video is still great! Thanks!
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!
Thank you sir!
Grazie per le spiegazioni sempre molto utili e chiare !
🤗
Very good video. Well presented and well explained. I am new to HA and frequently get stuck. I have subscribed.
Super straight forward guide! Thanks Jeff!
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.
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.😀
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.
That’s good feedback.
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!
Thank you for creating such an insightful and engaging video, I really enjoyed and learned a lot from it
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
Nice!
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...
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.
Thank you! Been looking for a primer like this. I really hope you continue on with follow on vid's on this.
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.
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.
very useful, would like to see a sequel
I got 3-4 videos in this series. Should be a playlist of them.
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.
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.
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?
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
@@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?
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. 🙂
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.
useful I was shying away from templates now i think I can try atelast. Need more of these type
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?
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
@@SlackerLabs thanks!
This is Amazing start for templates, always scared to look at temples, but not anymore 😮
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
@ 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)
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.
Subscription well earned. Great content!
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?
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.
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.
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?
same for me
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...
Wonderful video, thank you!
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.
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.
This is a great video. Thanks.
How do you save the template that you make in the template section of developer tools?
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?
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.
Such a Teacher ! Thanks ! I definitely subscribe to your UA-cam channel ! 👍
Thank you! I see paces I need to improve, but I'm glad even with my fumbles it helps!
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?
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.
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.
Dont worry. There is a method to my madness.
21:30 the month of July is missing. Why?
Typo from when I was adding it back in....didn't even miss it evidently...
@@SlackerLabs love your vids!!!
Great tutorial
"repeating of course" nice one ;-)
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?
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
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?
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?
Yea, it's an attribute as part of that light bulb. I think it's a Sylvania zigbee bulb.
@@SlackerLabs you forgot the unit (kWh).
Hmm... I've been looking for a way to display wind chill.
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?
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
Oh. Nice. Copy paste for the win
@@SlackerLabs Ah, right on!
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')}})
Hi, do you know why for weekday it is with () => {{ now().weekday() }} and for month without () => {{ now().month }} ? Thanks for your videos.
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.
Thanks, ❤ the greater than sign.
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: “”)
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.
Thank you Jeff!!!!!
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.
@@SlackerLabs This is a great start and is helpful! Thank you
Thanks
So the order of operations for pipe is before math. Who's have guessed it. I bet all my calculating templates are wrong
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 ()
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
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
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..