Need time sensor in real time

Hi everybody,

I have a sensor that is supposed to display the remaining time on my echo timer using a template. But it only updates every minute. How do I get it to display this in real time?

Unfortunately I haven’t found anything that helps me.
I need the sensor to display it on awtrix light.

Can anyone give me a hint?

echo_kueche_timer_rest:
        value_template:
          "{{ ((as_timestamp(states('sensor.echo_kueche_next_timer')) - as_times
tamp(now()) - 3600 | round(0))) | timestamp_custom('%H:%M:%S') }}"

I showed someone else how to make the template be updated every second. Before you attempt to do it, be advised that you should exclude your Template Sensor from the Recorder integration. If you don’t, your database size will grow very fast.

2 Likes

The sensor works perfect. Thank you very much. :heart:

I have another question about the recorder.
I wrote in configuration.yaml:

recorder:
  exclude:
    entities:
      - sensor.echo_kueche_timer_rest

But in the log is a warning:

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.echo_kueche_timer_rest, old_state=<state sensor.echo_kueche_timer_rest=01:56:20; friendly_name=echo_kueche_timer_rest @ 2024-02-28T02:35:49.225160+01:00>, new_state=<state sensor.echo_kueche_timer_rest=01:56:19; friendly_name=echo_kueche_timer_rest @ 2024-02-28T02:35:50.227569+01:00>>, skipping template render for Template[{% set x = states.sensor | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count %} {{ ((as_timestamp(states('sensor.echo_kueche_next_timer')) - now().timestamp() - 3600 | round(0))) | timestamp_custom('%H:%M:%S') }}]

Is it critical or can i ignore that? I read that this will not save in the DB. Only log. Is it right?

If you added states.sensor somewhere in your template, change it to something else such as states.binary_sensor or preferably pick a domain that has the fewest number of entities in your system (but greater than zero) perhaps states.cover or states.lock or states.fan.

Ok,

my sensor now looks like this:

 echo_kueche_timer_rest:
        value_template: >
          {% set x = states.lock | selectattr('state', 'in', ['unavailable', 'un
known', 'none']) | list | count %}
          {{ ((as_timestamp(states('sensor.echo_kueche_next_timer')) - now().tim
estamp() - 3600 | round(0))) | timestamp_custom('%H:%M:%S') }}

And in config.yaml the recorder exclude the sensor sensor.echo_kueche_timer_rest.

That’s right?

Edit:

But now the timer doesnt work anymore. Refresh after a minute and not per second like before.

Logger: homeassistant.helpers.script
Source: helpers/script.py:810
First occurred: 09:43:25 (12 occurrences)
Last logged: 09:52:00

Error in 'choose[0]' evaluation: In 'numeric_state': In 'numeric_state' condition: entity sensor.echo_kueche_timer_rest state '00:14:54' cannot be processed as a number
Error in 'choose[0]' evaluation: In 'numeric_state': In 'numeric_state' condition: entity sensor.echo_kueche_timer_rest state '00:14:11' cannot be processed as a number
Error in 'choose[0]' evaluation: In 'numeric_state': In 'numeric_state' condition: entity sensor.echo_kueche_timer_rest state '00:13:11' cannot be processed as a number
Error in 'choose[0]' evaluation: In 'numeric_state': In 'numeric_state' condition: entity sensor.echo_kueche_timer_rest state '00:12:11' cannot be processed as a number
Error in 'choose[0]' evaluation: In 'numeric_state': In 'numeric_state' condition: entity sensor.echo_kueche_timer_rest state '00:11:11' cannot be processed as a number

For all who looking for how to display an echo timer on awtrix pixelclock, here the solution.

I built a timer entity as a helper.

Then create an automation:

alias: Awtrix_alexa_timer
description: ""
trigger:
  - platform: template
    value_template: "{{ states('sensor.echo_kueche_next_timer') != 'unknown' }}"
condition: []
action:
  - service: timer.start
    target:
      entity_id: timer.Awtrix_alexa_timer
    data:
      duration: >-
        {{ (as_timestamp(trigger.to_state.state) - now().timestamp() + 5) |
        timestamp_custom('%H:%M:%S', false) }}
  - wait_template: "{{states('sensor.echo_kueche_next_timer') == 'unknown' }}"
    continue_on_timeout: true
  - service: timer.cancel
    metadata: {}
    data: {}
    target:
      entity_id: timer.awtrix_alexa_timer
mode: single

The second automation from the blueprint here: https://flows.blueforcer.de/flow/wq2NANplO7KV

What is sensor.echo_kueche_next_timer?