I’m using home assistant 0.103 in a venv and I have a similar problem with templating zones.
Simplified example:
I have two zones (kitchen and living room). Everything works perfect, if I use a separate script for every zone like this:
vacuum_room:
alias: "zoned cleaning"
sequence:
- service: vacuum.send_command
data_template:
entity_id: vacuum.rockrobo
command: 'zoned_cleanup'
params:
'zone_ids': ['kitchen']
But I don’t want to have a seperate script for every zone. I would like to use one script like this:
vacuum_room:
alias: "zoned cleaning"
sequence:
- service: vacuum.send_command
data_template:
entity_id: vacuum.rockrobo
command: 'zoned_cleanup'
params:
'zone_ids': >
{%- if is_state("input_select.vacuum_room", "Kitchen") %}['kitchen']{% endif %}
{%- if is_state("input_select.vacuum_room", "Living Room") %}['living room']{% endif %}
The script seems to be executed without an error, but the vacuum does not start.
Here is an extraction of the log from the working script:
2019-12-20 06:52:43 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1528187664] Received {'type': 'call_service', 'domain': 'script', 'service': 'turn_on', 'service_data': {'entity_id': 'script.vacuum_room'}, 'id': 62}
2019-12-20 06:52:43 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=vacuum, service=send_command, service_data=entity_id=vacuum.rockrobo, command=zoned_cleanup, params=zone_ids=['kitchen']>
2019-12-20 06:52:43 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=valetudo/rockrobo/custom_command, qos=0, retain=False, payload={"command": "zoned_cleanup", "zone_ids": ["kitchen"]}>
2019-12-20 06:52:43 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on valetudo/rockrobo/custom_command: {"command": "zoned_cleanup", "zone_ids": ["kitchen"]}
Here is an extraction of the log from the not working script:
2019-12-20 06:51:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1528187664] Received {'type': 'call_service', 'domain': 'script', 'service': 'turn_on', 'service_data': {'entity_id': 'script.vacuum_room'}, 'id': 57}
2019-12-20 06:51:24 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=vacuum, service=send_command, service_data=entity_id=vacuum.rockrobo, command=zoned_cleanup, params=zone_ids=['kitchen']>
2019-12-20 06:51:24 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=valetudo/rockrobo/custom_command, qos=0, retain=False, payload={"command": "zoned_cleanup", "zone_ids": "['kitchen']"}>
2019-12-20 06:51:24 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on valetudo/rockrobo/custom_command: {"command": "zoned_cleanup", "zone_ids": "['kitchen']"}
Comparing the two logs it seems a problem of the double quotes. I already tried different notations in the template, but I always have problems with the double quotes.
Strangely the second line of the log is equal and in the third line of the log there is a difference with the double quotes, which is probably the reason of my problem.
Any hints what’s going wrong?
Thanks in advance!