# Message ON/OFF in case one sensor Stop working

**URL:** <https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920>\
**Category:** General\
**Created:** [13 February 2019 09:22 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920 "2019-02-13T09:22:19Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 09:22 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/1 "2019-02-13T09:22:19Z")

</div>

I have 3 sensors to send data but I need that in case any stops sending data show a message in the dashboard for example when it is active show ON and when it is inactive show OFF, the ideia is create a alert message.  
If you compare the current value with the previous one and if it is the same it is signal that the sensor is stopped and then it should send a message saying OFF but the current value is different from the previous one it should send message to say ON.  
I have a Join node with this configuration

```auto
[{"id":"f9879ec5.a91d6","type":"join","z":"caaedfb9.ac4da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"15","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1597.1000061035156,"y":314,"wires":[["a4a957e.0e191a8","bba2a16.1af466"]]}]

```

and i need compare the values of array

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 February 2019 09:25 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/2 "2019-02-13T09:25:38Z")

</div>

see - [Trigger Email if Input not recevied since x minutes?](https://discourse.nodered.org/t/trigger-email-if-input-not-recevied-since-x-minutes/2909)

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 09:38 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/3 "2019-02-13T09:38:15Z")

</div>

I tried the Trigger and I have the sensor active but I get an OFF, the Inject configuration is as follows:

```auto
[
    {
        "id": "20020f02.5964a",
        "type": "inject",
        "z": "caaedfb9.ac4da",
        "name": "Inject Inductive Sensor",
        "topic": "ns=2;s=SensorIndutivo",
        "payload": "",
        "payloadType": "num",
        "repeat": "10",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 143.00005340576172,
        "y": 741.0000114440918,
        "wires": [
            [
                "1d56aab1.c971c5"
            ]
        ]
    }
]

```

and Trigger configuration is:

```auto
[
    {
        "id": "1d56aab1.c971c5",
        "type": "trigger",
        "z": "caaedfb9.ac4da",
        "op1": "",
        "op2": "OFF",
        "op1type": "str",
        "op2type": "str",
        "duration": "10",
        "extend": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "name": "",
        "x": 268.90002822875977,
        "y": 870.0000133514404,
        "wires": [
            [
                "647046d0.7b5b38",
                "eeea9976.35ecb8"
            ]
        ]
    }
]

```

and i receive in debug

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/12f0ce5cdbb708b4e39c6234a6aba99abb019b2b.png)

The sensor is working and send a OFF in Trigger

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 February 2019 09:50 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/4 "2019-02-13T09:50:55Z")

</div>

maybe re-read the instructions...

> the key part is to tick the box `extend delay if new message arrives` .

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 09:52 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/5 "2019-02-13T09:52:12Z")

</div>

I do that and the result is the same

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2019 10:48 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/6 "2019-02-13T10:48:14Z")

</div>

The trigger node is not going to look at a value to see if it has changed, it just looks to see msg's are coming in.

You say you need to monitor to see if a sensor is not sending data - but first some basic questions:

1. What platform/os are you running on?
2. what version of NR, node.js are you using? (look at NR start up log)
3. how often are the sensors sending the data?
4. how are you reading the data - i.e. are the sensors sending the data via MQTT?
5. is it possible a sensor might validly send the same reading twice in a row? (i.e. temperature remains steady)

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 11:14 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/7 "2019-02-13T11:14:02Z")

</div>

The platform i´m using is CompactRIO and Labview, the version of Node-Red is [v0.19.5], the sensors sending data every 10 seconds, i´m reading the data between topics of OPC UA (ex. ns=2;s=LM35), more or less the value of temperature is stable. I send the values to a database

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a9542d11bafef07ffa5f6ee9be5a6bc98d0275fe.png)

and i need detect if the sensor is sending data or not sending data(like show a message ON or OFF  
when one sensor stops sending data( in this case the LM335), in my database the value is undefined like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/343062759202b46d514e2624a21a636d130758c0.png)

---

<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:** [13 February 2019 12:52 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/8 "2019-02-13T12:52:39Z")

</div>

I’m confused your last example where one sensor is undefined is a valid database entry.

What would you want the database to record? Or is it just your dashboard you want to change?

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 13:01 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/10 "2019-02-13T13:01:15Z")

</div>

> [@ukmoose](#):
>
> I’m confused your last example where one sensor is undefined is a valid database entry.
> 
> What would you want the database to record? Or is it just your dashboard you want to change?

For Dasboard i only need to show in dashboard a message (text) that says ON or OFF when the sensor is active (ON) or inactive (OFF), is that i want show in dasboard.

---

<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:** [13 February 2019 13:16 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/11 "2019-02-13T13:16:13Z")

</div>

so the Trigger node should be able to tell you when you don’t get a value when you expect it.  
A switch node should be able to separate that from a true value  
and a change node will be bale then to change msg.payload to On

I would suggest you set up some triggers with different values and have a play

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 14:06 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/12 "2019-02-13T14:06:37Z")

</div>

> [@ukmoose](#):
>
> so the Trigger node should be able to tell you when you don’t get a value when you expect it.  
> A switch node should be able to separate that from a true value  
> and a change node will be bale then to change msg.payload to On
> 
> I would suggest you set up some triggers with different values and have a play

Can you help me to construct this part with Trigger with switch and change?

I've tried use the Trigger but only send a zero when i defined a number

---

<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:** [13 February 2019 14:20 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/13 "2019-02-13T14:20:10Z")

</div>

Not from the train on my phone!  
Show us what you have done, you have all the pieces you need.  
Start with the trigger node, configure it and attach a debug.  
Confirm the messages in the debug, match what you expect.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 February 2019 14:24 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/14 "2019-02-13T14:24:49Z")

</div>

I showed you in the other thread how to configure the trigger node to send On each time a good sample is received, and if the samples stop coming then to send Off.

---

<div class="post-metadata">

**Author:** ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)\
**Post date:** [13 February 2019 14:34 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/15 "2019-02-13T14:34:03Z")

</div>

I've done that way and the result is:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d86088aece7346ab016551a128818a4d321cd759.png)  
the Trigger Confiiguration  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/363530e861ebd9c7febccb71083099168822a578.png)

```auto
13/02/2019, 14:29:38[node: Output Tigger](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : string[2]

"ON"

13/02/2019, 14:29:38[node: Output Tigger](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : string[3]

"OFF"

```

Send ON and OFF together

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 February 2019 14:37 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/16 "2019-02-13T14:37:09Z")

</div>

You have the delay set to 500 milliseconds so it will send one then 0.5 seconds later it sends the other. You need to set the timeout larger than the normal time between samples.  
Also you do not want to send ON or OFF to the Join node, that should still be connected direct to the sensor.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 February 2019 11:21 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/17 "2019-02-14T11:21:28Z")

</div>

Moved to [Show if sensor is ative or inactive](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/2)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 February 2019 11:21 UTC](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/18 "2019-02-14T11:21:33Z")

</div>


