Zigbee fire alarm MQTT message action

My Zigbee fire alarm sends different MQTT status messages but if there is a fire this is one of the unique messages:

{"ZbReceived":{"0xCB76":{"Device":"0xCB76","EF00/020F":100,"Endpoint":1,"LinkQuality":87}}}

To be more precise, the part "EF00/020F:100" is unique.

Can anyone tell me how to set up a (switch?) node so that there is only action when the above message arrives?

Here is a simple flow you can use - node you will feed the switch with the mqtt-in data

[{"id":"bd8d338ef133cb1a","type":"inject","z":"47b962d7577cfddb","name":"100","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ZbReceived\":{\"0xCB76\":{\"Device\":\"0xCB76\",\"EF00/020F\":100,\"Endpoint\":1,\"LinkQuality\":87}}}","payloadType":"json","x":230,"y":180,"wires":[["6bc9b28b0ed61f0f"]]},{"id":"8431c3d828a36f6e","type":"debug","z":"47b962d7577cfddb","name":"100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.ZbReceived[\"0xCB76\"][\"EF00/020F\"]","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":180,"wires":[]},{"id":"6bc9b28b0ed61f0f","type":"switch","z":"47b962d7577cfddb","name":"","property":"payload.ZbReceived[\"0xCB76\"][\"EF00/020F\"]","propertyType":"msg","rules":[{"t":"eq","v":"100","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":220,"wires":[["8431c3d828a36f6e"],["5e21526f57d9143b"]]},{"id":"920bd8632cb74fd6","type":"inject","z":"47b962d7577cfddb","name":"999","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ZbReceived\":{\"0xCB76\":{\"Device\":\"0xCB76\",\"EF00/020F\":999,\"Endpoint\":1,\"LinkQuality\":87}}}","payloadType":"json","x":230,"y":240,"wires":[["6bc9b28b0ed61f0f"]]},{"id":"5e21526f57d9143b","type":"debug","z":"47b962d7577cfddb","name":"not 100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.ZbReceived[\"0xCB76\"][\"EF00/020F\"]","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":240,"wires":[]}]

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

1 Like

In Node-RED, when trying to work out how to extract data from an object, the easiest way is to add a debug node. Here I simulate what your mqtt-in node would do

image

With the debug output looking like this

image

In this grab, the mouse was hovering over the copy path button which you can click to get payload.ZbReceived["0xCB76"]["EF00/020F"].

You can put this into a switch node

image

Noting that the output is a number not a string.

Now, there may be a complexity if you have >1 alarm device and want to trigger on any of them. In that case the ["0xCB76"] part will be a problem as I assume it represents a specific device.

There are various ways to get around that issue. Personally I would probably use a function node. And if doing that, there really isn't any point in also having a switch, may as well do it all in the function.

// Check if msg.payload (optionally) contains ZbReceived
if (msg.payload?.ZbReceived) {
    const zbr = msg.payload.ZbReceived
    if (zbr["EF00/020F"] && zbr["EF00/020F"] === 100) {
        return msg
    }
}
1 Like

When I encountered this problem and it did not solve it after a few hours of trying, I posted a message here. It is very nice that there are people to help like in this case.

My "problem" is solved, thank you both for your help!

1 Like

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