ESPhome sensor battery monitoring: update from HA v7.6 to 8.x renders "battery-low" alert non-functional

Good morning community,

with the help of numerous threads I read here I could set up battery monitoring of my ESPhome based ESP-01 temperature sensors which was (!) working reliably until I chose to update my Home Assistant installation to v8.0 which rendered the battery monitoring unusable.

I’m monitoring the temperature and humidity updates (which are also updated every 15 min. if there’s no value change) and an automation checks if the value exceeds 3600sec. Prior to the OS and Core updates, if a sensor didn’t send an update within the last hour, an alert is sent via mail/app to check the battery. But now, this isn’t working anymore.

I used the developer tools and saw that the seconds value since the last update cycle is still calculated correctly when pasting the code from my configuration.yaml.

library_lastupdate:
        friendly_name: "Sensor library last update"
        value_template: >-
          
            462
          
        unit_of_measurement: "Seconds"
        device_class: timestamp

configuration.yaml

sensor
  - platform: template
    sensors:
      library_lastupdate:
        friendly_name: "Sensor library last update"
        value_template: >-
          {% if states.sensor.library_temperature.last_updated > states.sensor.library_humidity.last_updated %}
            {{ (as_timestamp(now()) - as_timestamp((states.sensor.library_temperature.last_updated) | default(0)) | int ) | round(0) }}
          {% else %}
            {{ (as_timestamp(now()) - as_timestamp((states.sensor.library_humidity.last_updated) | default(0)) | int ) | round(0) }}
          {% endif %}
        unit_of_measurement: "Seconds"
        device_class: timestamp

This is the automation comparing the value of the sensor above to the threshold value of 3600sec.

- id: '1641394205454'
  alias: 'Temperature Sensor Library (App): Battery warning'
  trigger:
  - platform: numeric_state
    entity_id: sensor.library_lastupdate
    above: '3600'
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  condition:
  - condition: time
    after: 07:00
    before: '22:00'
  action:
  - service: notify.mobile_app_floriantelefon
    data:
      message: Please change battery!
      title: 'Temperatur sensor library: battery empty!'

From my point of view either the sensor value is not correctly evaluated by the automation or the automation is no working correctly anymore but I know where to look at to further troubleshoot this.

Thanks a lot for any useful hints.
Florian

Missing a quote after sensor, although I guess you typed that manually to avoid pasting in lots of the file.

In your templates, you use int, which should now take a default value e.g. int(0). This error should be visible in your HA logs. What is the current state of your sensor in Developer Tools / States?

Hi Troon, sorry for the late reply. I didn’t receive a notification via mail and need to check the settings here in the portal to enable that.

You are right, I manually added those two lines to the output here. The code indeed contains a colon (not quote)

sensor:
  - platform: template
<...>

The default value is achieved with the default(0) as far as I know but the state visible in the developer tools is as follows (it is in German, I translated the words in my initial post so that is easily readable/usable for others as well). The value is unknown which I can’t understand as it correctly calculates when I paste it in the developer tools.

Thanks for helping me.