I’m trying to run a template script but somehow the output produces an error that I cannot fix:
I have a set of input_boolean
helpers that store, which room needs to be cleaned. In a script I would like to call a service to have the vacuum clean these rooms. The input_boolean
are kept in a group
and I use the following template:
{% set rooms = expand(['group.cleaning_rooms']) | selectattr('state','eq','on') | map(attribute='entity_id') | list %}
{% set mapper = {
'input_boolean.clean_dining_area' : 20,
'input_boolean.clean_bedroom' : 17,
'input_boolean.clean_master_bath' : 16,
'input_boolean.clean_living_room' : 18,
'input_boolean.clean_kids_room' : 21,
'input_boolean.clean_study' : 19,
'input_boolean.clean_corridor' : 22,
'input_boolean.clean_guest_toilet' : 4
} %}
{% for room in rooms if room in mapper %}
- {{ mapper[room] }}
{% endfor %}
I have set the bedroom to be cleaned, and in the developer tools, this produces the following output:
- 17
Now I’ve put this into a script:
alias: Start vacuum room cleaning
sequence:
- service: xiaomi_miio.vacuum_clean_segment
data_template:
entity_id: vacuum.xiaomi_vacuum_cleaner
segments: >
{% set rooms = expand(['group.cleaning_rooms']) | selectattr('state','eq','on') | map(attribute='entity_id') | list %}
{% set mapper = {
'input_boolean.clean_dining_area' : 20,
'input_boolean.clean_bedroom' : 17,
'input_boolean.clean_master_bath' : 16,
'input_boolean.clean_living_room' : 18,
'input_boolean.clean_kids_room' : 21,
'input_boolean.clean_study' : 19,
'input_boolean.clean_corridor' : 22,
'input_boolean.clean_guest_toilet' : 4
} %}
{% for room in rooms if room in mapper %}
- {{ mapper[room] }}
{% endfor %}
mode: single
icon: 'mdi:play'
Now I get the following error:
Failed to call service script/start_vacuum_room_cleaning. expected int for dictionary value @ data[‘segments’]
When I call the service in the developer tools with data like this, it works:
entity_id: vacuum.xiaomi_vacuum_cleaner
segments:
- 17
Any hints what I’m doing wrong?