# Alarm System with ON/OFF switch

**URL:** <https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819>\
**Category:** General\
**Created:** [17 October 2019 14:06 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819 "2019-10-17T14:06:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![maku12](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maku12](https://discourse.nodered.org/u/maku12)\
**Post date:** [17 October 2019 14:06 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/1 "2019-10-17T14:06:34Z")

</div>

Hi, I want to create an alarm system in node red. I have a Xiaomi Door Sensor which is already implemented in iobroker.  
The iobroker node sends a message to the Telegram node when the sensor is open, which is already working.  
Now i want to add a switch, where I can toggle on and off the alarm system. So if the switch is off and sensor is open no message should be send to telegram, only when the switch is on.

Many Thanks for helping

---

<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:** [17 October 2019 14:42 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/2 "2019-10-17T14:42:57Z")

</div>

Take a look at the context examples in the cookbook

[https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

---

<div class="post-metadata">

**Author:** ![maku12](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maku12](https://discourse.nodered.org/u/maku12)\
**Post date:** [18 October 2019 08:15 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/3 "2019-10-18T08:15:32Z")

</div>

Hi, i tried to adapt the flow based on the cookbook example. Thanks for the hint.

But I cannot get on there.

If I click on close or open on the incjet node, there only should be an output,  
if Alarm ist set to ON (armed). If Alarm is set to OFF there should be no output. (disarmed)

I don't know how to implement the additional code.

Many Thanks for your help.

[flow.json](https://discourse.nodered.org/uploads/short-url/5vCOhiadeHdMYwAub1nQwUtlVD2.json) (2.2 KB)

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7e9df615ed188c36fd0c6d8f15d647cd9f5f9e5f.jpeg)

---

<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:** [18 October 2019 08:31 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/4 "2019-10-18T08:31:42Z")

</div>

I’m on my phone so can’t look at your flow.

But basically you set the context value in the manual flow (eg alarm\_set = “On”)

Then in the switch in your Door sensor flow,  
have a switch that only allow messages through if alarm\_set is “On”

---

<div class="post-metadata">

**Author:** ![maku12](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maku12](https://discourse.nodered.org/u/maku12)\
**Post date:** [18 October 2019 08:51 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/5 "2019-10-18T08:51:58Z")

</div>

hmmm, i don't know exactly what you mean, maybe you can show me later in the flow?

thx

---

<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:** [18 October 2019 09:41 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/6 "2019-10-18T09:41:10Z")

</div>

Play with the example in the cookbook it’s exactly what it does

---

<div class="post-metadata">

**Author:** ![maku12](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maku12](https://discourse.nodered.org/u/maku12)\
**Post date:** [19 October 2019 19:48 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/7 "2019-10-19T19:48:21Z")

</div>

Hi, i tried many things to get this running, but unfortunately i failed.

Maybee any suggestions, this would be great.

Thank you

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 October 2019 20:49 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/8 "2019-10-19T20:49:37Z")

</div>

The flow as shown works as I expect.

I am missing what you mean when you say:

> [@maku12](#):
>
> If I click on close or open on the incjet node, there only should be an output,  
> if Alarm ist set to ON (armed). If Alarm is set to OFF there should be no output. (disarmed)

That is what happens, or what I see.

Ok, rethinking it.  
You are a bit confused I think.

If you only want to see messages when the alarm is activated, then you already have that. It is just you don't need to see/have the other `debug` node.

(By the way the `alarm ON` node has a blue dot. I'm guessing that is because you activated it's output?)

Deactivate the `Alarm OFF` node and just ignore it.

You get an output in the `Alarm ON` node if the alarm is active.

What else do you want?

---

<div class="post-metadata">

**Author:** ![maku12](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maku12](https://discourse.nodered.org/u/maku12)\
**Post date:** [21 October 2019 10:08 UTC](https://discourse.nodered.org/t/alarm-system-with-on-off-switch/16819/9 "2019-10-21T10:08:09Z")

</div>

Hi,

ah , ok now I got it. I had an error in reasoning.

thanks all for the feedback.
