Unavailable / Unknown Entity Monitoring - Template Sensor

I do not have it setup in Lovelace… Did not know that was a required setting.

I certainly don’t have this setup properly as the sensor is not listed in my Entities nor does it show as an option in Dev Tools/States.

Here’s my main config:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Component files
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
zone: !include zones.yaml
rest_command: !include rests.yaml
scene: !include scenes.yaml
input_select: !include inputs.yaml
# Home Assistant
homeassistant:
  packages: !include_dir_named packages
# URL
http:
  base_url: https://xxxxxxxxxxxxx
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
# Text to speech
tts:
  - platform: google_translate
# IFTTT
ifttt:
  key: xxxxxxxxxxxx
# MQTT
mqtt:
  broker: core-mosquitto
  username: xxxxxxxxxx
  password: xxxxxxxxxxx
  discovery: true
  discovery_prefix: homeassistant
  birth_message:
    topic: 'hass/status'
    payload: 'online'
    qos: 0
    retain: false

I have your code in a yaml file in the Packages folder, per instructions.

I’m not actually sure if this matters or not but I’ve always had the homeassistant: section and http: sections at the beginning of my configuration.yaml file. Also not sure if linux is case sensitive or not but make sure whatever your have in your config file (!include_dir_named packages) matches the directory name (you called it Packages in your comment).

Also, if you have not updated to v0.113 yet, comment out the mode: queued line in the automations in the package file.

homeassistant:
  packages: !include_dir_named packages
http:
  base_url: https://xxxxxxxxxxxxx
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Component files
group: !include groups.yaml
automation: !include automations.yaml

etc. etc.

Try that first. Check your config and don’t forget to restart!

Thx! Looks like it was the ‘Packages’ name, and/or arrangement of the config file. Sensor now shows in Entities and Dev Tools/States.

In terms of use… I’m simply using the automations you have in the package; I assumed this would trigger a notification from/in my HA Android app, but sounds like I need to update Lovelace first? If so, how do I do that? Pardon for the ‘learning curve’ questions herein.

Glad you got it working!

The included automations are just simple ones to get you started with the sensor. You do not need lovelace to send notifications to your app.

Also, if a recommendation fixes your problem your should mark that comment as “Solution” so others know.

Thanks again. How do I mark a comment a solution, especially if I did not start the Question, and this is in Projects, so not sure we can even mark solutions. I would, but I don’t find the Solution icon/button.

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