The fan in the pain cave has been bugging me for a while. It's out of arms length once I'm sat on the trike on the trainer, so I either need to turn it on first and freeze until I get into the session, or stop and turn it on part way. The obvious solution would be to plug it in to the four way strip next to me, that is in easy reach.
However, I've been playing with a Megalodon 16 key + 3 knobs macro pad keyboard (I use QMK on my main keyboards, so am used to it) to give easy control of the computer when on the trainer; rotary knobs for prev/next/volume for media, big buttons for pause/mute, focused keypad with just the hotkeys I need rather than a full sized keyboard. So, the obvious thing to do was put the fan onto a smart socket and, rather than use a Zigbee button to turn it on and off, program up a key on the keyboard to do it.
So reprogram the keyboard so pressing one knob presses F13 (a function key that isn't likely to collide with another use). Then figure out AutoHotKeys on the Windows machine I use for the trainer (I'm not normally a Windows sort of person anymore). So that can now run a script automatically when I press F13. Figure out how to access the HomeAssistant API from the command line in Windows (went the simpler route of generating an authentication key in HA, then using curl to POST a command), and set that to toggle the smart socket on/off when F13 is pressed. That took an irritating amount of time to figure out the incantation of single and double quotes and backslashes.
But now it works. So rather than plugging in the fan or flicking a switch on the extension board, I now
Press a key on the macropad, where the QMK programming determines the keycode to send dependent on how long I hold the key (a long press is used to maximise the Zwift window, short press toggle the fan), which talks over USB to the laptop next to the fan.
The AHK on the laptop intercepts the keypress and triggers a script to call HomeAssistant (running on a Raspberry Pi elsewhere in the house) over the network.
HomeAssistant does its magic, then sends out a signal over Zigbee to turn on the socket.
The fan starts to turn.
Rube Goldberg would approve, I feel.