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

**URL:** <https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814>\
**Category:** General\
**Created:** [7 June 2021 14:00 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814 "2021-06-07T14:00:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [7 June 2021 14:00 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/1 "2021-06-07T14:00:46Z")

</div>

How do I inject a service to a call service node?  
 ![callService](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/6364344d01c35930e0b7da0edf982e1d06f9c46d.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [9 June 2021 14:03 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/2 "2021-06-09T14:03:45Z")

</div>

Anyone? Please?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 June 2021 14:17 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/3 "2021-06-09T14:17:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [9 June 2021 17:44 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/4 "2021-06-09T17:44:51Z")

</div>

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=

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

```

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [9 June 2021 18:00 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/5 "2021-06-09T18:00:29Z")

</div>

Hope this is what you are looking for?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76b645270c1d6a2c7e234667bb7b01762c2f06c9.png)  
The Inject Node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd6e4fb204103bba9a7e76f2ccfc4fd4c719dcf2.png)  
The Call Service Node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af35880ac2f7fb91352196a9c4eab8d9b44b315d.png)

[{"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}]

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [9 June 2021 18:42 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/6 "2021-06-09T18:42:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 June 2021 18:43 UTC](https://discourse.nodered.org/t/how-do-i-inject-a-service-to-a-call-service-node/46814/7 "2021-06-23T18:43:07Z")

</div>

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