Dave's Notebook
Writing Practice by David Rickmann.
Command Interface: Connecting Devices
I have this boat that I live in. I have long had plans to add automation solutions and sensors and all sorts of fun things to it. But I’ve rarely had the time or energy, and also things like floors and walls have generally taken precedence.
We now have quite a few floors Also quite a few flaws, but I’m working on that. and walls, albeit not quite as many as we should have. So I’m going to indulge myself a little by doing a little work on the gadgets. Today I’ll do a first pass on trying to get R to talk to some of the existing gadgets.
Today’s gadget of choice: The Black water pump.
On the boat is a tank that holds all the liquidised stuff that we don’t want to go in the river. It’s the sewage tank. This has to leave the boat and go into the sewage system proper to be treated and so there is a pump which does this. The black water pump is already connected up to various systems, so it’s a good candidate for starting to explore building a control interface.
The pump is connected via a TP-Link hs110 smart plug. The smart plug is connected to the wifi and through that it can be controlled either with an app. It’s also visible to Alexa, so it can be voice controlled. Mostly it runs on a schedule.
In order to let R control it I’m going to use If This Then That to do most of the heavy lifting.
I’m using the Webhooks Channel and the TP-Link Channel and creating an applet that says:
If I receive a webook event called “pump_on”, then turn on the smart plug.
Nice and straightforward.
I’ll add another one to turn it off as well. I could create a toggle command, but I think it’s probably safer to explicitly turn it on or off.
The next step is to get R to send a webhook request.
To do this I’ll use the package httr.
event <- "pump_off"
key <- "A secret key"
maker_url <- paste('https://maker.ifttt.com/trigger', event, 'with/key', key, sep='/')
httr::POST(maker_url)
The bit that says secret key is, obviously, a secret key that I’m not telling you, because I don;t want you to turn my black water pump on and off.
All in all that was easier that I thought it would be. I can now control bits of the boat from R.