I am trying to customize a Xiaomi vacuum card in order to have multi-zones selections. I added a “switch” button for every room (based on a input_select - see below) but I’m getting this error when executing xiaomi_miio.vacuum_clean_segment: “expected int for dictionary value @ data[‘segments’]”.
My configuration.yaml:
sensor:
- platform: template
sensors:
vacuum_zones:
friendly_name: "Zones"
value_template: >
{% if not is_state('input_select.vacuum_living', 'Off') %} {{ states('input_select.vacuum_living') + ',' }} {% endif %}
{% if not is_state('input_select.vacuum_bedroom', 'Off') %} {{ states('input_select.vacuum_bedroom') + ',' }} {% endif %}
{% if not is_state('input_select.vacuum_bathroom', 'Off') %} {{ states('input_select.vacuum_bathroom') + ',' }} {% endif %}
{% if not is_state('input_select.vacuum_hallway', 'Off') %} {{ states('input_select.vacuum_hallway') + ',' }} {% endif %}
{% if not is_state('input_select.vacuum_kitchen', 'Off') %} {{ states('input_select.vacuum_kitchen') + ',' }} {% endif %}
input_select:
vacuum_living:
name: Living
initial: "Off"
icon: mdi:sofa
options:
- 3
- "Off"
vacuum_bedroom:
name: Bedroom
initial: "Off"
icon: mdi:bed
options:
- 1
- "Off"
vacuum_bathroom:
name: Bathroom
initial: "Off"
icon: mdi:shower
options:
- 2
- "Off"
vacuum_hallway:
name: Hallway
initial: "Off"
icon: mdi:road
options:
- 17
- "Off"
vacuum_kitchen:
name: Kitchen
initial: "Off"
icon: mdi:silverware-fork-knife
options:
- 16
- "Off"
My lovelace template:
type: custom:button-card
template: button_small
aspect_ratio: 3/1.3
name: Zones
icon: mdi:play
entity: vacuum.robo
styles:
icon:
- color: >
[[[ return entity.state == 'cleaning' ? 'var(--paper-item-icon-active-color)' : 'var(--paper-item-icon-color)' ]]]
tap_action:
action: call-service
service: xiaomi_miio.vacuum_clean_segment
service_data:
entity_id: entity
segments: >
[[[ return ("[" + states["sensor.vacuum_zones"].state + "]").replace(",]", "]") ]]]
If I replace the value of segments with something like [1,3] is all ok and working.
Also, sensor.vacuum_zones works ok and returns its value in the exact format as above (eg: [1,3] ).
This is the card