Can I write an automation to reload/restart an integration?

Can I write an automation to reload/restart an integration?
I have one integration that occasionally stops and clicking on “reload” brings it back. If I could write an automation that restarts the integration, for example once a day, that would be OK. (Though I would rather the integration not spontaneously stop).

8 Likes

The best I can think of is rebooting homeassistant daily with a homeassistant.restart automation. Alternatively, you could submit a bug on github against that integration and maybe some kind developer can help find and fix the root cause.

2 Likes

Thanks. Restarting Home Assistant sounds extreme, but it will accomplish the same things. Will it, however, also restart Node Red? If so then some of my timings in Node Red may be compromised.

I can’t submit an issue on GitHub because the author has abandoned the repository. The repository is archived (locked) and the author hasn’t been on GitHub for nine months.

I haven’t touched Python in years, but it looks like a relatively uncomplicated program that logs into Dexcom with my credentials and receives the data. The only thing I can think of is that the connection needs to be refreshed more often.

I don’t know, you’ll have to try it. If Node red is an add-on I would not expect it to restart, but I don’t know how gracefully it handles home assistant core restarts.

Better yet, perhaps some super kind developer (or you?) could make a new integration that uses the dexcom api. That could be a lot of work, but given that it’s health related someone might be a little more inclined to volunteer.

Given that the integration requires the dexcom share feature, I am assuming that it is not using the API, but I very well may be wrong.

I wouldn’t want any effort to be made unless other users are experiencing the same problem. I was just looking for the easiest way to hide my symptoms.

Use following automation:

automation:
- alias: Restart Dexcom on startup
  trigger:
  - event: start
    platform: homeassistant
  action:
  - service: hassio.addon_stdin
    data:
      addon: name_of_your_addon
      input: restore-sensor
  mode: single

or use time trigger:

  - trigger:
    - platform: time
      # Military time format. This trigger will fire at 3:32 PM
      at: "15:32:00"
3 Likes

Thanks, but it always starts properly on HA startup. Also, it isn’t an add-on, it’s an integration.

2 Likes

Read : Add service integration.reload similar to above only using rest_command

Thanks for the link, but my Home Assistant developer tools do not include “integration.reload”. The thread you pointed to is a feature request from about a dozen (plus one, now) users.

Actually post #37 of that thread shows an example for reloading integrations via the HA rest api. In this case the Ikea Tradfri integration. It’s not very elegant, but it should work with any other integration as well.

I don’t understand all this Rest API stuff. I, too, want to automate reloading a couple of my integrations (for me, it’s Meross and Logitech Harmony). Is it reasonable to expect this to appear in a future HA update?

1 Like

Likewise. I bought a 3rd meross smart plug and now all 3 of them become unavailable multiple times a day

2 Likes

Agreed, I’m in the same boat and am very frustrated with the TP-Link integration. I have to reload it multiple times a day and of course, the devices I need are never available (via HA) when I need it. An automation to do this would be greatly appreciated.

2 Likes

Where is your issue on github? Things don’t get fixed by reloading integrations. They get fixed by posting proper bug reports.

Well, not sure if always. My example: I have an air conditioning devices integrated with HA via KNX. For longer periods of inactivity I switch power off completely from those AC units (by Shelly 1PM) so I don’t waste energy as they use ~20W while being idle. After a longer power off the KNX is not able to pick it up when turned on back again - is that a bug in KNX integration I should raise to be fixed or rather an expected behavior that a simple KNX integration reload fixes nicely?

That sounds like a bug.

Hi, Have a similar problem with a Samsung TV integration on a older Samsung TV. The manual reload works, however annoying.
I have made a automation activated when the entity goes unavailable. I use the “Home Assistant Core Integration: Reload config entry” service with the unresponsive entity.

alias: Samsung, Stue, reload TV
description: ''
trigger:
  - platform: state
    entity_id: media_player.samsung_65
    to: unavailable
condition: []
action:
  - service: homeassistant.reload_config_entry
    target:
      entity_id: media_player.samsung_65
mode: single
36 Likes

I’ve tried doing this with a Rest command and a curl script and cannot get it to reload an integration. I’ve does the whole Long lived access token and everything. But it still takes me to manually click reload in the UI before it reloads properly. In my case it’s Eufy Security. If anyone has any ideas, I’m all ears!

Thank you for this. I will try the same with my entities that become unavailable.

While this does not fix the bug with the integration, at least it makes it easier than manually reloading it.

I will also create a bug for the integration, if there is none.

I found this thread when looking for a fix for my Meross dimmer as well. Have you narrowed down what’s causing the integration to stop working? I haven’t had a chance to test my theory yet, but I’m wondering if it’s related to my internet access going down briefly (which happens at my house fairly regularly for anywhere from 5 seconds, to a few minutes at a time, unfortunately due to the type of internet service I have in my area).

I planned on setting up an automation that triggers an integration reload any time my internet access goes down (which I already monitor with ping sensors).

1 Like