jazzyisj/unavailable-entities-sensor

issue with reject filters

Closed this issue · 1 comments

running into an issue with the reject filters on this

here is the strings i want to filter out

sensor.qemu_haos_dev_104_memory_used
sensor.qemu_haos_dev_104_uptime
sensor.roku_streaming_stick_active_app_id

this is the filter formats i have tried
|rejectattr('entity_id','search','(_memory_used|_uptime)')
|rejectattr('entity_id','search','(active_app_id|active_app)')
i also tried breaking them up
|rejectattr('entity_id','search','active_app_id')
|rejectattr('entity_id','search','active_app')
|rejectattr('entity_id','search','_memory_used')
|rejectattr('entity_id','search','_uptime')
tried with or without the starting underscore
|rejectattr('entity_id','search','memory_used')
|rejectattr('entity_id','search','uptime')

but the entities are still not filtered out, the other filters seem to work just fine

full template below

template:
  - sensor:
      - name: "Unavailable Entities"
        unique_id: unavailable_entities
        icon: "{{ iif(states(this.entity_id)|int(-1) > 0,'mdi:alert-circle','mdi:check-circle') }}"
        state: >
          {% set entities = state_attr(this.entity_id,'entity_id') %}
          {{ entities|count if entities != none else none }}
        attributes:
          entity_id: >
            {% set ignore_seconds = 60 %}
            {% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
            {% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
            {% set entities = states|rejectattr('domain','eq','group')
                |rejectattr('last_changed','ge',ignore_ts)
                |rejectattr('entity_id','search','_playlist')
                |rejectattr('entity_id','search','_current')
                |rejectattr('entity_id','search','_identify')
                |rejectattr('entity_id','search','_restart')
                |rejectattr('entity_id','search','_preset')
                |rejectattr('entity_id','search','(active_app_id|active_app)')
                |rejectattr('entity_id','search','_application')
                |rejectattr('entity_id','search','grill_')
                |rejectattr('entity_id','search','ibbq_')
                |rejectattr('entity_id','search','octoprint')
                |rejectattr('entity_id','search','segment_')
                |rejectattr('entity_id','search','(_memory_used|_uptime)')
                |selectattr('state','in',['unavailable','unknown']) %}
            {% set entities =  entities|rejectattr('entity_id','in',ignored)
                if ignored != none else entities %}
            {{ entities|map(attribute='entity_id')|list }}

group:
  ignored_unavailable_entities:
    entities:
      - button.nas_reboot
      - button.nas_shutdown
      - sensor.desk_height

Interestingly enough I've run into a similar issue in my config. I have a handful of entries the 'search' test just will not work for. I haven't figured out why yet, but I did resolve it by using "contains" test.

|rejectattr('entity_id','contains','jason_laptop')

I see you marked your issue as closed. How did you resolve it?