Notice due to lack of data

Hello, I have some temperature sensors at home via zigbegg connected to a hub. I have that hub in home assistant. The fact is that I receive the house temperatures perfectly in home assistant.

My problem comes from the fact that these sensors do not have a battery meter and I don’t know how to make home assistant notify me that I have not received data from them for more than 2 hours. That would help me detect a warning that it has no battery since it sends data every 5 minutes.

trigger:
  - platform: state
    entity_id: sensor.foo_bar
    to:
    for:
      hours: 2
action:
...

Note: this will trigger if the sensor state stays the same value for 2 hours. So that may give you false triggers if you have a rarely changing sensor.

I have this automation to notify of stale devices

alias: "Notification: Stale devices"
description: ""
trigger:
  - alias: Check for idle Porch Probe
    platform: template
    value_template: >-
      {{ now() - states.sensor.porch_probe.last_changed >= timedelta (hours=11)
      }}
    id: Porch Probe
  - alias: Check for idle Current Cost
    platform: template
    value_template: >-
      {{ now() - states.sensor.cc_power.last_changed >= timedelta (minutes=15)
      }}
    id: Current Cost
  - alias: Check for idle X10 Light Sensor
    platform: template
    value_template: >-
      {{ now() - states.binary_sensor.x10_light_sensor.last_changed >= timedelta
      (hours=20) }}
    id: X10 Light Sensor
  - alias: Check for idle UPS
    platform: template
    value_template: >-
      {{ now() - states.sensor.ups_time_left.last_changed >= timedelta
      (minutes=90) }}
    id: UPS
  - platform: template
    value_template: >-
      {{ now() - states.sensor.hive_temperature.last_changed >= timedelta
      (hours=4) }}
    alias: Check for idle hive temperature
    id: Hive temperature
  - alias: Check for idle Kitchen door temperature
    platform: template
    value_template: >-
      {{ now() -
      states.sensor.lumi_lumi_sensor_magnet_aq2_device_temperature_2.last_changed
      >= timedelta (hours=13) }}
    id: Kitchen door temperature
  - alias: Check for idle Front door temperature
    platform: template
    value_template: >-
      {{ now() -
      states.sensor.lumi_lumi_sensor_magnet_aq2_device_temperature.last_changed
      >= timedelta (hours=13) }}
    id: Front door temperature
  - alias: Check for offline Porch camera
    platform: template
    value_template: >-
      {{ now() - states.camera.porch_main.last_updated >= timedelta (minutes=15)
      }}
    id: Porch camera
  - alias: Check for offline Garden camera
    platform: template
    value_template: "{{ now() - states.camera.garden.last_updated >= timedelta (minutes=15) }}"
    id: Garden camera
condition: []
action:
  - service: notify.telegram
    data:
      title: "*STALE DEVICE* - {{ trigger.id }}"
      message: >
        {{ now().strftime('%H:%M:%S %A %d %B %Y') }} This is probably due to
        running out of batteries or web service downtime
  - service: notify.email
    data:
      title: STALE DEVICE - {{ trigger.id }}
      message: >
        {{ now().strftime('%H:%M:%S %A %d %B %Y') }} This is probably due to
        running out of batteries or web service downtime
mode: single
1 Like

All I need is for @tom_l to beautify it for me by creating a configurable hash :grin:

ah, great! what a good idea, I’ll put it that way.

I could configure it from the visual menu? how would it be?

I could configure it from the visual menu? how would it be?

I have been reviewing both options you give me @_dev_null and @tom_l but I now have a sensor no batteries and it seems that it does not stay at a continuous fixed value or fixed state but rather goes to unavailable. Can I have HA alert me if a device appears as unavailable for several minutes?

Does anyone know how to send a warning when a sensor is not sending temperatures and is in unavailable status?

cal_service notify

Ohh, i guess you “missed” (/dev /null ) 's Solution !

== state

14.04.2024_22.34.48_REC

PS: And please Mark ( /dev /null )'s Answer as Solution, as it cover yours and +100000 other users “thoughts”

EDIT: Would also be appropriate if you would go through your other Topics, and mark those which have a “helped” you with , Marking it as Solution, This would help other who uses the Search Function, to find similar Answers/Solutions

Sorry but I didn’t understand the code, I don’t doubt that it is correct but I need some more help.

I have created this code adapted to my HA

image

alias: "test - Notificacion: Dispositivos sin envio de datos"
description: ""
trigger:
  - alias: Comprobacion de datos Temperatura Habitacion Grande
    platform: template
    value_template: >-
      {{ now() - states.sensor.humidity_158d000101d0d0.last_changed >= timedelta (minutes=1)
      }}
    id: Temperatura Habitacion Grande
  - alias: Comprobacion de datos Temperatura Cochera
    platform: template
    value_template: >-
      {{ now() - states.sensor.humidity_158d00010c37e3.last_changed >= timedelta (minutes=1)
      }}
    id: Temperatura Cochera
