# Filter sensor data

**URL:** <https://discourse.nodered.org/t/filter-sensor-data/43775>\
**Category:** General\
**Created:** [6 April 2021 17:24 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775 "2021-04-06T17:24:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [6 April 2021 17:24 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/1 "2021-04-06T17:24:48Z")

</div>

Hello,  
I have a sonoff th10 temperature and relay board flashed with tasmota (9.3.1). The one with the SI7021 sensor. I guess it's a firmware thing and or hardware problem, the measurements (on the tasmota web interface) someties show "null", but not that often.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9a79183ba21ea15231679a300769636b6704606.png)

The problem is; this gets transmitted over mqtt and node red, which shows something like this in a debug node hooked to the tasmota sensor node; "TypeError: Cannot read property 'hasOwnProperty' of null".

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

Now I'm past the point of investigating this on tasmota level like a hw or fw issue because i lack the knowledge.  
Is there a fancy js fuction or node which would ignore this error and substitute the value with the oldest healthy value to pass it on until the tasmota resumes from its "seisure"?  
Thanks in advance.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/349d91fb9ef6030c019449d38b88d997ee04b0b9.png)

```auto
[{"id":"5bce5d10.c72dc4","type":"Tasmota Sensor","z":"ae6391de.2859e","broker":"a36e2f8a.1c6a6","device":"Meteo","name":"Meteo","outputs":1,"uidisabler":false,"fullTopic":"","cmndPrefix":"","statPrefix":"","telePrefix":"","rules":[],"x":290,"y":40,"wires":[["2ea6696e.d36116","c26b3d62.dda0b","59b65171.29118"]]},{"id":"47bd8f42.be086","type":"ui_gauge","z":"ae6391de.2859e","name":"TempGauge","group":"c4b3876e.5da4c8","order":1,"width":0,"height":0,"gtype":"donut","title":"Hőmérséklet","label":"°C","format":"{{value}}","min":"-25","max":"45","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1070,"y":100,"wires":[]},{"id":"61a606e0.6fa538","type":"ui_chart","z":"ae6391de.2859e","name":"TempGraph","group":"c4b3876e.5da4c8","order":1,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"N/A","dot":false,"ymin":"-25","ymax":"45","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1070,"y":160,"wires":[[]]},{"id":"485e6d35.c190e4","type":"smooth","z":"ae6391de.2859e","name":"AvgFltTemp","property":"payload","action":"mean","count":"30","round":"1","mult":"multi","reduce":true,"x":870,"y":100,"wires":[["61a606e0.6fa538","47bd8f42.be086"]]},{"id":"3e1da494.88b2fc","type":"inject","z":"ae6391de.2859e","name":"TRUE 3s","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":110,"y":40,"wires":[["5bce5d10.c72dc4"]]},{"id":"2ea6696e.d36116","type":"function","z":"ae6391de.2859e","name":"HumFunc","func":"var MeteoHum = { payload: msg.payload.SI7021.Humidity };\nreturn MeteoHum;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":40,"wires":[["d91adacf.9f41e8"]]},{"id":"1b6a81e7.1d8a7e","type":"rbe","z":"ae6391de.2859e","name":"ErrorFltTemp","func":"rbei","gap":"0%","start":"","inout":"in","septopics":true,"property":"payload","x":670,"y":100,"wires":[["485e6d35.c190e4"]]},{"id":"59b65171.29118","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.SI7021.Temperature","targetType":"msg","statusVal":"payload","statusType":"auto","x":540,"y":160,"wires":[]},{"id":"c26b3d62.dda0b","type":"function","z":"ae6391de.2859e","name":"HumTemp","func":"var MeteoTemp = { payload: msg.payload.SI7021.Temperature };\nreturn MeteoTemp;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":100,"wires":[["1b6a81e7.1d8a7e"]]},{"id":"2b281dc3.d1c6c2","type":"ui_text","z":"ae6391de.2859e","group":"c4b3876e.5da4c8","order":2,"width":0,"height":0,"name":"HumText","label":"Páratartalom:","format":"{{value}}%","layout":"row-center","x":1060,"y":40,"wires":[]},{"id":"166106fd.ac5099","type":"smooth","z":"ae6391de.2859e","name":"MaxFltHum","property":"payload","action":"mean","count":"30","round":"1","mult":"multi","reduce":true,"x":870,"y":40,"wires":[["2b281dc3.d1c6c2"]]},{"id":"d91adacf.9f41e8","type":"rbe","z":"ae6391de.2859e","name":"ErrorFltHum","func":"rbei","gap":"0%","start":"","inout":"in","septopics":true,"property":"payload","x":670,"y":40,"wires":[["166106fd.ac5099"]]},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c4b3876e.5da4c8","type":"ui_group","name":"Default","tab":"58b1cb11.885b84","order":1,"disp":false,"width":"7","collapse":false},{"id":"58b1cb11.885b84","type":"ui_tab","name":"Hőmérséklet","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 April 2021 18:42 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/2 "2021-04-06T18:42:27Z")

</div>

I would think a rouge value is being passed or a undefined property. You would be best validating the sensor value and property exists.  
here is an example, I took some guesses as I do not have any input data and I dont't have smooth installed.

This example will only allow a value to pass if it is a number and the sensor property exists. You could add more conditionals I just added two.

```auto
[{"id":"3e1da494.88b2fc","type":"inject","z":"5a245aa1.510164","name":"20.56","props":[{"p":"msg.payload.SI7021.Humidity","v":"20.56","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":4580,"wires":[["2ea6696e.d36116"]]},{"id":"2ea6696e.d36116","type":"function","z":"5a245aa1.510164","name":"HumFunc","func":"if(msg.payload.SI7021 && !isNaN(msg.payload.SI7021.Humidity)){\n var MeteoHum = { payload: msg.payload.SI7021.Humidity };\n return MeteoHum;\n}else{\n return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":4580,"wires":[["b4445253.72c9a8"]]},{"id":"dccfd3db.8890f8","type":"inject","z":"5a245aa1.510164","name":"undefined","props":[{"p":"msg.payload","v":"","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":170,"y":4700,"wires":[["2ea6696e.d36116"]]},{"id":"a1693191.0c6dc","type":"inject","z":"5a245aa1.510164","name":"string","props":[{"p":"msg.payload.SI7021.Humidity","v":"tex tvalue","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":4640,"wires":[["2ea6696e.d36116"]]},{"id":"b4445253.72c9a8","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":4600,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [6 April 2021 20:02 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/3 "2021-04-06T20:02:55Z")

</div>

thanks for the fast reply, just tried it, unfortunately no luck.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce4c7f07d8daed27e54ac65977afd2c14ee94e59.png)

```auto
[{"id":"5bce5d10.c72dc4","type":"Tasmota Sensor","z":"ae6391de.2859e","broker":"a36e2f8a.1c6a6","device":"Meteo","name":"Meteo","outputs":1,"uidisabler":false,"fullTopic":"","cmndPrefix":"","statPrefix":"","telePrefix":"","rules":[],"x":710,"y":80,"wires":[["2ea6696e.d36116","c26b3d62.dda0b","aadd2e44.7388f"]]},{"id":"47bd8f42.be086","type":"ui_gauge","z":"ae6391de.2859e","name":"GaugeTemp","group":"c4b3876e.5da4c8","order":1,"width":0,"height":0,"gtype":"donut","title":"Hőmérséklet","label":"°C","format":"{{value}}","min":"-25","max":"45","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1290,"y":140,"wires":[]},{"id":"61a606e0.6fa538","type":"ui_chart","z":"ae6391de.2859e","name":"GraphTemp","group":"c4b3876e.5da4c8","order":1,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"N/A","dot":false,"ymin":"-25","ymax":"45","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1290,"y":200,"wires":[[]]},{"id":"485e6d35.c190e4","type":"smooth","z":"ae6391de.2859e","name":"MaxFltTemp","property":"payload","action":"max","count":"30","round":"1","mult":"multi","reduce":true,"x":1090,"y":140,"wires":[["47bd8f42.be086","61a606e0.6fa538"]]},{"id":"3e1da494.88b2fc","type":"inject","z":"ae6391de.2859e","name":"TRUE 3s","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":530,"y":80,"wires":[["5bce5d10.c72dc4"]]},{"id":"2ea6696e.d36116","type":"function","z":"ae6391de.2859e","name":"FuncHum","func":"if(msg.payload.SI7021 && !isNaN(msg.payload.SI7021.Humidity)){\n var MeteoHum = { payload: msg.payload.SI7021.Humidity };\n return MeteoHum;\n}else{\n return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":880,"y":80,"wires":[["166106fd.ac5099"]]},{"id":"c26b3d62.dda0b","type":"function","z":"ae6391de.2859e","name":"FuncTemp","func":"if(msg.payload.SI7021 && !isNaN(msg.payload.SI7021.Temperature)){\n var MeteoTemp = { payload: msg.payload.SI7021.Temperature };\n return MeteoTemp;\n}else{\n return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":140,"wires":[["485e6d35.c190e4","78bfff30.dce94"]]},{"id":"2b281dc3.d1c6c2","type":"ui_text","z":"ae6391de.2859e","group":"c4b3876e.5da4c8","order":2,"width":0,"height":0,"name":"TextHum","label":"Páratartalom:","format":"{{value}}%","layout":"row-center","x":1280,"y":80,"wires":[]},{"id":"166106fd.ac5099","type":"smooth","z":"ae6391de.2859e","name":"MaxFltHum","property":"payload","action":"max","count":"30","round":"1","mult":"multi","reduce":true,"x":1090,"y":80,"wires":[["2b281dc3.d1c6c2"]]},{"id":"78bfff30.dce94","type":"debug","z":"ae6391de.2859e","name":"FUNCTION_debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1110,"y":200,"wires":[]},{"id":"aadd2e44.7388f","type":"debug","z":"ae6391de.2859e","name":"NO_FUNCTION_debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.SI7021.Temperature","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":200,"wires":[]},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c4b3876e.5da4c8","type":"ui_group","name":"Default","tab":"58b1cb11.885b84","order":1,"disp":false,"width":"7","collapse":false},{"id":"58b1cb11.885b84","type":"ui_tab","name":"Hőmérséklet","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 April 2021 20:28 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/4 "2021-04-06T20:28:55Z")

</div>

From the image the error is coming from the Tasmota node, I do not have it installed. Hope fully someone here will. What is the nodes name?

[edit] Also set your debugs to show complete msg object.

---

<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:** [6 April 2021 21:03 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/5 "2021-04-06T21:03:42Z")

</div>

> [@E1cid](#):
>
> From the image the error is coming from the Tasmota node

I don't know whether it is co-incidence but there another ongoing question relating to tasmota nodes [ts.startsWith is not a function](https://discourse.nodered.org/t/ts-startswith-is-not-a-function/43750) and there is an associated issue on the node itself [Problem after update to 0.9.8 · Issue #26 · DaveMDS/node-red-contrib-tasmota · GitHub](https://github.com/DaveMDS/node-red-contrib-tasmota/issues/26). Some sort of conflict between the node and mosquitto I think.

Edit: Personally I don't use those nodes for Tasmota devices, I just use mosquitto and go through MQTT directly.

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [7 April 2021 07:19 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/6 "2021-04-07T07:19:46Z")

</div>

Thank you,  
I am new to node red and never used the MQTT node, what am I missing?

Server properties:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75a0350ed65ec93418ebe2c0e85b22b28216f609.png)

Node properties:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a31d448f87f674724a4d1f42dd2e0bc214bfe3e9.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd09d7c4a7f0e1e548c0deeb545698281c4b58f9.png)

```auto
[{"id":"1db61c4c.007214","type":"mqtt in","z":"ae6391de.2859e","name":"Meteo","topic":"Meteo","qos":"2","datatype":"auto","broker":"a36e2f8a.1c6a6","x":180,"y":500,"wires":[["4411a692.bf5d18"]]},{"id":"4411a692.bf5d18","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":480,"y":500,"wires":[]},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

Thank you

---

<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:** [7 April 2021 08:23 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/7 "2021-04-07T08:23:02Z")

</div>

Are you publishing anything to the topic `Meteo`?  
If you replace `Meteo` with `#` then it will show you everything being published.

Also it is worth installing MQTT Explorer on your PC, then you can connect to mosquitto and see what is going on. It is an invaluable tool when using MQTT.

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [7 April 2021 09:04 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/8 "2021-04-07T09:04:04Z")

</div>

The tasmota switch is called "Meteo" at the topic of its web interface so I assume the temperature and humidity should be published automatically?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51e93fe9beaccac7674035babaa63cc823a56236.png)

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58f900f2f7d63566b909a34defb4faab99a7dfa1.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55994ed83195cf4b1f0ec83bbfad7ab6df39aad3.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff4a22d78e5b456d8eb9cb39430fba91b90f0ebd.png)

```auto
[{"id":"a1b6a27d.4ea1c","type":"mqtt in","z":"97595981.4851a8","name":"","topic":"Yard/Meteo/","qos":"2","datatype":"auto","broker":"a36e2f8a.1c6a6","x":430,"y":340,"wires":[["3aba4b32.9ad6c4"]]},{"id":"3aba4b32.9ad6c4","type":"debug","z":"97595981.4851a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":720,"y":340,"wires":[]},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [7 April 2021 10:05 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/9 "2021-04-07T10:05:06Z")

</div>

Turns out no matter what topic I define on the tasmota's web interface to publish to, there are some unchangeable subtopics for the sensor(s) and relay(s) which have to be added on the node red side in the config.  
(Ex.: if the tasmota is publishing on "Meteo" topic, the MQTT node has to be configured to be subscribed on the "Meteo/SENSORS" topic)  
Now this might be obvious for everyone because i lack the experience and this is already grinding the upper psychological border of my investment in this.  
@Colin thank you very much for pointing out this neat MQTT explorer, this kind of resolved everything.  
Now back to building up my own mqtt node for the sensor read and fingers crossed for my original problem's solution.  
Cheers.

---

<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:** [6 June 2021 10:05 UTC](https://discourse.nodered.org/t/filter-sensor-data/43775/10 "2021-06-06T10:05:36Z")

</div>

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