In previous posts I showed how I am controlling the boil cycle of my geyser. I wanted a way to show the people in the house if the geyser was on, or not, and how long it has been in that status. See below, the geyser is currently off, the little clock will be red if it is on, and the 'since...' will have the minutes since the last change, thus, this says the geyser was just switched off.

Why is this important? As the family start understanding that they can control the environment around them (in this case the house), and that through IoT we have instant information at our finger tips ~ about aspects that influences costs, the environment, they can get direct and immediate feedback from the environment, to allow them to act on this info, and be more in tune with the physical environment. This is the promise of the age of Industry 4.0.

Here is the code snippets of how to do this, firstly the NodeRED flow:

1) Using ESP8266 firmware with instructions for relays and to query the status. For those that do not know, I use ESPEasy firmware on my ESP8266's. You can find the wiki of how it works, and how to flash it with Arduino onto the ESP, here at

2) Saving the switch status and time. Then, we need a function that will save the switched status in a global variable, an the time of the switch.

It is done in the function node <Geyser SQL & globalset GeyserTimeSwitced>.
As you can see, I also store the switch status into SQL, for other reasons.

In this code below you will also find a override switch, where a family member can switch the geyser on, if for instance they want to shower in the middle of the day when the geyser is off. But this override, will switch back to off state in 40min.

The code to set the global variable:

var GeyserTimeSwitched   = new Date() ;    global.set('GeyserTimeSwitched',GeyserTimeSwitched) ; // for use in the net flows

3) Requesting the switch status from the ESP gpio, checking time diff since switch, and display both.
So, the GeyserOn? function sends a message to the ESP, asking for the status of the GPIO 16, where I have the geyser relay hooked up to

msg.payload = "status,gpio,16" ;

Then, I listen on the mqtt topic ../status, where the ESP will post the status back to. That changes the clock icon of [Geyser On?].

I hope you find this useful !

NodeRed flows to do this:
Import these into NodeRED with the flow import function, copy the content of the txt file into the clipboard.
Code for 2) - saving the switched status time:

Code for 3) Requesting the switch status, and calculating the time since the change.

(Originally posted on IoTPlay blogspot 18 Feb 2017)