condition: []
action:
  - service: notify.push_msg_javier
    data:
      title: "test - Notificacion: Dispositivos sin envio de datos"
      message: "test - Notificacion: Dispositivos sin envio de datos"
mode: single

but I don’t quite understand this part:

  - alias: Comprobacion de datos Temperatura Cochera
    platform: template
    value_template: >-
      {{ now() - states.sensor.humidity_158d00010c37e3.last_changed >= timedelta (minutes=1)
      }}
    id: Temperatura Cochera

that would be::

  • alias: Comprobacion de datos Temperatura Cochera ------> Name you want to give?
    platform: template -------------> Is it always a template?
    value_template: >-
    {{ now() - states.sensor.humidity_158d00010c37e3.last_changed >= timedelta (minutes=1)
    }} ----------------------------> Is it only necessary to change the humidity_158d00010c37e3 value here to the appropriate one, do the states and the last_changed always exist by default in all sensors?
    id: Temperatura Cochera ------> Name you want to give?

I have already managed to make it work, and reduced the code:

alias: "test - Notificacion: Dispositivos sin envio de datos 2"
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now() - states.sensor.temperature_158d0001e89657.last_changed >=
      timedelta (minutes=14) }}
  - platform: template
    value_template: >-
      {{ now() - states.sensor.temperature_158d000101d0d0.last_changed >=
      timedelta (minutes=14) }}
condition: []
action:
  - service: notify.push_msg_javier
    data:
      message: "test - Notificacion: Dispositivos sin envio de datos 2"
      title: "test - Notificacion: Dispositivos sin envio de datos 2"
mode: single

Could you please format this to something human readable ?

  • Alias: Name ( a reference )
  • Platform: No it’s only “template” when it’s the template-platform you are addressing(want to use)
  • Not sure what you mean ( You don’t change the sensor value in the equation/template )
    You basically check “now()” whether last_change >= specified “timedelta”
    (if not =false change to true when it is)
  • State: if it’s working( thou broken is also a state :wink:
  • last_changed: NO , it’s a state in the DB When i.e a sensor change State, the DB/recorder add a timestamp to the column in DB ( Called last_changed )
    id: ID ( a reference )

yes, it works for me! Thank you, only 2 parameters are required:

platform: template
value_template: >

I leave here the solution:

alias: "test - Notificacion: Dispositivos sin envio de datos 2"
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now() - states.sensor.temperature_158d0001e89657.last_changed >=
      timedelta (minutes=14) }}
  - platform: template
    value_template: >-
      {{ now() - states.sensor.temperature_158d000101d0d0.last_changed >=
      timedelta (minutes=14) }}
condition: []
action:
  - service: notify.push_msg_javier
    data:
      message: "test - Notificacion: Dispositivos sin envio de datos 2"
      title: "test - Notificacion: Dispositivos sin envio de datos 2"
mode: single

image

I have a xioami temperature sensor which has 3 entities: battery, humidity and temperature.

sensor.battery_158d000110799c
sensor.humidity_158d000110799c
sensor.temperature_158d000110799c

Sometimes it receives a temperature signal, sometimes a battery signal and sometimes a humidity signal. How can I make a condition to know if in the last 4 hours I have received any data?

{# Temp Int Pasillo #}
{{
now() - states.sensor.battery_158d000110799c.last_changed >= timedelta (hours=4)
and
now() - states.sensor.humidity_158d000110799c.last_changed >= timedelta (hours=4)
and
now() - states.sensor.temperature_158d000110799c.last_changed >= timedelta (hours=4)
}}

First , you should Not put them all in same double brackets, as it result in true or false ( 1 result )
And not i.e True, False, False, or false, true, false

Use /Developer-Tools/Templates, to test and play with your templates

It works perfect for me, I think it is correct, could you show a view with this value? How would you do that? To know the last update received from a sensor?

Im not sure what you mean by

Beside This below, is Not what you asked here

To know the last update received from a sensor!, you just add last_updated … Not last_changed

What ever it is you are trying, i have very hard to understand what you actually are doing.
So please Follow my advice above

And read the DOCS about Template And Templating

Also Please open a New Topic, this is marked Solved, Yet you Keep asking New Question, Totally unrelated to This Topic

How to help us help you - or How to ask a good question.

I mean that this type of code works well:

{# Detector de Humo Cocina #}
{{
now() - states.sensor.battery_158d000130744c.last_changed >= timedelta (hours=24)
and
now() - states.binary_sensor.smoke_sensor_158d000130744c.last_changed >= timedelta (hours=24)
}}

Normally the last_changed usually coincides with the last_updated, doesn’t it?

I want to make a view with several sensors where you can see at a glance when they were last changed.

Do you actually know what the code Does ?, and what the “output/state” of those is ?

No, but sometimes ( When the Value is actually changed )
I:E You look in your wallet, you have 10 buck: Next time you want to check(next Update) You still have 10 Buck, Nothing have change NO Last_Change before you spend a dime

type: entities
entities:
  - entity: sensor.forecast_current_temperature
    secondary_info: last-updated

You REALLY should spend a little time reading the DOCS … Please ?