#Do something when entities / devices become unavailable?
1 messages · Page 1 of 1 (latest)
had claude make me this, I don't know if it will work, can someone tell
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?
I asked claude to do it, so the logic is when half of them become unavailable then power cycle it
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.
I don't think that would work, those entities don't show up under the ESPHome device. Rather, they show up as individual BTHome devices in Home Assistant
The entities are still handled via an integration. I don't run anything with ESPHome so I can't give you a better example. I do use Govee Bluetooth so I'm pretty sure this should be similar.
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']
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'].
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?
He is saying he wants half of them being unavailable before it goes true