Hi
i have some BLE sensors that need a battery.
sadly they do not give out the battery level, but they send all their data every minute.
the data are received with a Lolin D32 and esphome
is there a trigger that activates when no data has been received for a period of time?
i didn’t really find anything in the documentation.
Most entities do not report last updated.
But the statistics sensor does. You can set up a statistics sensor to hold only one value and it will show you the datetime of the last report.
You can have more than one value in the sensor, but unless you need the statistics, then one is enough.
Then you will have a sensor named “stats”.
This sensor should have an attribute called min (or max) age and that is the newest/oldest data points in the sensor.
But in your case with 1 as sampling size, it should be the same.
You’re not alone in thinking the States view shows everything.
It’s after reviewing the properties of the State Object does it become clear just how much information is available and the subset displayed in the States view.
One thing to keep in mind is that last_updated is not an attribute. In other words, this does not work:
# Invalid attempt to get 'last_updated'
{{ state_attr('binary_sensor.rear_door', 'last_updated') }}
The other thing is that last_updated reports the last time anything changed. In other words, it could be the entity’s state changed (but not if the value is the same) or any one of its attributes changed.
If someone were interested only in knowing when an entity’s state changed (and only its state, not one of its attributes), they can refer to its last_changed property.
Here’s a Template Sensor you can experiment with (you’ll need to change the entity name and the action to suit your needs).
- alias: 'BLE_Sensor Watchdog'
trigger:
platform: template
entity_id: sensor.time
value_template: "{{ now().timestamp() - states.sensor.ble_sensor.last_updated.timestamp() > 90 }}"
action:
service: persistent_notification.create
data:
title: 'BLE_Sensor value is stale.'
message: 'Value has not been updated in over 90 seconds.'
You will need to use the Time & Date integration to create sensor.time. It changes state every minute and so it will cause the Template Sensor to be evaluated every minute.
The Template Sensor simply checks if there’s more than 90 seconds difference between the current time and the BLE sensor’s last_updated. If there is then a persistent_notification is produced.