ESPHome template sensor — how to make them asynchronous like Home Assistant template sensors?

Is it just me, or are ESPHome template sensors just time-based? I was looking for a template sensor with a lambda that runs whenever the source sensor updates (like how Home Assistant does it). The ESPHome template sensor seems to just run its lambda every x seconds and will grab the source sensor’s value, even if it hasn’t been updated since the last time its lambda ran.

Any way to make the template sensor update only when its source sensor updates?

You could:

  • push the update_interval: out to some arbitrarily large value
  • leave the lambda: out of the template sensor
  • use the publish action in an on_value: or on_state: block within your original sensor.
1 Like

That works great! I thought the sensor.template.publish action would skip the filters on the template sensor (which are important to me, e.g. sliding average) and publish straight to the output value, but it doesn’t, it actually acts like it got the value from a lambda and applies the filters on top of the published value. This is great. Thank you

Like a copy sensor? :thinking: