How to Build Home Assistant Sensors using Wolfram Alpha
This weekend I decided to dig into some of my todo list items that have had sitting for a long while. This particular one was from December 20th 2017!
Better late than never I guess. I was inspired again to get this done when I saw a @TheJeffreyStone code change on his repo. He had developed some Python scripts to create sensors that would give you a countdown sensor to various holidays and dates in Home Assistant. I remembered my stuck todo list item and decided to give it a go. My method would be using straight YAML and a great website API called Wolfram Alpha. This computational engine had an API that allowed you to use the REST API component in Home Assistant to give it natural language queries and get the results back in very usable JSON formats. For the Holiday Sensor, this solution was fantastic since it would solve one of the issues I had been having for a while. Namely, floating holidays like Mother’s Day, Easter and Father’s Day. Since those holidays occurred on different dates each year, it was much more difficult to program against them in Home Assistant YAML.
With the ability to just ask Wolfram Alpha, “How many days until Easter?”, this problem was solved for me. This whole sensor opens up a bunch of possibilities for different lighting scenarios and speech output based on results from Wolfram.
I now have a bunch of holiday sensors that have numeric values in my Home Assistant. My next plans for these sensors is to use them in Speech Notifications and also to leverage them for my Outdoor Holiday lighting. I plan to color the house differently when various countdown sensors reach various thresholds. I think this should be pretty easy.
The whole solutions is free as Wolfram allows for up to 2000 API calls per month. I’d love to hear if you come up with some cool new queries that I didn’t think of. Leave them in the GitHub repo or drop them in the YouTube video’s comments.