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

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 to the point of being a mess. If I could inject the service I could clean up the flow considerably.

Anyone? Please?

Is that a Home Assistant node? Not many here use HA so you might be better asking on an HA forum.

However, why have you got braces round turn_on? Check the node's documentation to see what you have to pass it. I would have thought it might expect just a string.

You are correct that it is a Home Assistant node. I asked on the HA forum and got my answer. The data is in JSON format and my JSON structure was all wrong.

This worked: msg.data=

  "service": "turn_on",
   "domain": "switch",
   "data": {
       "entity_id": "switch.kim_desklight"
   }

Hope this is what you are looking for?
image
The Inject Node:
image
The Call Service Node:

[{"id":"7a74401a.9e28a","type":"inject","z":"38357f6c.c283b","name":"","props":[{"p":"domain","v":"light","vt":"str"},{"p":"service","v":"turn_on","vt":"str"},{"p":"entity","v":"light.dimmable_light_3","vt":"str"},{"p":"data","v":"100","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1058,"y":1696,"wires":[["d31b2d54.5af88"]]},{"id":"d31b2d54.5af88","type":"api-call-service","z":"38357f6c.c283b","name":"Empty","server":"32f2c474.d2eeec","version":3,"debugenabled":false,"service_domain":"{{domain}}","service":"{{service}}","entityId":"{{entity}}","data":"{"brightness_pct":"{{data}}"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":,"queue":"none","x":1266,"y":1696,"wires":[]},{"id":"32f2c474.d2eeec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

1 Like

I learned something new today- thanks. I did not know that I could substitute objects in msg this way.

1 Like

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