Hi all,
I am trying to create a script to allow users to select from a list of rooms to send my vacuum to clean.
I am trying to use the script fields “select” to allow for a custom list of rooms. The issue is that the rooms are mapped to an integer. I am struggling to convert the list of room names to a list of integers.
I have tried using the select selector’s label/value pair, but get an error when trying to use integers as the value eg:
options:
- label: Kitchen
value: 8
I then tried using a dictionary to convert keys a few different ways, but have not been able to get that to work.
Dictionary:
sequence:
- variables:
room_dict:
Kitchen: 11
Dining Room: 8
Living Room: 4
Entry: 7
Master Bedroom: 6
Guest Bedroom: 3
Hallway: 10
Bathroom: 5
Closet: 9
Office One: 1
Office Two: 2
I have tried:
- variables:
room_ints: "{{ room_dict.room_names }}"
→ Returns empty list
- variables:
room_ints:
"{% for room in room_names %}"
- "{{ room_dict.room }}"
"{% endfor %}"
→ Doesn’t save and doesn’t work when manually put into yaml.
I need the final service call to look similar to this:
- service: vacuum.send_command
data:
command: roomClean
params:
roomIds:
- 1
- 8
count: 1
target:
entity_id: vacuum.eufy_vac
What is the correct way to apply a dictionary to a list of strings? Or, how can I convert my strings to the corresponding integers? I’m not opposed to using the label/value combo, but I don’t think I can supply my vacuum with numbers formatted as strings. (I have not tried).
Full yaml:
alias: Vacuum Rooms
sequence:
- variables:
room_dict:
Kitchen: 11
Dining Room: 8
Living Room: 4
Entry: 7
Master Bedroom: 6
Guest Bedroom: 3
Hallway: 10
Bathroom: 5
Closet: 9
Office One: 1
Office Two: 2
- variables:
room_ints: "{{ room_dict.room_names }}"
- service: vacuum.send_command
metadata: {}
data:
command: roomClean
params:
roomIds: "{{ room_ints }}"
count: 1
target:
device_id: 32052100aa9681a3f547b08f1f292448
mode: single
icon: mdi:robot-vacuum
fields:
room_names:
selector:
select:
multiple: true
options:
- Kitchen
- Dining Room
- Living Room
- Entry
- Master Bedroom
- Guest Bedroom
- Hallway
- Bathroom
- Closet
- Office One
- Office Two
name: Rooms
required: true
default:
- Kitchen
- Dining Room
description: Text based list of rooms to vacuum