I’m playing with a template select entity to hold a value for a cetain amount of time before reseting to default value. The idea is to trigger it with an event that contains a new value and then use select_option: to check if the trigger contains the default value, and if not run a script that waits and then fires an event with the default value. However the select_option: doesn’t seem to go off.
I’ve managed to work around this using an action: after the trigger, but I’m baffled by the behaviour of select_option:, hoping for some insight on this.
Admitedly it took me a bit to realise that select_option: is for selecting an option, however should it not still run the actions defined there?
How I expected it to work:
template:
- unique_id: access_request_user
trigger:
- trigger: event
event_type: user_access_request
select:
- name: Access Request User
unique_id: f5ea3a02-5c00-4828-aa8f-61a88c114735
state: "{{ trigger.event.data.user }}"
options: "{{ ['None', 'Owner', 'User 1', 'User 2', 'User 3'] }}"
select_option:
if: "{{ not trigger.event.data.user is equalto 'None' }}"
then:
- delay: 15
- event: user_access_request
event_data:
user: 'None'
# Also tried replacing above with calling a script to handle the delay and event,
# script never activated
- action: script.turn_on
target:
entity_id: script.access_request_timeout
My work around, since select_option: is required I left a dummy event in there that I could listen for… it never fires.
Functional trigger-based Template Selects are quite new, so I haven’t had time to explore them as much as the state-based variety…
The configuration variable select_option holds a list of actions to execute when a new option is selected either from the frontend or through a script action… Based on how the state-based version has always worked, I would not expect the trigger to also fire the action in select_option.
So, what gets updated with the trigger event? Just the state and options? What about a variables block… do variables get updated and stored so that the updated values are usable in select_option actions?
Variables get resolved when a trigger occurs. They are stored every time a trigger occurs and they get passed to the service whenever the service needs to be executed.
I think I understand… maybe. I had assumed that because select_option: is required that it was always used. action: select.select_option does make use of it and the actions within do indeed go off.
select option is required because the minimum entry for a select entity is a list of options with an action to change the current selected option.
The state is also required, but that’s an oversite IMO and I will likely correct that in the future. I.e. make it optional, when not provided the entity will be optimistic.
Yes, I was hoping to keep the functionality in one spot rather than using an input_select and an automation, and it does serve the purpose even if that’s not its purpose.
Hadn’t though of that, works a charm. I already had the homeassistant start event in an automation as I also needed to catch event_template_reloaded, which of course can’t work inside a template that’s being reloaded.