# Conditions - alarm project

**URL:** <https://discourse.nodered.org/t/conditions-alarm-project/5602>\
**Category:** General\
**Created:** [9 December 2018 09:42 UTC](https://discourse.nodered.org/t/conditions-alarm-project/5602 "2018-12-09T09:42:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glorifiedg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/glorifiedg/32/4373_2.png) [@Glorifiedg](https://discourse.nodered.org/u/Glorifiedg)\
**Post date:** [9 December 2018 09:42 UTC](https://discourse.nodered.org/t/conditions-alarm-project/5602/1 "2018-12-09T09:42:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [9 December 2018 10:35 UTC](https://discourse.nodered.org/t/conditions-alarm-project/5602/2 "2018-12-09T10:35:45Z")

</div>

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](https://nodered.org/docs/writing-functions#storing-data)

---

<div class="post-metadata">

**Author:** ![Jaxn](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Jaxn](https://discourse.nodered.org/u/Jaxn)\
**Post date:** [9 December 2018 10:38 UTC](https://discourse.nodered.org/t/conditions-alarm-project/5602/3 "2018-12-09T10:38:52Z")

</div>

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

```auto
[{"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](https://www.npmjs.com/package/node-red-contrib-bool-gate)

---

<div class="post-metadata">

**Author:** ![Glorifiedg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/glorifiedg/32/4373_2.png) [@Glorifiedg](https://discourse.nodered.org/u/Glorifiedg)\
**Post date:** [9 December 2018 13:17 UTC](https://discourse.nodered.org/t/conditions-alarm-project/5602/4 "2018-12-09T13:17:00Z")

</div>

Made it!

Thank you so much!
