{"id":445,"date":"2020-12-23T21:05:58","date_gmt":"2020-12-24T03:05:58","guid":{"rendered":"https:\/\/lab.rapternet.us\/?p=445"},"modified":"2021-02-06T20:46:50","modified_gmt":"2021-02-07T02:46:50","slug":"adding-a-current-month-numeric-sensor-to-home-assistant","status":"publish","type":"post","link":"https:\/\/lab.rapternet.us\/?p=445","title":{"rendered":"Adding a Current Month Numeric Sensor to Home Assistant"},"content":{"rendered":"\n<p>I have a number of Christmas light strands in various windows around my house. These get turned on once a year when we remember they exist and its around Christmas time. I decided that these would be a good use for home assistant to add some Christmas lighting during November and December.<\/p>\n\n\n\n<p>To do this, I wanted an automation that would turn on the lights during specific months, and not during others. Thus I needed the current month available as a condition for my automation. I quickly found out that Home Assistant does not have this type of data built in, but can have it added relatively easily. I didn&#8217;t know how most of this was supposed to go together, so after a little bit of guess and check, here is what I ended up with.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I found that I could only add the sensor via the YAML configurations for Home Assistant. For this change to take effect as well, it required a reboot of the system. Since I wanted a numeric sensor, I used now().month which would give me a number from 1 to 12. Below is my configuration.yaml to perform this. The sensor will show up as &#8220;Current Month&#8221; in the lists in home assistant and will return a number representing the month.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-config.png\" alt=\"\" class=\"wp-image-448\" width=\"674\" height=\"466\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-config.png 911w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-config-300x208.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-config-768x532.png 768w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><figcaption>Current Month Sensor Code<\/figcaption><\/figure>\n\n\n\n<p>After adding the yaml code for the sensor, I created the automation that was to use it. I wanted the lights to turn on near sunset and turn off at a specific time. For this, I&#8217;ll only be showing the automation to turn things on. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"313\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-trigger-1024x313.png\" alt=\"\" class=\"wp-image-449\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-trigger-1024x313.png 1024w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-trigger-300x92.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-trigger-768x235.png 768w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-trigger.png 1079w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>Trigger for the automation<\/figcaption><\/figure>\n\n\n\n<p>While the real meat comes in when adding the sensor. After rebooting the server, it should be visible in the entity list when creating a &#8220;numeric state&#8221; condition. If it does not show up, then something is up with the configuration. I had to try settings a few different times to get things to work correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"503\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-1024x503.png\" alt=\"\" class=\"wp-image-447\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-1024x503.png 1024w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-300x147.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month-768x377.png 768w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2020\/12\/hass-current-month.png 1112w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>Condition using the new current month sensor<\/figcaption><\/figure>\n\n\n\n<p>After that, everything worked great and has been working for a while. The next challenge will be adding an or state to include January, or just create another automation to handle that. This was a good way to dip my toes into the yaml configuration for home assistant, as I have primarily lived in the realm of the GUI tools to create all of my (albeit few) automations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a number of Christmas light strands in various windows around my house. These get turned on once a year when we remember they exist and its around Christmas time. I decided that these would be a good use for home assistant to add some Christmas lighting during November and December. To do this, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lab.rapternet.us\/?p=445\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding a Current Month Numeric Sensor to Home Assistant&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":451,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[39,49],"class_list":["post-445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","tag-home-assistant","tag-smart-home"],"_links":{"self":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=445"}],"version-history":[{"count":6,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/445\/revisions\/460"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/media\/451"}],"wp:attachment":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}