# Show if sensor is ative or inactive

**URL:** https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957
**Category:** General
**Created:** [14 February 2019 11:05 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957 "2019-02-14T11:05:59Z")
**Posts on this page:** 16
**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: [14 February 2019 11:05 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/1 "2019-02-14T11:05:59Z")

</div>

I´m testing if a sensor is active or inactive, i used the trigger but not resolved my problem, i´m tried use this way but the problem to be continue:

 ![959d27465eb92de2c680919ac9bdee5d1a349dee.png](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/959d27465eb92de2c680919ac9bdee5d1a349dee.png)

My function is programmed like this:

```auto
if (typeof msg.payload === 'number') {
    msg.payload = true;
} else {
    msg.payload= false;
}
return msg;

```

When I run the program this gives me the following values ​​of msg.payload:

```auto
14/02/2019, 09:45:01[node: test function](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : boolean
true

14/02/2019, 09:45:01[node: value received](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : number
32.82964323001333

```

in the dasboard the led when it is true is green but when the sensor stops sending data it does not turn red (value false). The msg.payload of value received when sensor stops not send any value and not turn to red.

---

<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:12 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/2 "2019-02-14T11:12:10Z")

</div>

You now have 3 threads all on the same topic....  
tell me which one you want to use in preference and I will lock the others to stop others getting confused.

> [@Database not receive the data when one sensor stops](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/35):
>
> I use this thread. I testing another way for my problem but i still in the same, the way i´m used is this: My function is programmed like this: if (typeof msg.payload === 'number') { msg.payload = true; } else { msg.payload= false; } return msg; When I run the program this gives me the following values ​​of msg.payload: 14/02/2019, 09:45:01[node: test function](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : boolean true 14/02/2019, 09:45:01[node: value …

> [@Message ON/OFF in case one sensor Stop working](https://discourse.nodered.org/t/message-on-off-in-case-one-sensor-stop-working/7920/16):
>
> 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: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [14 February 2019 11:19 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/3 "2019-02-14T11:19:50Z")

</div>

I prefere this thread, because is more explicit

---

<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: [14 February 2019 11:36 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/4 "2019-02-14T11:36:56Z")

</div>

can you help me, i´m working about two days in this and i'm not be capable of finding a solution works correctly

---

<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:40 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/5 "2019-02-14T11:40:46Z")

</div>

cut/paste the output from the first debug node - i.e. what is going into your function - and how often it goes in when working - and what is the time to say it is no longer arriving. (IE what is the repeat time on your inject node)  
I should think a simple trigger node would work fine if it's just got to light up an led if configured correctly

---

<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: [14 February 2019 11:47 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/6 "2019-02-14T11:47:14Z")

</div>

This is the value of first debug , the value that is going to my function  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2188cc16df05c07fe0aa20155aeac90a2a77193c.png)  
and the injection node configuration is

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

and if for some reason the sensor stops sending data (as a sensor problem), the led should turn red to inform the person that the sensor has problems

---

<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: [14 February 2019 11:55 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/7 "2019-02-14T11:55:28Z")

</div>

[quote="smalhao, post:6, topic:7957"]  
This is the value of first debug , the value that is going to my function  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2188cc16df05c07fe0aa20155aeac90a2a77193c.png)  
and the injection node configuration is

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

The OPC-UA Client configuration i forget show  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8d421a366d7cd8a94d8631bab4c5d9b355179240.png)  
and if for some reason the sensor stops sending data (as a sensor problem), the led should turn red to inform the person that the sensor has problems

---

<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 12:17 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/8 "2019-02-14T12:17:52Z")

</div>

so maybe replace your function with this

```
[{"id":"b49bd44b.b8ab38","type":"trigger","z":"82738787.0e0338","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"5000","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":430,"y":1000,"wires":[["3df4d920.b6d216"]]}]

```

as long as messages keep arriving the output will be true... if nothing is seen for 5 seconds it will go false

---

<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: [14 February 2019 12:27 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/9 "2019-02-14T12:27:51Z")

</div>

> [@dceejay](#):
>
> as long as messages keep arriving the output will be true... if nothing is seen for 5 seconds it will go false

and i put the trigger in between the output of Subscribe Indutive sensor and function or in between function and led?

---

<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 12:32 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/10 "2019-02-14T12:32:11Z")

</div>

remove / replace your function node completely

so between inductive read - and led

---

<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: [14 February 2019 14:07 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/11 "2019-02-14T14:07:53Z")

</div>

> [@dceejay](#):
>
> remove / replace your function node completely
> 
> so between inductive read - and led

Which is what I have been saying all along of course, @smalhao was nearly there but then went off at a tangent again instead of asking if he did not understand the suggestions.

---

<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: [14 February 2019 14:30 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/12 "2019-02-14T14:30:31Z")

</div>

> [@Colin](#):
>
> Which is what I have been saying all along of course, @smalhao was nearly there but then went off at a tangent again instead of asking if he did not understand the suggestions.

I apologize, in fact I did not understand the suggestions, in particular the way the Trigger applied, the next time I do not understand the suggestions and how to apply them I will ask how the blocks apply, only recently I started programming in Node- Red and I have some difficulty understanding the functions of library blocks because I have little experience of programming with Node-Red.

---

<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 15:22 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/13 "2019-02-14T15:22:03Z")

</div>

No problem - we all had to start somewhere/sometime.  
The [http://noderedguide.com/](http://noderedguide.com/) and the cookbook - [https://cookbook.nodered.org/](https://cookbook.nodered.org/) are getting better - and are worth looking through when you get some time.

---

<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: [14 February 2019 15:42 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/14 "2019-02-14T15:42:56Z")

</div>

> [@dceejay](#):
>
> No problem - we all had to start somewhere/sometime.  
> The [http://noderedguide.com/](http://noderedguide.com/) and the cookbook - [https://cookbook.nodered.org/](https://cookbook.nodered.org/) are getting better - and are worth looking through when you get some time.

Thanks for the sugestion.

I wanted to ask about the dashboard, is that when it refresh alone the browser, "Connection Lost" appears, and i have the server connected. I would like to ask what could be this error and solutions? I've been looking and no see anything.

---

<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: [14 February 2019 15:45 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/15 "2019-02-14T15:45:07Z")

</div>

Best to start a new thread for that. When you do so give us more information about where the server is running, what you are running the browser on are they both on the same local network and so on.

---

<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: [14 February 2019 15:51 UTC](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/16 "2019-02-14T15:51:22Z")

</div>

> [@Colin](#):
>
> Best to start a new thread for that. When you do so give us more information about where the server is running, what you are running the browser on are they both on the same local network and so on.

Ok i iniciate a new thread
