[<< | Prev | Index | Next | >>] Saturday, March 29, 2025
My House Has Termux
[home automation; nerd tech]
I recently discovered termux (as a side effect of looking for ways to make an android phone talk to a Roomba via USB, but that's another story). And in particular termux-gui which lets one quickly build (very primitive, but functional) android-native interactive applications in python.
It turned out to be easy to work its event loop into my home automation suite, which surprisingly runs just fine in termux right on my phone.
So I only had to add one file, being a GUI front end that bridges termux-gui to my home automation setup, and presto, I now have panels like this on my phone:
The code to create one of those buttons looks, for example, like this:
row.dyn_value('thermostat/schedule', 'Schedule')If thermostat/schedule is an editable value, it will pick up the possible values over the network and when tapped will present the user with a popup of the options. Here's changing my A/V system's mode (scene):
Probably my favorite thing is this panel, which is all green most of the time (requiring no focus), but whose items fade through yellow to red if values or states get out of expected range (e.g., if I leave the front door unlocked, that upper-left square will be red):
All of these things update in real time, so it is simultaneously a controller and status monitor.
The full source code for the termux integration is in the file linked above, but here, for example, is the entire function that creates and configures the Thermostat pane (again: current values, and settings options, are picked up over the network from my existing home automation setup which didn't have to change at all):
def build_therm_panel(self, frame): frame.space(weight=1) row = frame.row(height=self.buttonsize) row.dyn_float('thermostat/temp_sensor/temperature' , 'Hall' , color='green') row.dyn_float('thermostat/remote_sensor/temperature', 'Bedroom', color='green') row.dyn_float( 'waveplus2/temperature', 'Office' ) row.dyn_float( 'waveplus4/temperature', 'Outside') row = frame.row(height=self.buttonsize) row.dyn_float('thermostat/heat' , 'Heat' , color='red') row.dyn_float('thermostat/heat_offset', '(offset)', color='red') row.dyn_float('thermostat/cool' , 'Cool' , color='blue') row.dyn_float('thermostat/cool_offset', '(offset)', color='blue') row = frame.row(height=self.buttonsize) row.dyn_value('thermostat/schedule', 'Schedule') row.dyn_value('thermostat/sensor' , 'Sensor') row.dyn_value('thermostat/fan' , 'Fan') row.dyn_value('thermostat/system' , 'System') row.dyn_value('thermostat/state' , 'State') frame.space(weight=1)I jammed everything together in one file because it's a one-off for me, but everything above the build routines at the bottom constitutes a pretty handy object based API for building termux-gui applications (largely using my home automation tools, but if you stripped those references out what's left is still pretty handy). Help yourself (if interested I can explicitly stick a liberal copyright notice on it, just ping me).
[<< | Prev | Index | Next | >>]