I'm new to Node-RED and first post on this forum. Very impressed with NR so far.
I am trying to get the output of a PIR to activate a number of lights. The PIR powers on (and off) a Sonoff. The lights are each connected to their own Sonoffs. The Sonoffs are Tasmota powered and MQTT pub/sub works fine. I have set manual buttons in NR using the mqtt nodes to turn the lights on and off - these work.
What I have been trying without success is to get one mqtt sub node (PIR detects motion) to activate the correct mqtt pub node (turns on security light).
How best to wire these up?
I have tried wired nodes:
"mqtt in" - "change (msg.payload = ON)" - "mqtt out"
Put a debug node on the mqtt In node and anther on the Change node. Give them names so they are easier to identify in the debug pane. Then look at what you are getting out of each and make sure it is what you expect. If that looks good then add another In node subscribing the the the topic you have configured for the Out node and check the right data is coming back (with another debug node). If you still can't work out what the problem is then post your flow here and explain what is not happening correctly. See this post for how to share a flow here.
Thanks Colin. I did as you suggested and watched the outputs in node-red as well as on the server directly (ssh in and sub to all topics). It works now! What I changed was to ensure that the topic accurately triggered the node. Using the Change node worked. I also added in a custom delay to a second child node that turns the light off. So this is completely independent of the PIR's own limitations.
The PIRs will be used to inform me of security related events, rather than just switching the security lights on.
Also have a look at the Trigger node, that can be used to send one message then after an interval send a different one. That might enable you to do the On then Off more simply. You might want to consider setting the mqtt topic in the messages rather than in the mqtt node, then you can use just one mqtt out rather than one for each topic.