I am trying to integrate a sensor that I created that outputs data based on input_boolean status. This is an integration for a play button of a robot vacuum cleanner. The idea is when I dont have any rooms selected or all of them on the play button custom field appears “Clean the entire house”, if I select individual rooms they will appear, if selected, on the play button, letting me know which rooms it will clean. So far I managed to create the sensor, and it outputs the values in the right way, “Clean the entire house” if all selected or none, and it will create a list of the input_booleans that are on.
The code
Sensor (sensor.vacuum_what_is_cleaning):
{% set all_rooms = {
'bedroom': 'Bedroom',
'toilet': 'Toilet',
'hallway': 'Hallway',
'bathroom': 'Bathroom',
'living_room': 'Living room',
'kitchen': 'Kitchen'
} %}
{% set ns = namespace(rooms_on=[], rooms_off=[]) %}
{% for k, v in all_rooms.items() %}
{% set ib = 'input_boolean.vacuum_room_cleaning_' ~ k %}
{% if is_state(ib, 'on') %}
{% set ns.rooms_on = ns.rooms_on + [v] %}
{% elif is_state(ib, 'off') %}
{% set ns.rooms_off = ns.rooms_off + [v] %}
{% endif %}
{% endfor %}
{% if ns.rooms_on | count == 0 or ns.rooms_off | count == 0 %}
Clean the entire house
{% else %}
{{ ns.rooms_on }}
{% endif %}
Custom field on a custom:button-card
custom_fields:
rooms: '[[[ return states["sensor.vacuum_what_is_cleaning"].state; ]]]'
My problem now is how do I integrate this into a button label and format it so it doesnt simple appear as [‘Item1’, ‘Item2’, …]