the key isn’t to use the state of the next timer but the time remaining value in the attribute of each timer.
try this automation to see if it works for you if you want to:
- alias: flash lights when echo timer is done
trigger:
- platform: state
entity_id: sensor.garage_dot_next_timer
condition:
- condition: not
conditions:
- condition: state
state: unavailable
entity_id: sensor.garage_dot_next_timer
action:
- delay: >
{% set index = (((state_attr('sensor.garage_dot_next_timer', 'sorted_active') | from_json)) | list | length) - 1 %}
{{ ((state_attr('sensor.garage_dot_next_timer', 'sorted_active') | from_json)[index][1].remainingTime/ 1000)| round(0) }}
- condition: not
conditions:
- condition: state
entity_id: sensor.garage_dot_next_timer
state: Unavailable
- service: switch.toggle
entity_id: switch.garage_lights_switch
- delay:
seconds: 1
- service: switch.toggle
entity_id: switch.garage_lights_switch
mode: parallel
max: 10
I tested it with two timers (the first was a one minute timer and the second was a two minute timer) and the lights flashed as expected without stopping either timer.
I have to correct us. Looks to me like it’s not correct after all. For me, only the variables declared under “variables:” work in the templates, while the variables defined under “input:” do not work in the templates. Can you check if this is the same for you?
I’m sorry I don’t use blueprints…yet…I haven’t updated to the latest version. (TBH, I don’t know if it’s something I’ll ever use…)
It seems strange that only variables would work in templates in blueprints. I don’t know why they would be treated any differently than any other entity.
Have you found that referenced anywhere in the docs? Maybe it’s a bug?
Oh, and thanks for checking that out and adding it to your work.
I didn’t even actually use that in my test automation so I didn’t really look to closely at it. I didn’t see the need for the second condition check since it was already confirmed in the first one. Then I uncommented it back in when I posted since I realized it would be needed for times when you started a timer but then cancelled it before it had expired and there was no longer a reason to have the lights flash.
As for the rest of your post referencing the choose code…
Where are you seeing that used in this blueprint? it’s not in the OP or mine.
After blueprint import a new automation (action>call service>ligh.toggle>light) is created via GUI, but…
got this error:
Do something when Alexa Timer has expired: Error rendering Do something when Alexa Timer has expired delay template: UndefinedError: list object has no element -1
automation do not work at all. what am I missing here?
you will see that if there is no timer set for the echo that is referenced in the blueprint and then try to run the associated automation manually.
try setting a timer and trying the blueprint again.
Tho I’m surprised that the blueprint config wouldn’t work and gave errors even tho the automation that used it wasn’t executed yet.
If the blueprint config actually checks the results of every template created within it before it is actually executed then I can see that being a big problem since there are a lot of templates that will throw an error because something might not exist before the automation is run.
And the condition that checks that the timer isn’t “unavailable” before evaluating the delay template eliminates that error.
Maybe I’ll revisit the template for the delay and put some error checking in it to eliminate the issue. But it still doesn’t seem right to me.
error: “list object has no element -1” appeared after I created automation with sensor.next_alarm and not sensor.next_timer
Now with correct sensor.next_timer used, error is gone.
It works for timer incl seconds too. it’s precise enough.
TnxUall
Then I still have to say that is potentially going to be a huge problem for more complex blueprints for use in automations. Sometimes you really need to rely on the fact that the template only gets rendered when other conditions are satisfied.
Automations have never worked like that. I wonder why they changed that