I also just wanted to add my findings to the whole topic of “passing a list to a script and from there pass it on to a service”:
tl;dr: I couldn’t get it working with a usual script, I had to do it with a python script.
Here’s my solution first, then I will post my findings. Hopefully they will help somebody or maybe knows the last missing puzzle piece:
My Python script:
rooms = data.get("rooms")
# logger.info(rooms)
rooms = [ int(x) for x in rooms.split(",") ]
# logger.info(rooms)
serviceData = {
"entity_id": 'vacuum.living_room_wall_e',
"command": "app_segment_clean",
"params": rooms
}
# logger.info(serviceData)
hass.services.call('vacuum','send_command',serviceData)
And my automation where I call it:
- id: '1594586327354'
alias: Vacuum the apartment if everybody left home
description: ''
trigger:
- entity_id: group.everybody
from: home
platform: state
condition:
- after: '10:00:00'
before: '20:00:00'
condition: time
action:
- service: vacuum.set_fan_speed
data:
fan_speed: "Turbo"
entity_id: vacuum.living_room_wall_e
- service: python_script.wall_e_vacuum_room
data_template:
rooms: >
{% if is_state("binary_sensor.living_room_door_on_off", "on") %}
{{ "1,2,17" }}
{% else %}
{{ "17" }}
{% endif %}
So as you can see I could not make it work to have the automation piece of code pass an actual list. No matter what I did, it was always a string, never a list. It always works in the Template Developer Tool, but never in the automation code.
I tried this: {{ [1,2,17] }}
I even tried weird conversions like that: {{ "1,2,17".split(',')|map('int')|list }}
Which again all work in the dev tools, but when receiving it in the script, it’s always a string, like this: '[1,2,17]'
But with my Python script, I can ezpz handle every data type. So I just decided to send a comma separated list, make that a real list and force each element to be int.
Maybe this is of any help for somebody or maybe knows how to properly pass a list to a script
Greetings,
Andy!