Homeassistant Node-RED: service from string

Dear All,
I have the following question:
In Node-RED I got a String from an external source back. This source tells what service to call, what IdentityID to use witch data.
Is there a possibility not to create a switch node with a hundred outgoing part to call any type of service with any type of entityID but still have this kind of functionality?

So :
Part1: From string I have to convert to node, and
Part2: inside this node from string I have to convert to EntityID…
Part 3 with Data is working properly :smiley:

Any ideas?
Thank you!
Best: Peter

Most nodes accept dynamic values as part of the message received, like msg.entity_id for the entity_id in the service call.

1 Like

Thanks! I really didn’t now that.
That seems a good start to reduce the number of swich-node service calls!

Hello!
Sorry for the question, but how can be set?
For example light.turn_on service I tried:
{{payload.data.entity_id}} or {{payload.entity_id}} and some different variation as entity_id, but always end up with error.
The payload JSON:

{
   "service": "light.turn_on",
   "entity_id": "light.bulb_childroom_control",
}

(Also as service is still can’t be filled dynamically, I’ve tried the ‘selector’ way… but one problem at a time :smiley: )

Can you help me with dynamic content in entityID?
Best: Peter

One of my dynamic service calls:

[{"id":"9882a2c0e9d3a6df","type":"api-call-service","z":"d934647b.bc0428","name":"Set thermometer temp","server":"541ade28.b4a62","version":5,"debugenabled":false,"domain":"climate","service":"set_temperature","areaId":[],"deviceId":[],"entityId":[],"data":"{\"temperature\": msg.payload, \"entity_id\": msg.entity_id }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":225,"wires":[[]]},{"id":"541ade28.b4a62","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"numeric","statusMonth":"2-digit","statusDay":"2-digit","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

Hello!

First: THANK YOU. I don’t know why it didn’t worked, but just not…
I find out how can I put a payload dynamically:

[{"id":"731c296e65dd7e14","type":"inject","z":"6c20a3ecdb12009b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"light.bulb_childroom_control","payloadType":"str","x":1210,"y":1200,"wires":[["1caececbb61d30ef"]]},{"id":"1caececbb61d30ef","type":"api-call-service","z":"6c20a3ecdb12009b","name":"","server":"38a485a6.dc51aa","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"{\"entity_id\":\"{{{payload}}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1450,"y":1200,"wires":[[]]},{"id":"38a485a6.dc51aa","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Now my problem is: this is only work for payload… how can I set it to work with other values of msg. like msg.entity_id:confused:
This Nodered starts to confuse me. :smiley: I feel the potential in that, but still not able to figure out the ways how it cooperates with homeassistant :smiley:

Forget the above answer’s last sentences :smiley:

[{"id":"731c296e65dd7e14","type":"inject","z":"6c20a3ecdb12009b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"entity_id","v":"light.bulb_childroom_control","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":1210,"y":1200,"wires":[["1caececbb61d30ef"]]},{"id":"1caececbb61d30ef","type":"api-call-service","z":"6c20a3ecdb12009b","name":"","server":"38a485a6.dc51aa","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"{\"entity_id\":\"{{{entity_id}}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1450,"y":1200,"wires":[[]]},{"id":"38a485a6.dc51aa","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

So I figured it outm, that even if the service node called error, the mistake was in the injector node! I made a wrong type, but injector node didn’t corrected it, but the next service node failed to recieve it. This caused the error.

OMG :smiley:
Okay, I’ll continue this topic to see how about the services can be done dynamically (if possible).