This automation checks if any input_boolean switches are turned on. Each switch corresponds to an integer (representing a vacuum segment). If a switch is on, its value is added to a list (integer_list), which is then used to send a vacuum command.
Problem:
The integer_list is always empty, even when the switches are on. This prevents the vacuum command from being sent.
Expected Behavior:
• When a switch is on, its integer value should be added to the list.
• If the list is not empty, the vacuum command should be sent with the segments.
• If the list is empty, the automation does nothing.
alias: Input Booleans to Integer List Automation
trigger:
- platform: state
entity_id:
- input_boolean.switch_1
- input_boolean.switch_2
condition: []
action:
- variables:
input_boolean_int_mapping:
- entity: 'input_boolean.switch_1'
value: 29
- entity: 'input_boolean.switch_2'
value: 22
integer_list: >
{% set list = [] %}
{% for item in input_boolean_int_mapping %}
{% if is_state(item.entity, 'on') %}
{% set list = list + [item.value] %}
{% endif %}
{% endfor %}
{{ list }}
- choose:
- conditions:
- condition: template
value_template: "{{ integer_list | length > 0 }}"
sequence:
- service: vacuum.send_command
data:
command: app_segment_clean
params:
- segments: "{{ integer_list }}"
repeat: 1
target:
entity_id: vacuum.sample_vacuum
default:
- service: logbook.log
data:
name: Roborock
message: "No segments were selected, so no cleaning was started."```