Conditions - alarm project

Hi all! It's my first node red and I'm trying to make an mqtt arduino alarm.

I need help on how can I do something like this:
If door_open_topic="open" AND alarm_topic="armed" THEN do this and that...

Thanks for the help guys!

So I’m guessing you’ve realised that a node in node-RED has no memory of previous messages. There are several ways of getting the status of two messages together in Node-RED. One way is to use the join node the other way is to store one of the message values, see this part of the docs

https://nodered.org/docs/writing-functions#storing-data

Here is one example. Your conditions are set in a global variable. The payload only passes when both of them are true.

[{"id":"156b11a0.14c1ee","type":"inject","z":"1f481add.f1d5e5","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":40,"wires":[["339345ba.ce389a"]]},{"id":"339345ba.ce389a","type":"change","z":"1f481add.f1d5e5","name":"","rules":[{"t":"set","p":"door_open_topic","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":60,"wires":[[]]},{"id":"6418d271.0b747c","type":"inject","z":"1f481add.f1d5e5","name":"","topic":"","payload":"ALARM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":200,"wires":[["79abb755.831178"]]},{"id":"d43a1e7d.56035","type":"inject","z":"1f481add.f1d5e5","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":80,"wires":[["339345ba.ce389a"]]},{"id":"e5555548.403698","type":"inject","z":"1f481add.f1d5e5","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":120,"wires":[["c1d1b731.1ace88"]]},{"id":"c1d1b731.1ace88","type":"change","z":"1f481add.f1d5e5","name":"","rules":[{"t":"set","p":"alarm_topic","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":140,"wires":[[]]},{"id":"1e77dcff.e8a703","type":"inject","z":"1f481add.f1d5e5","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":160,"wires":[["c1d1b731.1ace88"]]},{"id":"79abb755.831178","type":"switch","z":"1f481add.f1d5e5","name":"","property":"door_open_topic","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":200,"wires":[["7e5f9789.1993a8"]]},{"id":"7e5f9789.1993a8","type":"switch","z":"1f481add.f1d5e5","name":"","property":"alarm_topic","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":200,"wires":[["acbc913e.ac345"]]},{"id":"acbc913e.ac345","type":"debug","z":"1f481add.f1d5e5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":490,"y":200,"wires":[]}]

If you'd like to check many conditions you should take a look at node-red-contrib-bool-gate

Made it!

Thank you so much!