I have a bunch of sensors that all have a few outliers, for which I found there is an outlier filter. But it’s 4 entities per device for a growing set of devices, so manually adding a filter sensor for each entity is very tedious.
Is it possible to somehow use templates to generate filters for every device in an integration? Or at least for a hardcoded list of entities?
For the curious, they’re Xiaomi BLE plant sensors, which have some pretty bad outliers.
If at all possible, figure out whether what you want can be acheived partly or in whole using YAML tools like anchors and merging. Even a slightly reduced config entry will make the following easier…
You cannot use templates to build YAML configuration in situ, but you can use the Template editor to iterate over your entities to “print” something you can paste into your configuration file.
You’ll have to decide for yourself, based on the complexity of the sensors you are setting up, whether or not it’s actually worthwhile to take the time to construct the template.
#For use in Template Editor ONLY
# DO NOT USE DIRECTLY AS CONFIGURATION
sensor:{% for c in integration_entities("xiaomi_ble") %}
- platform: filter
name: Filtered {{ state_attr(c, "friendly_name") }}
entity_id: {{c}}
filters:
- filter: outlier
window_size: 4
radius: 50.0{% endfor %}