Block value "null"?

Node Red version 2.06 running on a RPI.

Hello. I am new to programming in Node Red. And now i need some help. I got a flow from "tibber pulse" which sends a feed with values from my main meter. I get watt consumption every 2.5 seconds. I also get voltage and ampere. Voltage and ampere values is presented in the feed every five minutes or at least more seldom. When the values from voltage and ampere isnt presented, they are presented with "null" in the feed. How can i block the value "null" and just let the correct values for Voltage and Ampere go through?

Best regards Freddy.

Welcome to the forum @FSHelgeland

Show us what the data looks like in a debug node so we can see exactly what you are getting. Null can mean a number of things. It could be a String "null", or an undefined value for example.

payload.voltagePhase1
image

payload.voltagePhase1
image

Is this any help? Thank you for your quick answer.

I need to pass this to a modbus write node btw.

Would a switch node set to is not null work? or is of type number

1 Like

Like this? Am I missing something? Cant get any data out of the switch node as it is now.

The data is in msg.payload.voltagePhase1 not msg.payload

I got several payloads. I put them in a function in front of the switch node.


I cant do it like that?

Yes and if any one is null you don't want to proceed.
As said You set the switch node to look a msg.payload, when you need to set it to msg.payload.voltagePhase1, that should work.
But if you want to test all three use a JSONata expression as below

[{"id":"a999b7f9.565c2","type":"inject","z":"b779de97.b1b46","name":"correct payloads","props":[{"p":"payload.volt1","v":"1","vt":"num"},{"p":"payload.volt2","v":"2","vt":"num"},{"p":"payload.volt3","v":"3","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":4800,"wires":[["1313f93b.d0b027"]]},{"id":"1313f93b.d0b027","type":"switch","z":"b779de97.b1b46","name":"","property":"payload.volt1 != null and payload.volt2 != null and payload.volt3 != null","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":4880,"wires":[["2154a993.49803e"]]},{"id":"2154a993.49803e","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":4840,"wires":[]},{"id":"df7a7f43.076728","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload.volt1","pt":"msg","to":"null","tot":"jsonata"},{"t":"set","p":"payload.volt2","pt":"msg","to":"null","tot":"jsonata"},{"t":"set","p":"payload.volt3","pt":"msg","to":"null","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":4940,"wires":[["1313f93b.d0b027"]]},{"id":"49eead0a.7f7534","type":"inject","z":"b779de97.b1b46","name":"null payloads","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":120,"y":4940,"wires":[["df7a7f43.076728"]]}]

Where do i put that expression?

it goes in the switch node, you will need to edit it, as i did not use your property names, as it is just an example.

Thank you. I will try that.

Hmmmm why didnt i listen the first time? I got it to work whith your first suggestion. Tnx again, owe you one.

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