weemaba999
(Bart Weemaels)
February 25, 2025, 8:10pm
1
Hi,
Somehow my selected_rooms is not getting filled. The room: - Boolean - Value gives me correct values. But I’m not able to get the selected_rooms good
{% set selected_rooms = [] %}
{% for room in ['badkamer', 'master', 'gang', 'keuken', 'living_room', 'joosarne', 'bentjesse', 'berging', 'bureau', 'toilet'] %}
{% set room_boolean_state = states('input_boolean.roborock_room_' + room) %}
{% set room_value = states('input_number.roborock_room_enum_' + room) | int %}
Room: {{ room }} - Boolean: {{ room_boolean_state }} - Value: {{ room_value }}
{% if room_boolean_state == 'on' %}
{% if room_value is not none %}
{% set selected_rooms = selected_rooms + [room_value] %}
{% endif %}
{% endif %}
{% endfor %}
selected_rooms = {{ selected_rooms }}
Can anyone help ?
Kr,
Bart
123
(Taras)
February 25, 2025, 8:16pm
2
You need to use namespace
.
{% set ns = namespace(selected_rooms = []) %}
{% for room in ['badkamer', 'master', 'gang', 'keuken', 'living_room', 'joosarne', 'bentjesse', 'berging', 'bureau', 'toilet'] %}
{% set room_boolean_state = states('input_boolean.roborock_room_' ~ room) %}
{% set room_value = states('input_number.roborock_room_enum_' ~ room) | int(0) %}
Room: {{ room }} - Boolean: {{ room_boolean_state }} - Value: {{ room_value }}
{% if room_boolean_state == 'on' and room_value is not none %}
{% set ns.selected_rooms = ns.selected_rooms + [room_value] %}
{% endif %}
{% endfor %}
selected_rooms = {{ ns.selected_rooms }}
weemaba999
(Bart Weemaels)
February 26, 2025, 4:06pm
3
That worked !! Thanks a lot !
1 Like
123
(Taras)
February 26, 2025, 4:25pm
4
You’re welcome!
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
For more information about the Solution tag, refer to guideline 21 in the FAQ .
weemaba999
(Bart Weemaels)
February 26, 2025, 4:52pm
5
Nothing to consider, really helpfull. Marked as solutin as requested
Kr,
Bart
1 Like