The Home Automation Rabbit Hole
I was recently asked to write a short text to introduce myself to my new colleagues at Google. In this short text, I was supposed to state a “fun fact” about me - I chose to disclose a little bit about my smart home adventures and mentioned that my office lights turn red, if my standing desk height does not change for more than 60 minutes. I want to document this particular automation in a little more detail here, giving some insight into how my home automation setup looks like!
Using Home Assistant with my Standing Desk
Home Assistant VM on Unraid
I got started using Home Assistant a couple of years ago, when I was still running it as a single Docker Container on my previous QNAP NAS. Now, Home Assistant is running in its dedicated VM on my Unraid Server. While there are other solutions for home automation, I really appreciate the development Home Assistant is taking, abstracting all vendors to a single unified dashboard while supporting plug-ins and 3rd party tools. One technology I am relying on for my home is Zigbee, since I do not want to crowd my Wifi network with too many individual sensors. To enable my server for the Zigbee protocol, I purchased a Conbee II stick and passed it to my Home Assistant VM as a USB device. This allows me to access all different kinds of Aqara sensors, Philips Hue bulbs and Osram Lightify strips as native entities within Home Assistant, after configuring a small plug-in for the stick (“Deconz”).
Automating
While Home Assistant makes it easy to configure simple automations via its UI, I am relying on another plug-in for more complex automations. Node-Red allows me to use a graphical interface to model my automations and support all different kinds of actions, from triggers like state changes within Home Assistant to API calls via HTTP requests or MQTT commands. While there might be much more elegant ways to achieve the light changes, these were my requirements:
- When my standing desk height is not changed for 60 minutes, I want to get notified by turning a light at the other side of the room to the color red
- When the lights are currently off, the notification turns them on
- When I change the standing desk height, the counter is reset and the lights are turned to regular lighting again
- When the lights had been off before the automation turned them on (in red), changing the desk height should not only turn them back to normal, but also turn them off afterwards
- This automation should only run during my work hours
The last requirement was solved through a helper variable in Home Assistant. While I could try to find ways to automatically let my server discover I am currently working at my desk (e.g. through movement sensors), I wanted to be able to manually turn this automation on and off again - therefore I am simply scanning an NFC tag at my desk to toggle the behavior. The following flowchart is a screenshot taken from Node-Red, solving all the requirements mentioned above. Some of the design decisions may become clearer in the next section, where I explain how I determine whether the standing desk height has been changed.
Measuring desk height changes through energy consumption
My standing desk is not smart by design. While there are attempts to reverse engineer the protocol the desk’s remote is using, I decided against installation of an ESP device with RJ45 connection for this simple use case. I do not need to be able to set the desk’s height or even determine the height, but only need to know whether this height has been changed in the last 60 minutes. I considered options like movement sensors below the desk (might be too sensitive) and magnetic contact sensors fixed to the wall (would only determine very specific heights), but finally settled on the easiest solution I could think of: Measuring the amount of energy drawn by the standing desk while the motor is working. Luckily, all I needed for this was already in place. I had purchased some Gosund SP112 smart plugs a couple of years ago, and flashed them with the open firmware Tasmota. This allowed me to run these Chinese devices with a purely local connection on my home network, leveraging the MQTT-protocol. These smart plugs are able to measure the energy consumption of connected devices and also integrate into Home Assistant perfectly. So all I had to do now was connect the desks power cord to this smart plug and look for the energy sensor data to update, once the motor was moving the desk, to determine thresholds that tell me the desk motor has done some work.
Unfortunately, I had to create a small workaround at this point. Since the MQTT sensor updates were too infrequent to detect every surge in energy consumption, I could not rely on them for my automation. Instead I chose to incorporate API polling to the smart plug every 5 seconds in the automation above, determining whether my desk has been moved. If yes, all counters depicted in the flow would be reset - if not, my Zigbee lightstrips would be turned to red after 60 minutes!
The tip of the iceberg
Do I really need this? Of course not, it’s just for fun. Slightly helpful, at least! When I was still running Windows, this automation was even more complex. At that time I was able to determine whether I was in a call on MS Teams via a PowerShell script. If I was, the automation would wait for my call to end, before changing the lights.
There are a some more fun use cases I have implemented, like my smart letterbox sending me notifications about the number of letters in our physical mailbox, my MQTT-controlled portafilter, or automated work time-tracking for my wife through geo-fencing… the sky is the limit!