Mar 24, 2022
My last post described some of my setup for Home Assistant. Since then, I've been writing a number of automations for my house, ranging from simple to not so simple. I thought I'd share some of these ideas here.
My backyard has a wood fence with a single gate that I usually leave closed. For security, I wanted to know when the gate has been opened.
To make this work, I use a small Sensative z-wave reed switch. It has an enclosed battery that is supposed to last around 10 years. To make this a little more durable and hidden, I dug out a slot in a piece of wood and painted over the switch:
Attached to the gate, with a small magnet attached on the other side, I recieve events for when the gate is open or closed. On open, it notifies my phone or voice announces on a Google Home Hub indoors.
However, there are a few tricks. First, if it gets windy, sometimes the gates move enough that it triggers an "open". So, I don't trigger an event until the gate has been open for a couple seconds, otherwise I ignore it. Second, I don't want to get a flurry of notifications if someone is going in and out, so once the gate is closed, I disable notifications for the next 10 minutes. This timer resets and extends if it's opened again during this 10 minute period.
Last year, I installed LED lights along my roof line for holiday times. Home Assistant can hook into this and select different displays for different holidays. I now have settings for 8 different holidays:
For some holidays, I rotate through multiple patterns, changing every 2 minutes. Everything starts at sundown and shuts off at 11pm, except for New Years where it runs until a little past midnight.
One annoying "feature" is that the LED strips actually consume power even when not displaying any light. While this is probably not a lot of energy, it's also heat that wears out the LEDs faster. So, this automation first turns on a smart switch, then when the WLED server comes up, it starts sending commands on which patterns to display.
My electric rate plan charges me different amounts of money for power at different times. There are three time periods with increasing prices: off peak, partial peak, and peak. This automation publishes a signal that indicates which period we are in. It's used by other automations.
Computing this is pretty simple. The schedule is different in summer (May-Oct) from sinter (Nov-Apr), different on weekends vs. weekdays. Otherwise, it's just a lookup table.
I have my electric car plugged into a normal 120V outlet, with a smart plug controlling it. This automation turns the charger on when the PG&E rate is offpeak, and then back off otherwise. Pretty simple, and I can override with a button press either at the plug or on my phone if I need a charge sooner.
Similar to to the PG&E rate, I want to know if the TV is on. I use this for doing things like turning off a noisy dehumidifier.
My TV isn't very smart, but it has a USB port that powers a Chromecast. The Chromecast has power iff the TV is on. Home Assistant knows how to talk to the Chromecast, and can read it's state which are values like "Playing", "Paused", "Idle". And when the Chromecast is powered off, we get "Unavailable". So this automation basically reduces this enum to a "on" and "off", republishing those states. There is a several second delay while things boot or timeout on the network, but this is shorter than it takes me to start playing something, so I'm quite fine with it.
I have a dehumidifier, mostly for the summer, to keep the humidity down in the house. I put it on a smart plug and only run it when the thermostat detects high humidity, the PG&E rate is "offpeak", and the TV isn't on.
This one is probably the most involved. I installed an Innovelli Red smart switch to control my front porch lights. It has an LED indicator on the switch that I can control. The basic automation is to turn on the lights for 10 minutes if anyone comes up on the porch, but there were a lot of details to get right.
First are the trigger events. I have a camera doorbell, so I trigger if the doorbell is rung or a face is detected. I have a door sensor, so I trigger if the door is opened. I also geofence my and my wife's cell phones, so when we arrive home, it triggers. And of course, these are all disabled during the day.
Next is local override. If the lights are already on, I don't want to start up a timer and turn them off 10 minutes after an event. I want them to stay on. Similarly, if during an event, the user presses the light switch (up or down), I want this to override the light and the timer. So, an up press leaves the lights on but disables the timer.
This state (if we're on a timer or override) would be hidden to the user, so I use the LED indicator on the side of the light switch to indicate a timer is running, by having a Knight Rider style animation running when a timer is going, disabled if not.
Finally, when the timer isn't running, I use the LED indicator color to give me a estimate of the air quality outside at a glance. This is becoming an issue in the fall in California. So I bracket AQI into green-yellow-red-purple on a low intensity so it's not annoying.
This one has a lot of timers and possible states going on, so it was the automation that really got me looking into how to add test code to my setup.
I have a Roborock S4 Vacuum which, when finished, will automatically go back to it's dock and charge. The only problem is that it's tucked away in a less used part of the house, and the robot's dustbin is fairly small. I basically need to empty the dustbin after every run.
This automation tracks if the dustbin is full or not by monitoring the robot's cleaning run. When the dustbin is full, it will wait until the robot has charged up to 90% battery, and will then undock the robot and drive over to the trashcan in the kitchen and wait for me to empty it. Once I've done so, it'll drive back to it's charger. Pretty convenient!
One time I was not around and it ran the battery down waiting for me. So, I added an extra routine so that if the battery drops too low, it'll drive back to the dock, recharge, and then return to the trash can. This doesn't get much use, but it's an added convenience.
This might be my favorite. I monitor the local weather station for temperature, wind speed, rain, and humidity. I also monitor nearby air quality monitors for particulates. Finally, I track the temperature and humidity inside from my thermostats. When everything is such that the air outside is same or better than inside, I send a notification to my phone to open the windows. When things turn around, I send another notification to close them.
What I like about this is that it almost a software-only automation. If I simplified and ignored the inside thermostats, all of the computations use data online from weather and air quality stations. And there are no motors or lights to turn on or off, a human does the actual work.
I've been thinking about making a website where anyone can register for these kinds of alerts by entering a zip code or lat / long, as well as a phone number to text when it's time to open or close the windows. I don't know if I'll actually do this though.
These automations don't really make a huge difference in my life. At most, they save me a few seconds or help me remember to do things, but they are all minor. That said, I've enjoyed coding them up and figuring out how to make everything work. Perhaps I'll bore of it, or maintenance will become a chore, but for now I'm enjoying playing with it all.