Incorrect state for sensor

I am trying to display number of entities that are in the state of unknown, unavailable or none. Here is my sensor config:

  - platform: template
    sensors:
      unavailable_entities:
        entity_id: sensor.time # updates sensor every minute
        friendly_name: Unavailable Entities
        unit_of_measurement: entities
        icon_template: "{{ 'mdi:check-circle' if states('sensor.unavailable_entities')|int == 0 else 'mdi:alert-circle' }}"
        value_template: >
          {{ states|selectattr('state','in',['unavailable','unknown','none'])
            |rejectattr('entity_id','in',state_attr('group.ignored_entities', 'entity_id'))
            |rejectattr('domain','eq','group')|list|length }}
        attribute_templates:
          entities: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])
              |rejectattr('entity_id', 'in', state_attr('group.ignored_entities', 'entity_id'))
              |rejectattr('domain','eq','group')|map(attribute='entity_id')|list|join(', ') }}
          names: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])
              |rejectattr('entity_id', 'in', state_attr('group.ignored_entities', 'entity_id'))
              |rejectattr('domain','eq','group')|map(attribute='name')|list|join(', ') }}

If I put this code in the template tool under development tools I get correct data:

- platform: template
    sensors:
      unavailable_entities:
        entity_id: sensor.time # updates sensor every minute
        friendly_name: Unavailable Entities
        unit_of_measurement: entities
        icon_template: "mdi:alert-circle"
        value_template: >
          3
        attribute_templates:
          entities: >
            binary_sensor.lumi_lumi_sensor_magnet_aq2_cd122a04_on_off, light.sidbord, sensor.tradfri_remote_control_3
          names: >
            Köksfönster 2, Sidbord, TRADFRI remote control 3

But, when I check the state of the sensor in development tools it returns a 207 and lists all my sensors (same as in lovelace).

What am I doing wrong here?

/Carl

When you restart, all entities are unavailable. Just wait 1 minute and it should update.

It does not update though :frowning_face:
It stays at listing all entities.

Do you have sensor.time integrated into your system?

1 Like

@petro
That was it! Didn’t have sensor.time! Added and it works like it should!

Out of curiosity, are you currently using version 0.114?

@123
Yes, I’m running 0.114.

I was hoping to show you how to use a new feature in 0.114. Unfortunately, after trying it, I discovered it fails to work correctly.