In your Node-Red flow, msg.payload contains a list of Input Booleans. The for-loop iterates through the list and checks if it contains the entity_id any of six specific Input Booleans. For each matching Input Boolean, it appends its associated integer value to a list.
What in Home Assistant contains this list of Input Booleans?
In other words, how do you plan to tell the automation which rooms you want to have vacuumed?
How are you currently telling your Node-Red flow which rooms you want vacuumed?
You appear to have a Function node that receives msg.payload containing a list of Input Booleans. What is/are the previous node(s) in your flow that is producing the list of Input Booleans and passing it to your Function node via msg.payload?
I do the same thing, but with extra steps. I put all my “segments” code into a template sensor, then point to that for the params in the service call.
I add my room numbers as attributes on the input booleans using customize.yaml: CONFIG > customize.yaml
Then make sure you tell home assistant about the customize.yaml file. Place the following in CONFIG > configuration.yaml:
homeassistant:
customize: !include customize.yaml
By doing this type of attribute customization, you might then create a template sensor helper with the following: (I named mine “sensor.active_vacuum_zones”)
{% set ns =namespace(COMMAND = "") -%}
{%- set ROOM_FLAGS = expand("group.raumauswahl_erdgeschoss_alle_raume") | selectattr("state", "eq", "on") | list-%}
{%- for flag in ROOM_FLAGS -%}
{%- set ROOM_NUMBER = flag.attributes.room_id -%}
{% if loop.last %}
{%- set ROOM_NUMBER_STR = (ROOM_NUMBER|string) -%}
{% else %}
{%- set ROOM_NUMBER_STR = (ROOM_NUMBER|string +",") -%}
{% endif %}
{%- set ns.COMMAND = ns.COMMAND + ROOM_NUMBER_STR -%}
{%- endfor -%}
[{{ ns.COMMAND }}]
Now in your script code you call the list from the helper sensor:
I love this script but I would like to have it only vacuum the rooms I select–the rooms were the input_boolean for that room is on. The group contains all the rooms and correctly pulls the corresponding seqment numbers, but for my use case, I want to only vacuum the segments where the corresponding input_boolean segment(s) for the rooms have been turned on.
EDIT:
I figured out what I needed: from @123’s first example just add an if around making the room list:
{% if states(room) == 'on' %}
{% set ns.room_numbers = ns.room_numbers + [rooms.get(room)] %}
{% endif %}
I am trying to use this, but I am struggling creating a helper group (group.raumauswahl_erdgeschoss_alle_raume) containing all of my input_boolean helpers. The GUI doesn’t let me create a group containing those helpers, at least the entities can’t be found. Maybe I have to create the group via YAML?
Or is there a better way to get @123 script working, without having to create a group that contains the boolean helpers?
Also, if all of my room helpers are set to OFF, I would like to clean all of the rooms. What’s a good way to achieve that? Add all room ids to “segments”?