Dynamically set entity in Call Service node

I apologize for the noobie question. I’m trying to avoid creating a new call service node for each input_select as I have one for each room and its gotten quite repetitive (for example: input_select.master_bathroom_scene_entities.

Specifically I’m having trouble dynamically passing the entity to the call service node. How do I tell the call service node to use what is being passed in as the Entity. Example:

I don’t have an example flow to give but I’ve been using Kermit’s example here:

You have to send the domain, service, and entity_id in the following format

[{"id":"f9da7824fb4b2009","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":570,"y":1100,"wires":[[]]},{"id":"1225d79a3df842e7","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"domain\":\"input_boolean\",\"service\":\"turn_on\",\"target\":{\"entity_id\":[\"input_boolean.morning_boost\"]}}","payloadType":"json","x":370,"y":1100,"wires":[["f9da7824fb4b2009"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"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}]

Thank you for the reply. I think I’m screwing up the array portion of the input_select. Not sure on the formatting:

msg : error
"HomeAssistantError: required key not provided @ data['option']"
[{"id":"329f46d0b83204dd","type":"api-call-service","z":"2c514b7023cd7317","name":"","server":"ed8abe17.255eb","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":310,"y":180,"wires":[["41878bbb83a91666"]]},{"id":"3f9446b45092d3df","type":"inject","z":"2c514b7023cd7317","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"domain\":\"input_select\",\"service\":\"select_option\",\"target\":{\"entity_id\":[\"input_select.master_bedroom_scene_entities\"]}}","payloadType":"json","x":110,"y":180,"wires":[["329f46d0b83204dd","c64297a33d5739c3"]]},{"id":"c64297a33d5739c3","type":"debug","z":"2c514b7023cd7317","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":280,"wires":[]},{"id":"41878bbb83a91666","type":"api-call-service","z":"2c514b7023cd7317","name":"","server":"ed8abe17.255eb","version":5,"debugenabled":true,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":500,"y":180,"wires":[["1ccbe5eff6cea1d9"]]},{"id":"1ccbe5eff6cea1d9","type":"debug","z":"2c514b7023cd7317","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":180,"wires":[]},{"id":"ed8abe17.255eb","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]
{
    "domain": "input_select",
    "service": "select_option",
    "target": {
        "entity_id": [
            "input_select.master_bedroom_scene_entities"
        ]
    }
}

Sorry about that for the select you would need to include the option you want to select

{
    "domain": "input_select",
    "service": "select_option",
    "target": {
        "entity_id": [
            "input_select.master_bedroom_scene_entities"
        ]
    },
    "data": {
        "option": "Overnight"
    }
}

Thank you for the clarification. I confirmed the input_select Entity changed via the Home Assistant Dev tools but it did not actually activate or use the scene. I think I need to correctly pass what entity to use in the Call Service node instructing it to turn on but haven’t been able to figure it out.

[{"id":"dd3d7c3a8ffdd4d8","type":"api-call-service","z":"332e5b4ff712adf3","name":"","server":"ed8abe17.255eb","version":5,"debugenabled":true,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":410,"y":200,"wires":[["e3baeb651161ecd2","edf8907584295be7"]]},{"id":"5386b22c60190880","type":"inject","z":"332e5b4ff712adf3","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"domain\":\"input_select\",\"service\":\"select_option\",\"target\":{\"entity_id\":[\"input_select.master_bedroom_scene_entities\"]},\"data\":{\"option\":\"scene.master_bedroom_all_blue\"}}","payloadType":"json","x":190,"y":200,"wires":[["dd3d7c3a8ffdd4d8","305e926a8bc246be"]]},{"id":"305e926a8bc246be","type":"debug","z":"332e5b4ff712adf3","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":140,"wires":[]},{"id":"edf8907584295be7","type":"api-call-service","z":"332e5b4ff712adf3","name":"","server":"ed8abe17.255eb","version":5,"debugenabled":true,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"{ \"entity_id\": msg.payload }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":200,"wires":[["4f05d15f4a6a6069"]]},{"id":"e3baeb651161ecd2","type":"debug","z":"332e5b4ff712adf3","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"4f05d15f4a6a6069","type":"debug","z":"332e5b4ff712adf3","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":200,"wires":[]},{"id":"0cd2b464cec63a25","type":"inject","z":"332e5b4ff712adf3","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"scene.2_bonus_room_all_purple","payloadType":"str","x":430,"y":320,"wires":[["edf8907584295be7"]]},{"id":"ed8abe17.255eb","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

I think you may be adding a step here. How is the input select being changed? On the dash, from a drop down? If so you only need this

[{"id":"249128f68b422b87","type":"server-state-changed","z":"60f2d2277843c698","name":"input select","server":"6b1110b5.183a4","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"input select","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":410,"y":4880,"wires":[["c6320d0c6ff671ce"]]},{"id":"c6320d0c6ff671ce","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":true,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{payload}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":660,"y":4880,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"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}]

If something else is changing the input select, still use the above. Separate the scene call service. When the select is updated in the first automation the event state will fire setting the scene.

image

If you want to leave it all inline, how you have it.

[{"id":"dd3d7c3a8ffdd4d8","type":"api-call-service","z":"60f2d2277843c698","name":"Set input select","server":"6b1110b5.183a4","version":5,"debugenabled":true,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":480,"y":4700,"wires":[["c6320d0c6ff671ce"]]},{"id":"5386b22c60190880","type":"inject","z":"60f2d2277843c698","name":"Some trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"domain\":\"input_select\",\"service\":\"select_option\",\"target\":{\"entity_id\":[\"input_select.vacuum_select\"]},\"data\":{\"option\":\"scene.new_scene\"}}","payloadType":"json","x":250,"y":4700,"wires":[["dd3d7c3a8ffdd4d8"]]},{"id":"c6320d0c6ff671ce","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":true,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{payload.option}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":4700,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"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}]
1 Like

The 2nd one was exactly what I was looking for. The input_select is being changed via a schedule and mostly some Aqara Wireless Mini Switches. The idea was based on Smart Home Junkie’s video on scene cycling in Home Assistant but had gotten out of control and needed a way to abstract some of the areas and colors. I’ve made it into a subflow where I just pass the area and color.

[{"id":"beae01a3f87b05c0","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"7012120a728904ac","type":"debug","z":"beae01a3f87b05c0","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":440,"wires":[]},{"id":"a7e341f6062f02b9","type":"api-call-service","z":"beae01a3f87b05c0","name":"Call Service (via payload)","server":"ed8abe17.255eb","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":690,"y":260,"wires":[["4dd6ad791879490d"]]},{"id":"4dd6ad791879490d","type":"api-call-service","z":"beae01a3f87b05c0","name":"Call Service: scene - turn_on (via payload.option)","server":"ed8abe17.255eb","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{payload.option}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":710,"y":440,"wires":[["7012120a728904ac"]]},{"id":"fce62d9cf47aa286","type":"template","z":"beae01a3f87b05c0","name":"input_select: Change Area / Color Based On Payload","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"domain\": \"input_select\",\n    \"service\": \"select_option\",\n    \"target\": {\n        \"entity_id\": [\n            \"input_select.{{payload.area}}_scene_entities\"\n        ]\n    },\n    \"data\": {\n        \"option\": \"scene.{{payload.area}}_all_{{payload.color}}\"\n    }\n}","output":"json","x":340,"y":260,"wires":[["a7e341f6062f02b9"]]},{"id":"8db6234ec4ae56ca","type":"template","z":"beae01a3f87b05c0","name":"script: Change Area Based On Payload","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"domain\": \"script\",\n    \"service\": \"turn_on\",\n    \"target\": {\n        \"entity_id\": [\n            \"script.scene_{{payload.area}}_all_off_set_not_active\"\n        ]\n    }\n}","output":"json","x":300,"y":220,"wires":[["100d4781c0d3e554"]]},{"id":"100d4781c0d3e554","type":"api-call-service","z":"beae01a3f87b05c0","name":"Call Service (via payload)","server":"ed8abe17.255eb","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":690,"y":220,"wires":[[]]},{"id":"4b512291636b7c52","type":"template","z":"beae01a3f87b05c0","name":"Set Area / Color","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"area\": \"master_bedroom\",\n    \"color\": \"orange\"\n}","output":"json","x":360,"y":80,"wires":[["8db6234ec4ae56ca","fce62d9cf47aa286"]]},{"id":"5f69166c3dea149f","type":"inject","z":"beae01a3f87b05c0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":80,"wires":[["4b512291636b7c52"]]},{"id":"ed8abe17.255eb","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

Thank you so much for you help @Mikefila

Hey @Mikefila
Wondering if you could help me out again. The flow broke for me when I upgraded from 2024.9 to 2024.10. I’ve got it somewhat working now.

How would I update the flow to fix the deprecation message:

“The domain and service input properties are deprecated and will be removed in version 1.0. Please use the action property instead.”

while still being able to pass Mustache template values?

Additionally, I haven’t been able to figure out how to pass the Mustache template values to the scene.turn_on action node without having to use a function node to block the original domain: "input_select" and service: "select_option" which override domain: "scene" and service: "turn_on". Previously it was as easy as setting {{payload.option}} as the entity.

[{"id":"3fb425e7684a0275","type":"api-call-service","z":"4b39eb5e1b7934e0","name":"Call Service: input_select - select_option","server":"ed8abe17.255eb","version":7,"debugenabled":true,"action":"input_select.select_option","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_select.{{payload.floor}}_{{payload.location}}_{{payload.subarea}}_scene_entities"],"labelId":[],"data":"{ \"option\": msg.payload }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_select","service":"select_option","x":1080,"y":220,"wires":[["3f223bf0ed126b69"]]},{"id":"165bdbe529a11cc1","type":"api-call-service","z":"4b39eb5e1b7934e0","name":"Turn On: Scene Entity","server":"ed8abe17.255eb","version":7,"debugenabled":true,"action":"scene.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":[],"labelId":[],"data":"{\"entity_id\":\"{{payload.data.option}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"scene","service":"turn_on","x":500,"y":320,"wires":[[]]},{"id":"0a5706ce72607c5d","type":"template","z":"4b39eb5e1b7934e0","name":"Bonus_Room:Red","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"floor\": \"2\",\n    \"location\": \"bonus_room\",\n    \"subarea\": \"all\",\n    \"color\": \"red\"\n}","output":"json","x":310,"y":220,"wires":[["47d9507c5f1183b4"]]},{"id":"47d9507c5f1183b4","type":"template","z":"4b39eb5e1b7934e0","name":"input_select: Change Area / Color Based On Payload","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"action\": \"input_select.select_option\",\n    \"target\": {\n        \"entity_id\": [\n            \"input_select.{{payload.floor}}_{{payload.location}}_{{payload.subarea}}_scene_entities\"\n        ]\n    },\n    \"data\": {\n        \"option\": \"scene.{{payload.floor}}_{{payload.location}}_{{payload.subarea}}_{{payload.color}}\"\n    }\n}","output":"json","x":660,"y":220,"wires":[["3fb425e7684a0275"]]},{"id":"f8d67bfd8777b38f","type":"inject","z":"4b39eb5e1b7934e0","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":220,"wires":[["0a5706ce72607c5d"]]},{"id":"3f223bf0ed126b69","type":"function","z":"4b39eb5e1b7934e0","name":"Function (Required)","func":"return {\n    payload: {\n        domain: \"scene\",\n        service: \"turn_on\",\n        data: {\n            entity_id: msg.payload.data.option\n        }\n    }\n};","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":320,"wires":[["165bdbe529a11cc1"]]},{"id":"ed8abe17.255eb","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":true,"cacheJson":false,"heartbeat":true,"heartbeatInterval":"60","statusSeparator":"","enableGlobalContextStore":false}]

It is the version of your nodes that are giving the error. Domain and call service were combined a few months ago to create actions. When sending in the config you will need to use action instead of domain and call service.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/action.html#input