Evitar falsos positivos with sensor

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

False positives of 0.208mm can be seen.

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

  • 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)

[{"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"]]}]

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}]

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.

[{"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":[]}]

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

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

1 Like

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.

Yess!, always

@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

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

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