Smart socket power consumption monitoring in Node Red

Hi Chaps.
The caravan which is powered up to the mains on my drive, recently suffered a spurious electrical spike which tripped the onboard RCD and cut the power off as it should. Problem was that the fridge and freezer began to thaw and yes, you guessed it, it got a bit funky in there. So I now have the power lead connected through a smart socket that has power monitoring capability, which I can observe from the "Smart Life" app. I can check as often as I like to see if the power consumption has dropped to zero indicating some kind of protection device operation. I would love to Tazmotise the smart socket (flash it with custom firmware) but it seems that the manufactures have made it almost impossible on recent models. I have found some pre-loaded Tasmota smart sockets from a well know Chinese supplier but they're gonna take a good long time to arrive.

Has anyone else considered or successfully addressed the monitoring of mains power through some kind of smart device and constructing a Node Red flow to control and monitor it? Not seen anything on these forums tackling this topic before. There may be a better option to what I'm proposing? Just throwing it out there.



Sure you can use NR, but..... From a practical side of things:
You can do most of this outside the software world.

Caravan power point.
Plug in a small phone charger supply. Use this to power a circuit that is active with electricity.
Basically hold a relay operated and so the contacts are open.

If the relay releases, the contacts close.

12v battery close by.
Connect a circuit through the normally open contacts of the relay.
When the contacts close (relay released / power gone) an alarm is sounded.

As a slight spin on that:
Get an ARDUINO and have the contacts looking at the relay's contacts.
If they short, it sends a WIFI signal to your WAP (use MQTT) and Node-Red can receive the signal and.... your choice.

Hope that helps.

(Relay: Optocoupler that detects an LED glowing and is biased off) :wink:

I use these Zigbee devices

Zigbee is good.

There are lots of ways this could be set up without the need for a 12v battery, assuming you can get a Wi-Fi signal into the caravan, you could use an ESP device with a small battery (Wemos have an addon for the D1-mini for example). You could detect when the USB power cut of and send a signal. You only need enough battery to see you through connecting to Wi-Fi and sending a message.

Even easier would be to have an ESP always on and sending a heartbeat MQTT message with a last will and testament message defined so that if the ESP doesn't report in, the LWT message is sent by the broker and you can watch for that in Node-RED.

Another way that doesn't need any new hardware at all would be to regularly network ping the non-controllable smart-switch. When the ping fails, you know that the switch is offline.


@Surefire01 The above is an easy and cheap option - Make sure you have the smart plug inside the caravan so its after the RCD, with fridge plugged into it.

A lot of devices with "smartlife" could be OTA flashed with Tuya-Convert, but this option is mostly closed off now in newer device firmware. You can still do a serial flash if you can get to the internal connections, but this requires taking the device apart and needs special care ! You could goolge for your specific device to see if there are instructions for doing this.

It was more a/the generic solution.

Non-mains supply/power supply that will remain if mains goes away.

I am not up on the newer LIPO or NIMH batteries.

Thanks for the helpful suggestions chaps. I do like the idea of Pinging a smart device within the caravan connected to the mains supply. I have a spare Sonoff TH16 kicking around that could be pressed into service. It has already been flashed with Tasmota so all I need to do now is figure out how to create a Node Red flow that will take the MQTT data from it and inform me with an alarm or notification when the data is no longer being received (i.e. it's powered off). Fortunately I get a fairly good WiFi signal form inside the caravan as it's pretty close to the house.

Tasmota automatically sends status messages by mqtt. I think by default it's hourly but you can change that.

No need for ping if you already have mqtt.

So you just need an mqtt-in node to listen for them and a trigger node to send nothing then after say 10 minutes send the warning, extend the delay if a new message arrives

Even better use LWT and the broker will tell you if it fails

I've tried setting a Last Will message but I'm not very confident with it and can't recall it being successful.

My MQTT broker used to be Aedes, now I have Mosquitto which certainly supports LWT.

I suppose it's reassuring that I can see Node-Red monitoring devices rather than relying on the broker doing something in the shadows.
I spent the morning updating to the latest Tamota version so this is a good time to have another look at birth, disconnect and lwt messages.

Jbudd, thanks for the pointer about using a trigger node. I simulated a power outage on a spare Sonoff th16 and set up an email node to send a message when when the trigger node doesn’t receive anything for a while. Worked a treat :grin:

Have you looked at the node-red-contrib-tuya-smart-device node. . I use it for Smart Sockets and it works well

I have revisited Last Will and Testament with Tasmota and Mosquitto.
Don't suppose this is news to anyone else but I was confused before.

Mosquitto is installed on a Raspberry Pi. The only non-default settings are to require a password.

The Tasmota device has MQTT topic set to "bedroom/light"

  • A Mqtt-in node subscribed to tele/bedroom/light/LWT will receive a payload of "Online" when the device is plugged in and "Offline" when it's unplugged.
  • The Offline mesage only arrives after several seconds.
  • If I briefly cut off power to the Tasmota device, restart Mosquitto or restart Node-red, "Offline" and "Online" both arrive in that order but less than a second apart.
1 Like

The 'heartbeat' method is the simplest way to proceed IMO.
Having previously had a trailer stolen, I now have a Wemos board on the (new) trailer which sends a signal to the house every two minutes. A timer node running in NodeRed is set to send an alert message to my phone every /three/ minutes. When a message (a 'heartbeat') arrives from the trailer, it resets the three minute timer.... So while the trailer is plugged into the mains, the heartbeats keep coming, and the alert signal is held off. Should a miscreant unplug the trailer to drive off with it, I'll get an alert within maximum three minutes.
You can use the same approach to the power in the caravan ~ a regular heartbeat message over MQTT, and trigger an event if it doesn't arrive in time.
No battery, no charger required!


You can also change the frequency of the messages being sent out from Tasmota - using the TelePeriod command - believe the default is 5 minutes - you can change that down to as short as 10 seconds.


Sorry, but I may have tried it and had no end of trouble.

I'm not saying it won't be what is needed.

But one of those tuya nodes was more pain than it is worth.

I on the other hand hand used it successfully all last winter on our new heatpump and it did not miss a single beat


Ok, thanks.

Just to close this topic down, I found a solution was to use a trigger node (thanks Jbudd for the pointer) to check the timings and absence of an MQTT payload and respond with and email node if the MQTT data doesn't arrive.

I also incorporated a Telegram node with an account so that I am also notified via a Telegram bot on my mobile devices. As an aside it also works as a theft alarm as any villains would have to disconnect the power should they want to steal the caravan. Great, two birds one stone.

Thanks everyone for your input.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.