Unavailable / Unknown Entity Monitoring - Template Sensor

Click this button on the comment you want to mark.

Lol, this is YOUR thread, how’s someone else going to mark it as solved? :see_no_evil:

@ScottS, don’t worry about it, I think Jason needs a lie down…

Huh. Since when does the person supplying the solution mark it solved? How do I know if it worked for him? Have I been doing this wrong all along? :thinking:

Not that I care about it here, but more good info for him in the future. Annoying when people don’t mark it.

No, what he was saying is that you started this thread. So you are the only one who can mark the thread as “solved”. No one else even has the icon to mark it as “solved”.

Scott just happened to ask you a question that you answered in your own thread. Scot can’t mark your thread as solved. Only you can.

:laughing:

Dunno what the hell I was thinking. Other things on my mind I guess.

2 Likes

Hi, seems I can’t make it to work. Here is what I have:
Configuration.yaml:

Sensor:
  - platform: template
    sensors:
      unavailable_entities:
        entity_id: sensor.time
        friendly_name: Unavailable Entities
        unit_of_measurement: items
        icon_template: >
          {% if states('sensor.unavailable_entities')|int == 0 %} mdi:check-circle
          {% else %} mdi:alert-circle
          {% endif %}
        value_template: >
          {% set count = states|selectattr('state','in',['unavailable','unknown','none'])
            |rejectattr('entity_id','in',state_attr('group.ignored_sensors', 'entity_id'))
            |rejectattr('domain','eq','group')|list|length %}
          {{ count }}
        attribute_templates:
          entities: >
            {% set entities = states|selectattr('state','in',['unavailable','unknown','none'])
              |rejectattr('entity_id', 'in', state_attr('group.ignored_sensors', 'entity_id'))
              |rejectattr('domain','eq','group')|list|join(', ') %}
            {{- entities -}}
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

Automations.yaml:

- alias: "Sensor Unavailable Notification"
  trigger:
    platform: state
    entity_id: sensor.unavailable_entities
  condition:
    condition: template
    value_template: "{{ trigger.to_state.state | int > trigger.from_state.state | int }}"
  action:
  - delay:
      seconds: 30
  - service: homeassistant.update_entity
    entity_id: sensor.unavailable_entities
  - condition: template
    value_template: "{{ states('sensor.unavailable_entities') | int >= trigger.to_state.state | int }} "
  - service: notify.pushover
    data_template:
      message: "Unavailable Sensors: {{ state_attr('sensor.unavailable_entities','entities').split(', ') | join('\n') }}"

But it’s not working. Do I have to do anything else? Thanks.

What does not working mean? You have both the sensor configuration and an automation there. Is there a sensor.unavailable_entities listed in the Developer Tools states page?

I display a UI card with any unavailable entities. This works now great, however, when the entity becomes available again, it is not removed from the unavailable entities list until I reboot HA. Is there a means to have the card refreshed when an entity is back online?

Yes there is but stays unknown even if I turn off a smart bulb from a physical switch.

If that line is in the sensor config, it should be updating every minute (which means it can take up to a minute to reflect any changes). What card are you using to display your unavailable sensors? If anything all you should have to do is refresh your lovelace view. You should never have to reboot HA to see any changes.

A markdown card is probably be the easiest way.

  - type: markdown
    title: "Unavailable Sensors"
    content: "{{ state_attr('sensor.unavailable_sensors','names') }}"

The state of this sensor should never be unknown, it should always resolve to an integer number.
You are going to have to post your config so we can see where you’ve gone wrong.

Can you confirm that you have configured sensor.time? It’s part of the Time & Date integration and looks something like this:

sensor:
  - platform: time_date
    display_options:
      - 'time'

entity_id: sensor.time is in the config.

UI card… here’s a screenshot of this card’s code I’m using. I’m not certain wha the card is; it’s a card I selected from the Lovelace UI options.

sensor.time is in the config for this package, but I have not configured a sensor like you show anywhere in my code. Where should this code appear/be placed?

Edit: I found the sensor info and placed in my config file.

Update: Since adding Date & Time to my config, the Unavailable Sensors card has been properly updating… thanks.

Post 92

D’oh! Sorry lost track.

I don’t see the ignored sensors group in the config you posted. That’s probably your issue. That is explained in the comments in the gist. Also I think the sensor config in the gist has been updated since version you have there.

I updated the gist to include the time_date sensor config. I guess I assumed everyone would have that already configured (really not sure why it isn’t just present by default). I really gotta stop assuming things…

There are big changes coming in how listeners are assigned to Template Sensors. Currently, if the entities in the template aren’t obvious, no listeners are assigned and the template never gets evaluated (only at startup). So a common workaround is to include sensor.time just because it changes state every minute (which causes the template to be evaluated). This will become far less necessary once the improvements are released (possibility in 0.115).

So many changes happening now it’s hard to keep up with them. Thanks for the heads up!

I actually have a few sensors where I’ve had to resort to using sensor.time to keep it updated. Always been curious how much overhead was involved in doing that. I imagine there has to be some sort of performance hit, but I’ve never noticed it.

Ok now it’s working as expected except that file editor shows the red exclamation mark after adding the ignored sensors group.

1 Like