{"id":1084,"date":"2023-11-12T14:07:03","date_gmt":"2023-11-12T14:07:03","guid":{"rendered":"https:\/\/thomas.w-p.me.uk\/blog\/?p=1084"},"modified":"2023-11-12T14:07:03","modified_gmt":"2023-11-12T14:07:03","slug":"home-assistant-templates","status":"publish","type":"post","link":"https:\/\/thomas.w-p.me.uk\/blog\/2023\/11\/home-assistant-templates\/","title":{"rendered":"Home Assistant Templates"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have been getting to grips with <a href=\"https:\/\/www.home-assistant.io\/\" data-type=\"link\" data-id=\"https:\/\/www.home-assistant.io\/\">Home Assistant (hassio)<\/a>. (This was after attempting, late at night and tired, to update OpenHab&#8230; It didn&#8217;t go well and though I had solid backups I knew I would need to do a full restore and have kept hearing about Home Assistant. I wanted to give it a try, and found it is so much better than OpenHab. I had everything OpenHab had and more in one morning of play. Everythign is so much easier).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the more I got in to hassio  the more I kept hearing about <strong>Templates<\/strong>. Hassio is well documented but there are no examples at all. I can read them but miss the point because, typiccally, I read too fast.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So when the <a href=\"https:\/\/www.home-assistant.io\/docs\/configuration\/templating\/\" data-type=\"link\" data-id=\"https:\/\/www.home-assistant.io\/docs\/configuration\/templating\/\">Templating documentation<\/a> said:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Templating in Home Assistant is powered by the <a href=\"https:\/\/palletsprojects.com\/p\/jinja\">Jinja2<\/a> templating engine. This means that we are using their syntax and make some custom Home Assistant variables available to templates during rendering.<\/p>\n<cite>https:\/\/www.home-assistant.io\/docs\/configuration\/templating\/<\/cite><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">I didn&#8217;t realise this meant &#8220;custom code&#8221;. That would have helped. Template = Custom Code in Jinja2!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I went in to the Developer Tools > Template and had a play (<a href=\"https:\/\/www.youtube.com\/watch?v=cdz32TLu_gw\" data-type=\"link\" data-id=\"https:\/\/www.youtube.com\/watch?v=cdz32TLu_gw\">with the help of avideo by &#8220;Smart Home Junkie&#8221;<\/a>) I found that I could easily get the value of things using {{ states(&#8216;the_thing&#8217;) }} (I also found that the Dutch word for curly bracket is &#8220;accolade&#8221; which is way better to my ear).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With my new knowledge I made my first Template to show the current rate as a read only thing so I can display is safely. <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A name &#8211; this is what you look up later and is turned in to a spaceless name, this one would become current_rate<\/li>\n\n\n\n<li>The Jinja2 code<\/li>\n\n\n\n<li>Preview<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"1024\" src=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-682x1024.png\" alt=\"\" class=\"wp-image-1085\" srcset=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-682x1024.png 682w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-200x300.png 200w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-768x1154.png 768w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image.png 952w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I made a sensor called &#8220;Current electricity period&#8221; and magic happened when creating a dashboard.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1-1024x682.png\" alt=\"\" class=\"wp-image-1087\" srcset=\"https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1-1024x682.png 1024w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1-300x200.png 300w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1-768x512.png 768w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1-1536x1023.png 1536w, https:\/\/thomas.w-p.me.uk\/blog\/wp-content\/uploads\/2023\/11\/image-1.png 2038w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I know it is basic knowledge, but I needed to make this first step. I think I am away now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been getting to grips with Home Assistant (hassio). (This was after attempting, late at night and tired, to update OpenHab&#8230; It didn&#8217;t go well and though I had solid backups I knew I would need to do a full restore and have kept hearing about Home Assistant. I wanted to give it a &hellip; <a href=\"https:\/\/thomas.w-p.me.uk\/blog\/2023\/11\/home-assistant-templates\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Home Assistant Templates<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,108],"tags":[],"class_list":["post-1084","post","type-post","status-publish","format-standard","hentry","category-general","category-home-assistant"],"_links":{"self":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/comments?post=1084"}],"version-history":[{"count":2,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1084\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1084\/revisions\/1088"}],"wp:attachment":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/media?parent=1084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/categories?post=1084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/tags?post=1084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}