#Do something when entities / devices become unavailable?

1 messages · Page 1 of 1 (latest)

dark coral
#

I have a bunch of BLE devices connected over a ESPHome Bluetooth proxy, and sometimes they all go unavailable. When this happens I need to power cycle the ESPHome device to get them back. Is there an easy way to do this using automations? or better, a ready made template

dark coral
#

had claude make me this, I don't know if it will work, can someone tell

fierce geode
#

in priciple it looks it could work. Use the template editor in developer tools and try what the template returns. The only thing I don't get is why / 2 in the equation?

dark coral
gloomy wing
#

I posted my method of monitoring entities in another thread. #1464606159334932733 message
It uses a templated sensor entity watching entities that are labeled. Automation triggered when the count of entities that are unavailable changes. Notification says what device is unavailable.
If you wanted to try something like my method, instead of watching entities that are labeled, you could use something like integration_entities("Demo") (where Demo is the name of the ESPHome Bluetooth integration). Then, you don't have to worry about hard-coding the entities. As you add/remove BLE devices, the template will already be watching them.

dark coral
gloomy wing
#

You can see here how the device links back to the integration.

#

The "hard" part is figuring out the integration's actual name to use in the template. I used this in Developer Tools: yaml {% set config_id = config_entry_id('sensor.freezer_battery') %} {{ config_entry_attr(config_id, 'domain') }} which returned govee_ble.
Using {{ integration_entities("govee_ble") | expand() | sort(attribute='entity_id') | map(attribute='entity_id') | list }} returned a list of entity_ids (I used name in the original template) ['sensor.freezer_battery', 'sensor.freezer_humidity', 'sensor.freezer_signal_strength', 'sensor.freezer_temperature', 'sensor.refrigerator_battery', 'sensor.refrigerator_humidity', 'sensor.refrigerator_temperature']

gloomy wing
#

The takeaway from all of this is you can write a template to return just about anything that you want it to return. It's just a matter of figuring the how. Since you're using a standardized naming convention (all the entities are named similarly), you could return everything named sensor.3dlie_yin_jo_wen_shu_du_ji_*_battery. For example,
{{ states.sensor | selectattr('object_id', 'match', 'freezer') | map(attribute='entity_id') | list }}returns ['sensor.freezer_temperature', 'sensor.freezer_humidity', 'sensor.freezer_battery', 'sensor.freezer_signal_strength'].

gloomy wing
# dark coral I asked claude to do it, so the logic is when half of them become unavailable th...

Looking back at this original template, the logic seems confusing to me. You don't need a total count of entities and, I think your comparison should be {{ unavailable > 0 }}.
In it's current form, if one entity goes unavailable, {{ 1 > 7 / 2 }} would return false. You would need four entities to be unavailable before it would return true.
@fierce geode what are your thoughts on this?

fierce geode