Home Assistant (and Node-red) on your Android phone
Updated: Jan 23
Is home automation incredibly useful living in an NYC apartment? Not really - when you are only an arms-length or two from a light switch or the window blinds, don't have a 2-car garage to automate, nor multiple floors of a house to monitor... it's a bit like a Thor's hammer looking for a nail. Besides, I can usually yell...er, ask my kids to shut that light.
Is it incredibly cool? Hell yes! When you have everything running well, you only need your imagination to put together Tony Stark-style automations for your home.
Home Assistant is a free, open-source and powerful Home Automation platform. It comes with built-in, comprehensive device support and has a vibrant community of users. It's also FREE, can support local network only (no Cloud needed) and works with MQTT so you can connect to off-the-shelf or DIY IoT devices. When you combine it with Node-RED, creating automations gets even easier!
When I setup HA for my apartment, my first requirement was to be minimal. A server or desktop sitting around would not pass the spouse test. A Raspberry Pi seemed like overkill, especially when I had several perfectly capable old smartphones lying around. What were my use cases and requirements beyond being minimal? To be honest, I didn't really know, beyond high-level ideas of turning on/off appliances and lights by voice and automating some of that based on home presence and other conditions.
So the first thing was to ensure I could get this to run on my old phone! I followed the basic instructions here to install HA, Node-RED, Mosquitto on my old Android Pixel 2 XL...and success! Equipped with a few more things (like Tasker, a Bluetooth keyboard and mouse), my old, non-rooted stock Android smartphone is now a perfectly capable, Home automation server with a low profile (I hide it behind some books in a bookshelf).
(As a "bonus", this phone's screen is actually broken (it doesn't respond to touch) and hence, kid-proof. They can't mess with my HA config when the touchscreen doesn't work!)
The linked thread above is chock full of info but hard to follow. In a nutshell, the instructions are to:
Install Termux to your Android phone
Install a bunch of needed packages in the Termux shell, including python, NodeJS and of course HA Core, mosquitto and NodeRED
Start them up (eg, using pm2, python's process manager)
Ensure things are OK. This means ensuring HA starts up without major errors and you can successfully add home devices as Entities
Debug, debug and debug (if you have issues in step 4)
Ensure NodeRED is working with Home Assistant. This means being able to see your HA Entities and other info in the NodeRED UI. This required a few steps, including:
Setting up long-lived Access Token in HA (instructions)
Installing node-red-contrib-home-assistant-websocket and configuring it to point to the HA server
Install the Companion Custom component/Add-on for Node Red in HA
Now, there certainly will be hiccups and limitations depending on your Android device and versions of the software you're installing. And the frustrations I faced getting this running up have largely faded over time as the memories become hazier. Notable headaches/issues:
I had trouble with HA finding my Google home devices. That wasn't specific to my Android setup but the version of HA. Upgrading it solved it but I had to deal with some hassle of downgrading my Python to do so and hitting some other side issues
Termux has issues with Android 10+. I luckily stuck with 9 on my Pixel 2
Termux itself doesn't have USB access so Zwave and other dongles that RPi HA regularly use are not supported
Termux doesn't have access to the built-in Bluetooth on the device
However, this is where HA is also interesting on the Android device because you can run Tasker on the same phone, and leverage Tasker's ability to interface with the phone's hardware and system events to do things like:
Scan nearby Bluetooth beacons for a particular device
Receive Google Home voice commands (via Autovoice in Tasker)
to then trigger any NodeRed automations you've created (There's a lot to cover here, so I'll save that for a future post).
Besides the low-profile and cool Tasker capabilities, another plus in having the HA server on a phone is that you can move it around easily. For instance, I moved it around quite a bit to balance both hiding it from plain-view while being close enough to where I tend to place my keys (which have a Bluetooth beacon attached). You can't do that easily with your RPI!
Anyways, it's now been running smoothly for 2+ months and I've continued to layer on more and more automations with no issues. Not bad for a dusty, outdated Android phone with a broken touchscreen!