Call Service node help please

How do I inject a service to a call service node?

callService

I tried setting msg.service in the inject node to {{turn_on}}, but that isn’t working.

This is part of an experiment to clean up one of my flows. I am turning selected lights on or off. Some are MQTT and some are Home Assistant service calls. My current flow works, but it is spaghettified because I have separate call service nodes for turn_on or turn_off. If I could inject the service (turn_on_ or turn_off) I could clean up the flow considerably.

Use turn_{{payload}} in the call service node, then inject on or off

Wow, so simple… It works great.
Thanks

If you want to keep your service call node 100% clean:

image

[{"id":"17f4237e.0285cd","type":"inject","z":"26a8be47.ed6452","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"service\":\"turn_on\",\"domain\":\"light\",\"data\":{\"entity_id\":\"light.your_light\"}}","payloadType":"json","x":360,"y":60,"wires":[["5176faf5.3ecfd4"]]},{"id":"5176faf5.3ecfd4","type":"api-call-service","z":"26a8be47.ed6452","name":"","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":60,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

Thanks again.
I am still struggling to understand JSON format, and tips like these help me a lot.

In this case, my trigger data (“on” or “off”) is coming from an Alexa node, so Mike’s solution will work here. (msg.payload is already “on” or “off”).

If by this you mean in comparison to YAML, just an FYI the two are completely interchangeable. YAML is really just a way of presenting JSON that is more readable for humans, often applications will convert YAML to JSON in order to ingest it.

If you’re familiar with YAML but not getting the hang of JSON I would recommend playing around with a tool like YAML to JSON. Then you can punch in the YAML you want and have it make the JSON for you. Then you can start to see how one translates into the other so you can get the hang of it.

Thanks, I discovered this a few weeks ago. If YAML is supposed to be more readable for humans, then I am not human. Give me a struct in C++ and, I get it. But YAML and JSON are still my weak spot.

1 Like

Just to clarify, YAML is supposed to be more readable for humans in comparison to JSON. So I definitely wouldn’t say someone who has trouble reading YAML isn’t human. Being more readable then JSON is a pretty low bar lol.