Purge all entities but keep only certain sensors

It’s possible via action recorder.purge purge all entities without certain sensors?

Thanks

You can purge all, action: recorder.purge

Or you can purge a list of entities, action: recorder.purge_entities

There are no other purge actions.

You could construct a template for all entities except those on your exclude list and use that with the purge entities service.

action: recorder.purge_entities
data:
  keep_days: 0
  entity_id: >
    {% set exclude = ['sensor.foo','sensor.bar'] %}
    {{ states 
      | selectattr('entity_id') 
      | rejectattr('entity_id','in', exclude )
      | map(attribute='entity_id') 
      | join(',')
    }}

That will purge everything except sensor.foo and sensor.bar

1 Like

Thanks for the solution!