Hi there, just updated the power-monitor node. Have to adapt my function node, which sends me notification if e.g. the dishwasher has finished.
I have to filter the messages since there are now messages incoming even if the dishwasher is running. I have to filter for the stop message, because only there are the data, I'm interested in. Thought about something like this:
I'm a beginner if it comes to coding. And I use a json validator and get errors. If I put it in a function node, it's meant to have two outputs. One if it's a "stop" event and one output for every other value. But there is only one output and non message comes through.
Did you add debug nodes before and after function as suggested...
What do you see?
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
Yes I did add the debug node but there is nothing on the output, as i mentioned before.
Good hint is to set the node to two outputs. Didn't know that this is possible. Thought it does that by itself, if the code needs two or more. Will debug again now.
Don't forget to add a debug node to the node feeding the function node. That way you will see the actual msg.payload going into the function node.
Also, as a debuggging tip, you can add node.warn(); statements into the function node to see what is going on. The output will display inteh debug sidebar.
So you could have
var payload = msg.payload.event;
node.warn('payload= '+payload)
if (payload == "stop") {
node.warn('in TRUE part of IF')
msg.payload.time = Math.round(msg.payload.time / 60);
msg.payload.cost = Math.round(msg.payload.energy * 29.70) / 100;
return [ msg, null ];
} else {
node.warn('in ELSE part of IF')
return [ null, msg ];
}
This can help you see how the function node is working.
Also remember to copy and paste the results you see to a reply. That way we can see it and help you out.