A long long time ago, I did a small project called “ZigBee low battery warning“. It would actively scan your ZigBee network and notify your phone when your battery-powered device drops below a personalised threshold. It would also let you buy the batteries directly from Android notifications! The project had one shortcoming. It didn’t care about sensor responsiveness.
Monitoring ZigBee sensors in NodeRED
My work on DIY Smart Heating v4 takes more time than I would like, but I made one more module that will be integrated into my ZigBee network. This time around, I used NodeRED and Join to scan connected sensors and notify my phone if one of them hasn’t called home for a while. There are multiple reasons why this could happen, but it’s infuriating given how crucial sensors are to our automation – when the sensor is not performing as expected.
What I haven’t mentioned in the video, is the fact that this project works for any device that reports back to NodeRED. As long as the payload is posted to your NodeRED server, you can make it work no matter the protocol it uses.
How often do sensors call home?
A couple of articles ago, I tested 11 ZigBee temperature and humidity sensors for home automation. Apart from the usual metrics, I also took a look at how often sensors would call home and update your server with the latest readings. This would vary wildly between sensor type and brand but it would boil down essentially to a couple of triggers:
- environmental change – a change in temperature, humidity, lux etc would trigger an update almost instantly. Once the threshold for change is crossed, the sensor sends the update
- interval – without significant changes to your environment, the sensor would still report back. On average, you should expect one or more updates every 5-30 min
Your battery-powered (and not only) devices can skip a beat. A faulty sensor may not work as expected, a crappy battery may drop current when an update is called or a troublesome router in the mesh network can hinder ZigBee communication. All these can affect the frequency of your reports.
The fix isn’t always as easy as swapping a battery, but knowing when the device failed and how long it had been since then helps to troubleshoot the issue.
NodeRED to the rescue
The project uses NodeRED with Join node (install via palette manager: node-red-contrib-join-joaoapps). Join links up with your Android phone and allows NodeRED to issue notifications. I have a complete write-up on the advantages of using Join in NodeRED here.
You can use this project in NodeRED and make it compatible with whatever automation at home. There are some requirements that your automation must meet, otherwise, you’ll have to modify the core code yourself.
To hunt for unresponsive ZigBee devices, sensors must be stored in an array
#get the list of existing sensors (make sure initially sensors = [])
var sensors = flow.get("sensors");
var sensor = msg.payload;
#add timestamp off the sensor update
sensor.timestamp = Date.now();
sensors.push(sensor);
flow.set("sensors", sensors);
and each sensor is an object which must contain these two key-value pairs:
{
"room":"name_your_sensor",
"last_report": 1675014128151
};
Each sensor object can contain other information too, but these 2 must be included in each object. You can assign the timestamp for each update by using this simple function:
sensor.last_report = Date.now();
Once you set the stage, import the project and take a look at the Settings node. In the “OnStart” tab you will find the settings which can be set for the flow and your Android notifications. If the sensors array has info on your battery status, it will include that in the notification too. It should help decide if the battery was at fault when the sensor went dark.
I suggest setting the timeout to more than an hour unless you have a good reason to keep more frequent notifications. The project is set to notify your phone within 1h from the time your sensor reports as unresponsive. It will issue a single notification for each sensor that became unresponsive. To prevent it from spamming, you can disable repeats, otherwise, NodeRED will reset notifications at 8 am the next morning.
Make sure to add names or IDs for your Join devices. You can specify one or the other and list more than one device to be notified.
Better control over notifications
If you are interested in having better control over the look and styling of Android notifications including HTML tags, links and whatnot – the AutoNotification plug-in is the answer. Take a look at my Perfect Notification article to take your notifications to the next level and style it the way you want.
Final thoughts
It’s a very simple add-on, but can be extremely useful. Similar data I available via the ZigBee2MQTT dashboard, but checking it daily is a chore – and no one likes hard work. Over the next few weeks, I’ll put some time aside to merge this project with my ZigBee low battery warning. It will give me the motivation to streamline that old project as NodeRED has gotten new tools since then. Let me know what you think in this Reddit thread.