Badges for addon service status

Hi,

Just a HA user for a couple of months, already in love with it :blush:

A couple of Hassio Addons were stopped for some days, until eventually I realized I had an issue with the service.

I’m trying to find a way to create an ‘status sensor’ for those addons, so I can show their status (running/stopped) as lovelace badges.

Anyone faced the same and found how to solve it?

Qny help is appreciated!

I’m not sure about detecting individual addons, but if you use the Glances addon with the Glances sensor, you can get that to tell you the number of running containers. If you know how many should be running you could make an automation to alert you if that number changes.

That would worked if I were interested on monitoring all the addons, but not sure if that fits when focusing on a specific one. Let’s have a look into Glances though, thanks :wink:

Here is how I do it.

Create a sensor for the add-ons:

Optionally, you can create switches to control the add-ons:
https://github.com/SilvrrGIT/HomeAssistant/blob/master/switches.yaml#L124

Finally, a notification if an add-on stops

2 Likes

I’ve checked at your Github and definitelly looks to be what I need! :slight_smile:

However, tried to make a sample for duckdns using this info at my secrets.yaml generates a sensor.duckdns entity with “Unknown” state. Do these secrets look fine at your sight?

duckdns: https://mydomain.duckdns.org:8123/hassio/addon/core_duckdns
llt: “Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”

I get this error at log:

Error fetching data: <PreparedRequest [GET]> from https://mydomain.duckdns.org:8123/hassio/addon/core_duckdns failed with HTTPSConnectionPool(host=‘mydomain.duckdns.org’, port=8123): Max retries exceeded with url: /hassio/addon/core_duckdns (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x7576ec70>: Failed to establish a new connection: [Errno 111] Connection refused’))

Look good. I assume you chagned ‘mydomain’ to your actual domain?

Does the call to your domain loop back to your HA server? Ie, in a browser can you enter https://mydomain.duckdns.org:8123 and get to your frontend? Or do you need to enter the actual IP?

Also, I will get that error sometimes when things are starting up, I think the supervisor isn’t ready to respond to requests or something while homeassistant is making the requests at startup. It will populate the status after a minute.

Yes, mydomain is just for sanity, I se my own, and I always access that URL to access my FE (have that NATed at my router).

When HA starts up, I get a diferent error, which looks like it being unable to use rest API at startup: “Platform rest not ready yet. Retrying in 30 seconds.”

NOw I can see more recent errors like: " Error fetching data: <PreparedRequest [GET]> from https://mydomain.duckdns.org:8123/hassio/addon/core_duckdns failed with HTTPSConnectionPool(host=‘mydomain.duckdns.org’, port=8123): Max retries exceeded with url: /hassio/addon/core_duckdns (Caused by NewConnectionError(’<urllib3.connection.VerifiedHTTPSConnection object at 0x6e80ce10>: Failed to establish a new connection: [Errno -3] Try again’))"

are you missing the /info at the end of the URL?

It should be https://myhome.duckdns.org:8123/api/hassio/addons/core_duckdns/info

No, that doesnt work, either. I seems any header from my config is not ‘compatible’ with my current setup…but no idea why :face_with_raised_eyebrow:

  • platform: rest
    resource: https://mydomain.duckdns.org:8123/hassio/addon/core_duckdns/info
    name: duckdns
    value_template: ‘{{ value_json.data.state }}’
    scan_interval: 60
    headers:
    Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpasdfghjklpouiytrewqzxcvbnmNDM0ZGMwOGQ0NTg0ODk2NjgyMDNiMiIsImlhdCI6MTU1MjU4ODU0NywiZXhwIjoxODY3OTQ4NTQ3fQ.xE3vt2Aeiaqz48UoLeVXqm8uIKJ396gXbDOAgp-BbZg
    Content-Type: application/json

Took me way longer than I wanted to spend on this, but here is a custom component that can get the state:

USE AT YOUR OWN RISK

It’s pretty hacky at the moment. I was even so lazy as to modify the object the hassio component uses by adding some methods to it directly. Make sure you have a way to access your configs without the hassio component and disable this custom component if you run into issues.

