Do something when Alexa Timer has expired

What kind of notification? It should be.

pushover i utilize for anywhere

Well then add the action that sends it.

but reminder not timer… is possibile?

Thanks for the blueprint, works fine! Is it possible to only start an action, if the timer wasn’t stopped after a specific time?

I’m wondering if it is possible to retrieve the “timerLabel” value of a timer and use it as condition, as this would make some interesting automation possible. For instante, one could ask “alexa, set timer tv 10 minutes”, and the automation would turn off the tv, but only the for the “tv” timer.

Replying to myself: the timer name could be retrieved with something like this:

   {% set foo = state_attr("sensor.echo_dot_next_timer", "sorted_active") %}
   {% set bar = foo|from_json %}
   {{ bar[0][1].timerLabel|lower }}

I ended writing a appdaemon app to do the same (and a few more things), but I leave this as someone might be interested.

2 Likes

Hello, I don’t know if it has to do with the template or with the integration, but the sensor_next_timer gives errors.

Home Assistant 2023.1.7
Supervisor 2023.01.1
Operating System 9.5
Frontend 20230110.0 - latest

Logger: homeassistant.helpers.event
Source: helpers/template.py:425
First occurred: 15:03:30 (1 occurrences)
Last logged: 15:03:30

Error while processing template: Template("{% if states(‘sensor.echo_dot_de_edu_negro_next_timer’) != ‘unavailable’ %} {{ ((as_timestamp(states(‘sensor.echo_dot_de_edu_negro_next_timer’)) - as_timestamp(now()))/60) | int + 1 }} {% else %} 0 {% endif %}")
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1606, in forgiving_as_timestamp
return dt_util.as_timestamp(value)
File “/usr/src/homeassistant/homeassistant/util/dt.py”, line 132, in as_timestamp
raise ValueError(“not a valid date/time.”)
ValueError: not a valid date/time.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 423, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1950, in _render_with_context
return template.render(**kwargs)
File “/usr/local/lib/python3.10/site-packages/jinja2/environment.py”, line 1301, in render
self.environment.handle_exception()
File “/usr/local/lib/python3.10/site-packages/jinja2/environment.py”, line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File “”, line 2, in top-level template code
File “/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py”, line 393, in call
return __context.call(__obj, *args, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1609, in forgiving_as_timestamp
raise_no_default(“as_timestamp”, value)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 1411, in raise_no_default
raise ValueError(
ValueError: Template error: as_timestamp got invalid input ‘unknown’ when rendering template ‘{% if states(‘sensor.echo_dot_de_edu_negro_next_timer’) != ‘unavailable’ %}
{{ ((as_timestamp(states(‘sensor.echo_dot_de_edu_negro_next_timer’)) - as_timestamp(now()))/60) | int + 1 }}
{% else %}
0
{% endif %}’ but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 540, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 425, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: as_timestamp got invalid input ‘unknown’ when rendering template ‘{% if states(‘sensor.echo_dot_de_edu_negro_next_timer’) != ‘unavailable’ %}
{{ ((as_timestamp(states(‘sensor.echo_dot_de_edu_negro_next_timer’)) - as_timestamp(now()))/60) | int + 1 }}
{% else %}
0
{% endif %}’ but no default was specified

The only issue/concern I have: I have to set this up on each individual Alexa device as sensor.this_device_next_timer does not work for me (I imagine that’s more to do with the Alexa Media Player add on than this blueprint).

I did try to add multiple echo devices via the YAML editor, but it did not work out for me. I wound up having to duplicate this automation and save it for each of my 6 different Alexa devices.

I did manage to get an elongated flash of lights to work. Attached are the screenshot for the visual editor, as well as the YAML Editor for posterity/anyone else who may run into this topic in the future.

alias: Entry Door Timer
description: Flash Hue Lights when Echo Timer Goes Off
use_blueprint:
  path: AndrejDelany/do-something-when-alexa-timer-has-expired.yaml
  input:
    echo_device_next_timer: sensor.entry_door_next_timer
    target_action:
      - repeat:
          sequence:
            - device_id: 2ab64fefbe93954fbdc4fb0544560b27
              domain: light
              entity_id: 6c9d7cabde555881da8d6efbf81ecbb4
              type: flash
          count: 30

Is anyone still working this thread? This has been doing my head in! I want to trigger an automation 30 seconds before my Alexa next timer (my echo device) expires. I can post my code, just wondering if anyone else is working on this?

TIA,
Russ

It is correct, that you have to create the automation for each echo separately.

As the creator of this blueprint, I drop by from time to time. Due to time constraints, however, I cannot offer extensive support and therefore I answer questions irregularly. However, in the spirit of open source, anyone can contribute and answer questions.

Thanks for the BP, I use it quite a bit! I’ll let you know if I figure out how to trigger an automation X seconds before timer expires.

Did you figure this out? I’d like to have a trigger based on when the timer starts.

This should work for your trigger…

trigger:
  - platform: state
    entity_id:
      - sensor.YOUR ALEXA DEVICE_next_timer
    from: unknown

Thanks. This works great.