The varnewmsg bit is meant to change to on or off to send on the the next devices. The Mqtt ones work fine but the entity.landing_lamp doesn’t. And I’m not sure if I am writing it wrong. Sorry on mobile atm.
As written newMsg will allways have a topic of Landing Lamp
How could I get it to have the state? Eg. On or off?
It's hard to understand exactly what you are trying to do here. Don't worry we all had to start somewhere ![]()
Perhaps you could share more of the flow and a description of what you want this function to do, even a sketch might help !
Looking at your function -
You don't seem to be using the incoming topics as they are commented out in the logic ?
You don't seem to be using topics on the outgoing messages either, as there are 3 MQTT OUT nodes which already have the topic set. This makes this code redundant, and you cannot define 3 values to the same variable like this anyway as it will always be the last value you set as I pointed out.
var newMsg = { topic: "zigbee2mqtt/Stairs Switch/state_l2"};
var newMsg = { topic: "zigbee2mqtt/Landing Switch/state_l2" };
var newMsg = { topic: "Landing Lamp"};
To send to the topic you define you need to leave topic blank in the MQTT node, and then only have 1 node.
You can set payload and topic within your if statments like this
var newMsg = { topic: "zigbee2mqtt/Stairs Switch/state_l2", payload: msg.payload } ;
As it stand if any of the 3 MQTT topics sends an On or Off payload, the function will stop at the first matching condition - eg if (landingstairs === 0) it will then send an ON payload to all three outgoing topics.
I'm guessing that all three will then send a new message back into the function, and after several iterations it may stop if there are no more matches ?
Regarding landinglamp there is no outgoing topic for that in the flow you shared.