Filter sensor data

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

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

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.

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

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.

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

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

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

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.

I don't know whether it is co-incidence but there another ongoing question relating to tasmota nodes ts.startsWith is not a function 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. 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.

1 Like

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

Server properties:
image

Node properties:
image

image

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

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.

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

image

image

image

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

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.