Select different template based on button selection

Hi all, hope someone can help out with this:

I have a Eufy X10 Pro which is working great via this great HACS repo.

I have placed a button in each room with a template that will send out the Vac to clean the respective room individually. That’s pretty straight forward as the template simply includes a room ID.

I would now however like to have something on a Vacuum dashboard that does it the other way around. Something that would allow me to select multiple rooms. The problem with that is that it would need to add room ID’s to a template on the fly depending on the room selection. So I guess this would call for some kind of dynamic templating solution.

This is an example of the segment that calls for the cleaning of 2 rooms. 2 is dining room, 3 is kitchen:

perform_action: vacuum.send_command
  target:
    entity_id: vacuum.robovac_x10_pro_omni
  data:
    params:
      data:
        command: room_clean
        params:
          rooms:
            - 2
            - 3
          map_id: 17

So imagine I have a selectable button per room on a dashboard and I’ve selected dining room and kitchen. Depending on which buttons are selected, it would build the template so in this case the template would be as above with both room ID’s. But when I deselect dining room, then the template would have to remove the Kitchen Room ID (room 3).
I’d then have a ‘Go’ button that would call the template based on the selection of rooms made .

Maybe there’s an easier way to do this but don’t really see how. Appreciate any insights anyone could share.
TIA!

Nobody? :pleading_face:

I’m not good at scripting in Jinja or YAML and basically what I’m trying to achieve is:

If button 1 is active but button 2 is inactive, and ‘Go’ button is pressed, trigger Template 1 (containing the RoomID for Living Room)
If button 2 is active but button 1 is inactive, and ‘Go’ button is pressed, trigger Template 2
(containing the RoomID for Dining Room)
If button 1 and button 2 are both active, and ‘Go’ button is pressed, trigger Template 3
(containing the RoomID for both Living Room and Dining Room)

There’s quite a few more buttons then just 1, 2 and Go which is why doing this via an automation seems insurmountable, hence asking for the assist.
I have 8 rooms total so the different combinations of rooms is quite substantial and that’s without even going into the permutations side of things (which I’m happy to leave well enough alone). So I don’t think I want to be manually doing this.

Many thx!

This sounds like an interesting setup! Maybe use 8 input booleans helper with your rooms, and a script that cleans the rooms based on input select values? I believe if you name them something like, room_clean_xxx or something else that is easy to script I guess, adding removing and renaming rooms should not be too painful

1 Like

First of all, you can’t use templates in a tap_action. So you will need to create a script, and then call the script. In the script you can use templates to clean only those rooms you want.

As suggested by @jeppesen you can indeed use input_booleans and name them smartly (eg input_boolen.clear_room_3 for the kitchen).

You could also use a mapping variable to map the input booleans to the rooms.

alias: Start vacuum based on input booleans
variables:
  mapper:
    - boolean: input_boolean.clean_living
      room: 1
    - boolean: input_boolean.clean_kitchen
      room: 3
sequence:
  - action: vacuum.send_command
    target:
      entity_id: vacuum.robovac_x10_pro_omni
    data:
      params:
        data:
          command: room_clean
          params:
            rooms: "{{ mapper | selectattr('boolean', 'is_state', 'on') | map(attribute='room') | list }}"
            map_id: 17
2 Likes

Thx for the replies guys!
A bit busy flying around for work so not enough time atm, but definitely keen to try.

The boolean part I had already figured, that was kind of a given :smiley:
It’s the scripting side of things that’s the tricky part.
I’m averagely decent at figuring out and editing exisiting low to mid complexity scripts, but suck at getting things started from scratch.

Thx for the code @TheFes, very very very much appreciated.
I’ll report back as soon as I’ve been able to play around with it!

Eureka, it works @TheFes !!!
Finally returned home and was able to test this out.

You did make a mistake in the script by doubling up on data and params but once I noticed that it was pretty straight forward.
Threw together a quick dash to select the rooms and now it’s busy doing it’s thing cleaning the bar and kitchen area. Mrs will be really happy :smiley:
And let’s face it, so am I :wink:

Thx again!

variables:
  mapper:
    - boolean: input_boolean.clean_living_room
      room: 9
    - boolean: input_boolean.clean_dining_room
      room: 6
    - boolean: input_boolean.clean_bar
      room: 7
    - boolean: input_boolean.clean_kitchen
      room: 3
    - boolean: input_boolean.clean_kitchen_counter
      room: 2
    - boolean: input_boolean.clean_toilet
      room: 1
sequence:
  - action: vacuum.send_command
    target:
      entity_id: vacuum.robovac_x10_pro_omni
    data:
      command: room_clean
      params:
        rooms: >-
          {{ mapper | selectattr('boolean', 'is_state', 'on') |
          map(attribute='room') | list }}
        map_id: 17
alias: X10 Room Selection
description: ""
icon: mdi:robot-vacuum
1 Like