Switch Output to Inject Message

Please bear with me, I am brand new to Node Red. I am trying to send either of the inject messages at the bottom based on the switch outputs, but since the inject object has no inlets I cannot do this. What objects can I use to accomplish this? Thank you!

[{"id":"4d7259cb.a97538","type":"switch","z":"c57161f9.a52c78","name":"","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":280,"wires":[["46da71f9.d48b"],["fcc83144.1b29c"],[]]},{"id":"3a2520ae.7be008","type":"server-events","z":"c57161f9.a52c78","name":"Button","server":"93de20d5.59f72","event_type":"zha_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":70,"y":280,"wires":[["4d7259cb.a97538","f78b9e0b.b5aa38"]]},{"id":"f78b9e0b.b5aa38","type":"debug","z":"c57161f9.a52c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":210,"y":360,"wires":[]},{"id":"46da71f9.d48b","type":"hue-scene","z":"c57161f9.a52c78","name":"Bright","bridge":"d548f4dc.bcdd28","sceneid":"R2a2Qd3chYvpIP8","groupid":"1","skipevents":false,"x":390,"y":220,"wires":[[]]},{"id":"fcc83144.1b29c","type":"hue-scene","z":"c57161f9.a52c78","name":"Blue","bridge":"d548f4dc.bcdd28","sceneid":"jrATfzVOblz3-mE","groupid":"1","skipevents":false,"x":390,"y":280,"wires":[[]]},{"id":"dbab66df.e4b388","type":"inject","z":"c57161f9.a52c78","name":"Toggle","props":[{"p":"payload.toggle","v":"off","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":80,"y":440,"wires":[["35ac9580.2a752a"]]},{"id":"35ac9580.2a752a","type":"hue-light","z":"c57161f9.a52c78","name":"Living Room Tall Lamp","bridge":"d548f4dc.bcdd28","lightid":"20","colornamer":true,"skipevents":false,"universalevents":false,"x":320,"y":440,"wires":[[]]},{"id":"dc77fe2d.ee2528","type":"inject","z":"c57161f9.a52c78","name":"OFF","props":[{"p":"payload.on","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":540,"wires":[["35ac9580.2a752a"]]},{"id":"93de20d5.59f72","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true},{"id":"d548f4dc.bcdd28","type":"hue-bridge","name":"Philips hue","bridge":"192.168.1.22","key":"dG94SxRNzHPBlZZCc2RnSoHy0B0SiGk-dRqRqE1o","interval":"3000","disableupdates":false}]

you can use a change node to alter object properties. or you can use a function node with javascript.

Thank you for your reply. I looked at using a change, but I am looking for one msg.payload and trying to output not just another value, but a different msg.payload and value. I couldn't figure out a way to make the prompts work.

Investigating function now, but getting similar syntax errors.

Make sure to go through the documentation, there is a wealth of information there.

https://nodered.org/docs/user-guide/messages

Yeah, unfortunately I did watch that. Nothing clicked.

The fields on the left side describe the property/key name, the values on the right are the values.
The value you are trying to send is {"on":false}, example, see the difference:

edit - never occurred to me that both work, in this case

yeah, thats why the injects work when I manually trigger them, but without an inlet in the inject I am asking how to send the same messages using the switch.

Yes all possible in a change node.
i.e

[{"id":"1de99e34.09fb02","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload.event.command","v":"off","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":390,"y":3900,"wires":[["aba218e9.c6e228"]]},{"id":"aba218e9.c6e228","type":"switch","z":"8d22ae29.7df6d","name":"","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":620,"y":3900,"wires":[["bb06ebbf.1e5ea8"],["20ce2466.1592f4"],["ab961f87.b9d578"]]},{"id":"bb06ebbf.1e5ea8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":3860,"wires":[]},{"id":"20ce2466.1592f4","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":3920,"wires":[]},{"id":"ab961f87.b9d578","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":false}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":4020,"wires":[["9775f360.485b"]]},{"id":"9775f360.485b","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":4020,"wires":[]}]

a switch node is for switching, based on conditions. For changing, you need a change node (as the documentation described). See @E1cid's response.

Thanks all. I stumbled may way into proper syntax for function, but I appreciate the switch example as well.

Just for info

The first will leave msg.payload 's other properties intact.
The second overwrites msg.payload

1 Like

Indeed. Good point.

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