Hey guys,
I started with my homeautomation just today. My Node-Red is up and running and I did a few basic stuffs.
Now I have a little problem where I don't know what I have to google for. Tryed out something like this:
node-red function return string
I can't find any usefull result.
My function looks like this and I want to send "on" or "off" as a string to my mqtt node to turn a switch on and off.
if (msg.payload.activityStatus == "0") {
return [msg,null];
}
if (msg.payload.activityStatus != "3") {
return [null,msg];
}
2nd Question, where should I start to not create so much MQTT nodes for one device? Both of these Nodes got different topics
But you should return a string, a function node should return a message object, and generally that object should contain the important info as msg.payload
If you look at the info panel for the MQTT out node it should say that the MQTT node will transmit msg.payload
With your function code, I’m guessing you need something such as the following if you are checking for a value
If you look at the debug node it shows you have a property in the payload called status. To access it you would use msg.payload.status but what are you using in the if statement? answer: msg.payload.activityStatus which does not exist in the payload.
Use a switch node have one mqtt node subscribing to `shellies/# and in the switch node test msg.topic
for
shellies/thing1 -> outout1
shellies/thing2 -> outout2
shellies/...
shellies/thingn -> outoutn