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, 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’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.
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 “Current Month” in the lists in home assistant and will return a number representing the month.
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’ll only be showing the automation to turn things on.
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 “numeric state” 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.
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.