#Script with variable
1 messages · Page 1 of 1 (latest)
Another thing you could do is create an "input number" helper for each room. The name of the entity would be the room name, and you can set the value to the segment number for that room. Then reference it in your other scripts like {{ states("input_number.roborock_kitchen_segment") }}
Go to scripts, select "Add Fields" in the overflow menu
Add a field with selector type select
Here's an example script to get you started:
sequence:
- variables:
room_ids:
Kitchen: 21
Bathroom: 24
Bedroom 1: 16
Bedroom 2: 17
Bedroom 3: 18
Bedroom 4: 19
Living Room: 99
- action: notify.persistent_notification
metadata: {}
data:
title: Cleaning Room
message: "Cleaning {{room}} (id: {{room_ids[room]}})"
fields:
room:
selector:
select:
options:
- Kitchen
- Bathroom
- Bedroom 1
- Bedroom 2
- Bedroom 3
- Bedroom 4
- Living Room
name: Room
alias: Clean Room
description: ""
When you call the script it has a dropdown for your desired room:
That would be a good way to do it if you want a single script which can be run for different rooms. You can call it from an automation or another script and pass it a specific room name, too.
Other option for making a "list in one place" is to make a single template and just stuff the whole list/map into an attribute
that would have to be done in yaml though
That will work for multiple too
if you change the selector to multiple
If you just want the single list and no script, then I guess the template entity is the way to go.
with the list in the attribute
HA doesn't really have "generic global variables"
Yeah it's definitely a learning curve
Well, yes it wasn't written for that, it would have to be changed to some other template
will get more complicated as you have to iterate each item in the list in the input variable and map it to the id
the answer has stumped me a bit, I'm sure it's possible but it probably involves a jinja foreach loop where you build a new array of IDs from the array of room names
There's always #1284966664357810196 if you have more complex templating question.