Quick button to control lights from phone (iOS)

OK, quickie for a Friday night.

I found myself in need of being able to manually turn off a light recently. But rather than doing it immediately, I needed a 5 minute delay.

While I could certainly set this up with my home dashboard, my Telegram bot or indeed some of the remote controllers around the house, each of those would take a bit of work and I probably won't need this for that long.

So I remembered that you can now use Apple's "Shortcuts" app to call a URL which makes it great for triggering Node-RED flows. 5 minutes of messing later, I had this simple flow set up.

[{"id":"e9114e5d.15e04","type":"http in","z":"fa3e1078.ef619","name":"","url":"/lights/:onoff/:switch/:delay","method":"get","upload":false,"swaggerDoc":"","x":190,"y":520,"wires":[["fb53d863.cfd198"]]},{"id":"fb53d863.cfd198","type":"change","z":"fa3e1078.ef619","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.params.onoff","tot":"msg"},{"t":"set","p":"delay","pt":"msg","to":"$number(req.params.delay)*60000","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"\"COMMAND/SWITCH\" & req.params.switch","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":520,"wires":[["24e558f7.e962f8","8a320c7.2098af"]]},{"id":"8a320c7.2098af","type":"http response","z":"fa3e1078.ef619","name":"","statusCode":"","headers":{},"x":610,"y":480,"wires":[]},{"id":"24e558f7.e962f8","type":"switch","z":"fa3e1078.ef619","name":"","property":"delay","propertyType":"msg","rules":[{"t":"null"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":610,"y":520,"wires":[["5f1e823d.6c71bc"],["42775d28.67e374"]]},{"id":"ea19310e.531de","type":"http in","z":"fa3e1078.ef619","name":"","url":"/lights/:onoff/:switch","method":"get","upload":false,"swaggerDoc":"","x":170,"y":560,"wires":[["fb53d863.cfd198"]]},{"id":"42775d28.67e374","type":"delay","z":"fa3e1078.ef619","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":760,"y":540,"wires":[["5f1e823d.6c71bc"]]},{"id":"5f1e823d.6c71bc","type":"link out","z":"fa3e1078.ef619","name":"To-Pi2-MQTT-Retained","links":["9d14e3db.2817"],"x":895,"y":500,"wires":[]}]

The shortcut on the phone is just 2 steps:

  1. URL: set to "https://:1880/lights/off/04/5" - That is light switch 04 turned off after a 5 minute delay.
  2. Get Contents of URL - it doesn't matter what Node-RED returns to this as we are just ignoring the output.

Then I add the shortcut to the home screen and I have a very quick and easy trigger.

You will note that I have 2 input http nodes. One with the delay and one without. I also have parameters that let me turn things on or off and lets me choose which light to control. So the whole thing can be used to control any light with or without delays.

I could extend the shortcut to ask for the delay, light and on/off choice as well if I wanted to.

Note that the output is a link node which goes to an MQTT out node since my lights are, of course, controlled via MQTT messages.

2 Likes

There are also the MQTT apps in play store / app store.

Welcome apple to 2008.

Haha, and I have one installed on my ageing apple thing.

Home Remote does a decent job but I have to use the desktop version to create one or more screens and wire everything up! Or I have to live with manually sending commands to MQTT using an MQTT test tool. Neither are nice.

Really though, what I'm doing isn't as important as knowing just how easy it is to set up a simple API and call it via a button using just native tools and Node-RED. It takes litterally a couple of minutes to set up the API which I can then use and expand the logic of at a whim.

What's more, it even stands up to the Mrs K. test! (well as long as I set it up for her of course). A button on the home screen - as simple a UI as it gets.

Nice!!! This might make it easier to start my coffee pot in the morning!

1 Like

thanks for sharing. A nice, simple solution. Has many WAF possibilities!