Help using Boolean Input to trigger Particle Function

I have a Particle Photon connected to a 24 Relay board. I’m able to control the relays using Node-Red with the inject node (using the Particle node).

The payload that turns on/off a specific relay is “1,on” and “1,off”, etc. which works fine using that as the payload in the inject node.

Where I’m running into issues is controlling the relays when I turn on or off the input boolean. It shows it’s current status in node-red, but I’m having trouble passing the appropriate payload through a switch.

Is there a way to pass parameter other than “on” and “off” via the switch node or should I be looking at something else?

Node-Red

If the number before the on is static you can use a change node to prepend the number. If it’s a dynamic number based on a value passed in you could make a more complicated change node or use a function node.

Swap out the switch node for the change node below.

I made the suggested change and it is still not working as expected. Do you see anything wrong?

It seems to be passing “1,on” but the debug of the function node gives a result of “[ object, null ]” when the correctly working inject passes a “1” when the relay is turned on or off.

Experimenting a bit more, I’m able to trigger the relays and turn on a lamp using the inject on/off in the following example, but changing the input_boolean only turns on the light and doesn’t affect the relay.

I’m using the same change message as above (search: “on” replace: “1,on”). The inject nodes are simply sending on and off respectively. Why does the input boolean work on the lamp but not the particle function?

What confuses is me is that the debug shows the same payload result for both the inject buttons as well as the input boolean switch on the front end.

I was just reading the info panel for the particle nodes and noticed this.

'shortcut': send just msg.payload without msg.topic to intepret the payload as a parameter string.

When you use an event: state node it sets the entity_id that triggered it to the topic. Try adding another rule to the change node that deletes msg.topic.

Thanks @Kermit for looking into this. Can you give me a hint how to accomplish that?

[{"id":"89ec60af.54136","type":"server-state-changed","z":"2802ff38.60d4c","name":"","server":"8d00ebbc.99a928","entityidfilter":"input_boolean.test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":236,"y":1680,"wires":[["1e52a128.fa087f","608fffb0.0d7c1"]]},{"id":"1e52a128.fa087f","type":"change","z":"2802ff38.60d4c","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"(.+)","fromt":"re","to":"1,$1","tot":"str"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":512,"y":1680,"wires":[["b4767512.9dcea8"]]},{"id":"d65cb1eb.2fe47","type":"api-call-service","z":"2802ff38.60d4c","name":"","server":"8d00ebbc.99a928","service_domain":"light","service":"","data":"{\"entity_id\":\"light.night_light\"}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":684,"y":1728,"wires":[[]]},{"id":"608fffb0.0d7c1","type":"template","z":"2802ff38.60d4c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"service\": \"turn_{{payload}}\" }","output":"str","x":496,"y":1728,"wires":[["d65cb1eb.2fe47"]]},{"id":"b4767512.9dcea8","type":"particle-func","z":"2802ff38.60d4c","pcloud":"","devid":"","fname":"","param":"","productIdOrSlug":"","repeat":0,"once":false,"x":674,"y":1680,"wires":[[]]}]

Sorry for the slow response. I was traveling and unable to test. All works and even better is that by adding a third rule I can now turn the relays on and off with the same node. Thank you so much!

This all works swimmingly…however, I would like to update the status of the Input Booleans if/when triggered directly from the Photon. How would you go about keeping status updated in HA from the particle device? Webhook, MQTT, etc?