Put all of those files under custom_components/hassio_info/ and then add to your config:

hassio_info:

It will find your installed addons automatically and create two sensors and a switch for each one:

  • sensor.hass_io_addon_name_version: current version
  • sensor.hass_io_addon_name_last_version: latest available version
  • switch.hass_io_addon_name: switch to turn on/off

You currently have to restart whenever you install an addon for it to get picked up.

5 Likes

Thank you for the effort!! Looks pretty!

After following your instructions, I created a sensor as:

sensor:

  • platform: hassio_info
    addon: duckdns

and I get the following error. I guess the issue comes from the addon ID (“duckdn” in my sample avobe), mabe I have to use an alternate ID? Where should I get it from?

2019-03-14 23:22:36 ERROR (MainThread) [homeassistant.components.sensor] hassio_info: Error on device update!
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py”, line 248, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity.py”, line 346, in async_device_update
await self.async_update()
File “/config/custom_components/hassio_info/sensor.py”, line 67, in async_update
info = await self._hassio.get_addon_info(self._addon)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/hassio/handler.py”, line 43, in _wrapper
raise HassioAPIError(data[‘message’])
homeassistant.components.hassio.handler.HassioAPIError: Addon does not exist

If you go to the add-on page where you can start/stop it you can see it at the end of the URL.

Edit: Updated with switches and to automatically find addons. See my post above.

1 Like

Incredible!! Great, thank you very much!! Works perfectly for me! Just tested and created an entity for each addon with all those sensors. I cannot see the switches…but seems you’re still modifying code :slight_smile:

We keep check it later, man. This was much more I expected to get for free!! :blush:

Just finished making sure everything was updated. There should be four files now. If they’re still not showing up with all of those :man_shrugging:. If you get an error in the logs I can look into it though.

I wanted an excuse to write a custom component anyway and since I use hassio it sounded like a good idea to have a way to be notified if something goes wrong. It was a win win.

I probably won’t do much more for now. Maybe at some point I’ll clean it up and make a separate post for everyone to use or try to get it merged into the core components somehow. I wouldn’t mind if someone else took over and did that for me though :laughing:

Updated in my hassio and now all entities are shown. I think this definitelly should be a builtin component in the system! Love it!

Hi silvrr,
I would like to integrate the addon status in my config using your way, but I have the same issue described by fgsalvado ([Errno 111] Connection refused’).

I noticed that if I try to connect via browser for example to
https://xyz.duckdns.org:8123/hassio/addon/core_samba/info
after the login page I see a warning page (Warning: Protection mode is disabled!), but if I hit “Enable protection mode” nothing happens.
Any help?
Thanks a lot

I don’t think you can connect directly with a browser like you are trying to do, you need to authenticate with the API.

What does your actual config look like?

Hi, here only the samba addon example extracted from the package created into the packages folder.

switch:
  - platform: template
    switches:

       samba:
        value_template: "{{ is_state('sensor.samba', 'started') }}"
        turn_on:
          service: hassio.addon_start
          data:
            addon: core_samba
        turn_off:
          service: hassio.addon_stop
          data:
            addon: core_samba

sensor:
  - platform: rest
    resource: https://xyz.duckdns.org:8123/hassio/addon/core_samba/info
    name: samba
    value_template: '{{ value_json.data.state }}'
    scan_interval: 5
    headers:
      Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhYThiMWJmY2NkOTk0NjE2YmEzM2U3YWJmN2FlYmU4NCIsImlhdCI6MTU1NjQwODAzMywiZXhwIjoxODcxNzY4MDMzfQ.zTJKHE7x_rd4zai7UC8pzop_NgNySODsMD4znKtnw_Q"
      Content-Type: application/json

from my configuration.yaml

api:

http:
  base_url: !secret base_url
  ssl_certificate: !secret ssl_certificate
  ssl_key: !secret ssl_key
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.1
    - ::1

Home Assistant 0.92.1

You are using a proxy?

I assume this would work with a proxy but I haven’t tested it with one. I wonder if the request is stopping at the proxy? Can you see in the proxy logs if the requests are going through?