# Evitar falsos positivos with sensor

**URL:** https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286
**Category:** General
**Created:** [23 October 2023 15:09 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286 "2023-10-23T15:09:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![manuugonz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manuugonz/32/84020_2.png) [@manuugonz](https://discourse.nodered.org/u/manuugonz)
#### Post date: [23 October 2023 15:09 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/1 "2023-10-23T15:09:43Z")

</div>

Hello,

I am somewhat new to NODE RED; very very new indeed.  
I am experimenting to make automations in Home Assistant with ESPHOME. I have a proximity sensor that depending on the distance I want to activate or deactivate a small fan. So far so good. Then, the problem is that my sensor ( TOF10120 ) sends erroneous values from time to time that make the fan turn on; something I don't want. Then I had thought that if there was some option to tell NODE RED that it has to receive at least 2 or 3 values between X and Y in a row for the fan to be activated; thus avoiding false positives. Would anyone know how to do it?

I don't know if there is another way to do it, here is the current scheme, receiving a single value.  
Thanks!!  
Manu

 ![Captura de pantalla 2023-10-23 a las 17.08.15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/022be4885ac8da7d23f4fbbe6c2d67163795d2c5.png)

False positives of 0.208mm can be seen.

 ![Captura de pantalla 2023-10-23 a las 17.10.13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02bd78a18f5e878d4e2ce7444e4c18fe9b7d4179.png)

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [23 October 2023 16:54 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/2 "2023-10-23T16:54:50Z")

</div>

Hi @manuugonz

You already know the `switch` Node by the looks of it.

so:

- Before you do anything filter out "unknown"  
 ![Screenshot 2023-10-23 at 17.42.30](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75ebaedac6f532a5fda4fc6d75457450cebad027.png)

- Then, using a combination of `switch` and `change` ensure you get 2 values in the range you need in a row. the trick here is to reset the `join` node if it receives a value outside your range

The `join` node will output an array of your values in the range you need (I set 2 payloads)

 ![Screenshot 2023-10-23 at 17.54.19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de67ac99fe7fac2c4585778c7838d45b8ed53a46.png)

```auto
[{"id":"46a73927200ca4b5","type":"switch","z":"2d7bf6e3.84c97a","name":"Filter out \"unknown\"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"unknown","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":235,"y":860,"wires":[["3c65b976ad61978e"]]},{"id":"3c65b976ad61978e","type":"switch","z":"2d7bf6e3.84c97a","name":"Between : 100-200","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"100","vt":"num","v2":"200","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":495,"y":860,"wires":[["ab7698ef45e7d8ad"],["be7b15a4c63d0290"]]},{"id":"ab7698ef45e7d8ad","type":"join","z":"2d7bf6e3.84c97a","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":885,"y":855,"wires":[[]]},{"id":"be7b15a4c63d0290","type":"change","z":"2d7bf6e3.84c97a","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":705,"y":900,"wires":[["ab7698ef45e7d8ad"]]}]

```

---

<div class="post-metadata">

### Author: ![manuugonz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manuugonz/32/84020_2.png) [@manuugonz](https://discourse.nodered.org/u/manuugonz)
#### Post date: [23 October 2023 20:23 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/3 "2023-10-23T20:23:54Z")

</div>

Hello,

I have tried what you tell me, but I don't quite understand where I should implement it, since the unknown value is a value that I already have set to Off (since it is when the sensor does not detect people), we could say that unknown would be when the value is higher than 2,000. But the "ghost" parameter is 0.208.

I have added my code because I have tried to add what you told me but it seems somewhat complex.

`[{"id":"f17a47346e4b60b7","type":"server-state-changed","z":"b46229fa78a0b009","name":"Distancia Baño","server":"fcef64af.20cf18","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"sensor.sensor_padre_distancia_bao","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":100,"y":320,"wires":[["e3e4774d2ad3fac5"]]},{"id":"cc75b44b07c67d0c","type":"debug","z":"b46229fa78a0b009","name":"JSON Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":280,"wires":[]},{"id":"e3e4774d2ad3fac5","type":"switch","z":"b46229fa78a0b009","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"0.5","vt":"num"},{"t":"gt","v":"0.9","vt":"num"},{"t":"cont","v":"unknown","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":270,"y":260,"wires":[["41c9cc2948e9bf77"],["931f904faf86e8af"],["931f904faf86e8af"]]},{"id":"41c9cc2948e9bf77","type":"api-call-service","z":"b46229fa78a0b009","name":"","server":"fcef64af.20cf18","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":["1704b1b9e959afc6bf5deeaf90575539"],"entityId":["switch.humificador_tapo1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":540,"y":120,"wires":[["cc75b44b07c67d0c"]]},{"id":"931f904faf86e8af","type":"api-call-service","z":"b46229fa78a0b009","name":"","server":"fcef64af.20cf18","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":["1704b1b9e959afc6bf5deeaf90575539"],"entityId":["switch.humificador_tapo1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":540,"y":200,"wires":[["cc75b44b07c67d0c"]]},{"id":"fcef64af.20cf18","type":"server","name":"Home Assistant","addon":true}]`

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [23 October 2023 21:09 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/4 "2023-10-23T21:09:13Z")

</div>

> [@manuugonz](#):
>
> Then I had thought that if there was some option to tell NODE RED that it has to receive at least 2 or 3 values between X and Y in a row

My example does that.

I have simplified it with an example - execute the injects in order they appear, and you will see the effect.  
replace the 4 injects with your input of course when in production.

```auto
[{"id":"12fdf9e0ab46c6f8","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"3c65b976ad61978e","type":"switch","z":"12fdf9e0ab46c6f8","name":"Between : 100-200","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"100","vt":"num","v2":"200","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":425,"y":350,"wires":[["ab7698ef45e7d8ad"],["be7b15a4c63d0290"]]},{"id":"ab7698ef45e7d8ad","type":"join","z":"12fdf9e0ab46c6f8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":805,"y":345,"wires":[["55a092ae28e686da"]]},{"id":"be7b15a4c63d0290","type":"change","z":"12fdf9e0ab46c6f8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":635,"y":390,"wires":[["ab7698ef45e7d8ad"]]},{"id":"12187cd51da1e8ae","type":"inject","z":"12fdf9e0ab46c6f8","name":"67 (erroneous)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"67","payloadType":"str","x":190,"y":335,"wires":[["3c65b976ad61978e"]]},{"id":"64f84d954ec4c01d","type":"inject","z":"12fdf9e0ab46c6f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"156","payloadType":"num","x":220,"y":275,"wires":[["3c65b976ad61978e"]]},{"id":"cfaeeaa0cb356de9","type":"inject","z":"12fdf9e0ab46c6f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"101","payloadType":"num","x":215,"y":385,"wires":[["3c65b976ad61978e"]]},{"id":"3bddcb868f1239b6","type":"inject","z":"12fdf9e0ab46c6f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"189","payloadType":"num","x":215,"y":440,"wires":[["3c65b976ad61978e"]]},{"id":"55a092ae28e686da","type":"debug","z":"12fdf9e0ab46c6f8","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":345,"wires":[]}]

```

 ![Screenshot 2023-10-23 at 22.10.25](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9268f8576cfd00a795d1f6601eb3079932a8e11.png)

I cant import your flow as I don't use HA - many hear don't

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [23 October 2023 21:13 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/5 "2023-10-23T21:13:05Z")

</div>

> [@manuugonz](#):
>
> But the "ghost" parameter is 0.208.

Is it always 0.208? You can use a switch node to filter out this specific value.

---

<div class="post-metadata">

### Author: ![manuugonz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manuugonz/32/84020_2.png) [@manuugonz](https://discourse.nodered.org/u/manuugonz)
#### Post date: [24 October 2023 14:16 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/6 "2023-10-24T14:16:02Z")

</div>

Hello,

I already managed to put what he sent me, the problem is that it is not entirely correct.

When the sensor is more than 2,000 mm or unknown then it makes the false parameter 0.208. But of course, to turn it on it is possible that the value to activate is 0.200m or 0.215, so I really want to "deactivate" the value 0.208, as @jbudd comments. I need to "isolate" or disable that value. Since when it detects something below 2.0000mm the ghost value does not appear, at least for the moment.

---

<div class="post-metadata">

### Author: ![manuugonz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manuugonz/32/84020_2.png) [@manuugonz](https://discourse.nodered.org/u/manuugonz)
#### Post date: [24 October 2023 14:16 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/7 "2023-10-24T14:16:32Z")

</div>

Yess!, always

---

<div class="post-metadata">

### Author: ![manuugonz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manuugonz/32/84020_2.png) [@manuugonz](https://discourse.nodered.org/u/manuugonz)
#### Post date: [24 October 2023 14:19 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/8 "2023-10-24T14:19:23Z")

</div>

@marcus-j-davies @jbudd It just occurred to me that I can apply the same method, for ranges between 0.000 to 0.205 and 0.207 to 2.000. And let it be deactivated in unknown. This is somewhat "tacky", but is there any way to disable that value? let it not be this way

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [24 October 2023 15:58 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/9 "2023-10-24T15:58:41Z")

</div>

> [@manuugonz](#):
>
> but is there any way to disable that value? let it not be this way

I'm getting dizzy, but if you want to disregard, ignore, not act on that value, do as @jbudd suggests - filter it out in a `switch` node

Connect this directly to the output of what ever is producing that value - it will then NOT pass through, so any nodes downstream will NEVER see this value

![Screenshot 2023-10-24 at 16.57.14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a389a818f67c9a5ce7a1fe52d6b3d551e7883c95.png)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 December 2023 15:59 UTC](https://discourse.nodered.org/t/evitar-falsos-positivos-with-sensor/82286/10 "2023-12-23T15:59:37Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
