I am constantly asked about using Bigtimer (node-red-contrib-bigtimer) and so here’s an example of how I am using it in conjunction with both Amazon’s Alexa (voice control) – and the Node-Red Dashboard.
So in this example, Amazon Alexa is being used courtesy of HA-Bridge – which is part of my normal setup for any Raspberry Pi or similar device, along with Node-Red itself and Mosquitto for communications.
Here we see my cabinet timer. Essentially I have a drinks cabinet which lights up with internal white LED strip from dusk until I think midnight. The first output from the Bigtimer goes off to MQTT (no particular reason why in this case it goes off to a separate node) and quite happily runs automatically as-is.
For any number of reasons I may want to override that lighting. For example if I decide to have an early night, I may want to turn off that and other lights. I can simply say “Alexa, turn the cabinet off” to over-ride the timer settings.
Overrides on the timer work by sending one of the following to the input of the timer. 1, 0, “auto” – the latter of course simply returns the time to it’s auto state. The overrides are only good to the next auto change of state (deliberately).
So in Ha-Bridge I have 2 simple settings – on and off. I’ve added the Mosquitto utilities to the mix so that I can send a message via the command line – and this is how I do that in Ha-Bridge. Below you see the setup for the cabinet.
As you can see my password is blurred out. So Ha-Bridge on hearing “Alexa, cabinet on” or similar, sends a command line message to publish a message of topic “alexa_cabinet” with the value 1. For those unfamiliar with the mosquitto_pub application – P means password, –u means user, –m means message and as you can see I’m using a local MQTT broker (Mosquitto).
This is picked up by the MQTT input node and fed straight into the BigTimer input as is the Off command.
I wanted, in addition a control for Node-Red Dashboard as Alexa is only good if you happen to be in the same room as the Amazon device…
If you look at the first image you will see the middle output of the node feeds into the Node-Red Dashboard “Cabinet ON/OFF” control - this is to ensure that (once a minute) the dashboard on-off control actually reflects the state of the output whether on auto or manual override. The actual outputs of the control send 1 or 0 (or in the case of the blue button “auto” to MQTT – to the same topic – i.e. “alexa_cabinet”. Sadly Ha-Bridge is very restrictive in what you can actually do so it is not possible to say “Alexa set cabinet to auto”. This can be done by other means but they are currently a little messy.
This of course is only one of several devices I have using this technique, it works well. So above you see an example of using MQTT along with both Alexa and buttons to control an output without having to store any global state variables etc. Simple.