Badges for addon service status

templates
Tags: #<Tag:0x00007fd07871b358>

#1

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!


#2

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.


#3

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:


#4

Here is how I do it.

Create a sensor for the add-ons:

Optionally, you can create switches to control the add-ons:

Finally, a notification if an add-on stops


#5

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’))


#6

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.


#7

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’))"


#8

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


#9

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

#10

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.


#11

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


#12

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


#13

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


#14

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:


#15

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:


#16

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