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

That is not a core integration is it?

Unfortunately not, it’s a custom integration as the company does not officially support HA but the folks that built it aren’t particularly active either.

homeassistant.reload_config_entry

Yes, this is the right service to load the integration. I use it for UniFi integration that doesn’t load by itself after updating Home Assistant, and integration clients aren’t at home, which causes problems when people are at home.
Hopefully the automation will work properly .

alias: "Po Restartu Home Assistant "
description: |-
  provede po restartování HA
  - znovu načtení integrace UniFi
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: update.unifi_network_application_update
mode: single

2 Likes

Thank you, this was the solution to auto-recover my Tractive integration.

same here. Thanks for your thoughts!

Is there any way to reload UI integration i have problem in Tuya integration
I notes after reloaded it back working as normal,
thanks

Yes, call the service homeassistant.reload_config_entry

1 Like

thanks, but this for individual entity
Is there a way to Full reload the integration ?

Reloading the config for one entity also reloads the config for its integration

top Thanks for the info

This does not seem to work for Adax integration. Reloading it with target as one entity fails to bring the integration online if there is an issue. Yet, reloading it from the integrations page works, but this does not help with my automation. Is there anything I can do?

The trouble is that (as I understand it) this statement is not universally true for all integrations

The source may give some clues.

1 Like

Hi Stasharo,

Thanks for this script, I am getting these error would you please be able to assist?

3430 |
3431 | alias: Restart Tuya
----------^
3432 | description: ‘’
3433 | trigger:

I have resolved this with the following with a time based automation (Below)

Home Assistant 2023.5.2
Supervisor 2023.04.1
Operating System 10.1
Frontend 20230503.3 - latest

Name of Automation : Restart Tuya
Trigger:
Mode: fixed time
At time: 08:30 AM (set the time after the unit is on, or else it will not work)
Actions: Call Service
Service: Home Assistant Core Integration: Reload config entry
Entity: climate.rcdf (this is how I have mine, choose your appropriate one)

Hope this helps someone else.

3 Likes

Hi! How do you “auto-recover” the Tractive Integration, do you want to share your automation? :slight_smile:

Thanks

The key is service: homeassistant.reload_config_entry

2 Likes

@Snille

Would not recommend this one for Tractive, as this generated a lot of API calls and I have ended up limited by them, had to pause everything for at least a week, nevertheless you might be able to use this for other purposes or just to have an idea.

Basically checking for feature unavailability, with conditions like having network communication with router and DNS and my router was not restarted manually, then checking for HA restart with input booleans (those are updated at the time of HA shutdown or Startup)

Below is the automation from where I call a script:

alias: Auto-recover Tractive integration
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.maya_live_tracking
    to: unavailable
    for:
      hours: 0
      minutes: 3
      seconds: 0
  - platform: state
    entity_id:
      - switch.maya_live_tracking
    to: unknown
    for:
      hours: 0
      minutes: 3
      seconds: 0
  - platform: state
    entity_id:
      - switch.maya_tracker_led
    to: unavailable
    for:
      hours: 0
      minutes: 3
      seconds: 0
  - platform: state
    entity_id:
      - switch.maya_tracker_led
    to: unknown
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.192_168_69_1
    state: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - condition: state
    entity_id: binary_sensor.1_1_1_1
    for:
      hours: 0
      minutes: 5
      seconds: 0
    state: "on"
    enabled: true
  - condition: state
    entity_id: script.router_restart
    state: "off"
    for:
      hours: 0
      minutes: 5
      seconds: 0
    enabled: true
  - condition: state
    entity_id: input_boolean.ha_start
    state: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - condition: state
    entity_id: input_boolean.ha_stop
    state: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0
action:
  - parallel:
      - service: script.fix_tractive_integration
        data: {}
      - service: notify.mobile_app_xel_s23
        metadata: {}
        data:
          message: Tractive integration reloaded
          title: HA debug message
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
mode: single

And below the script being called, this device “xa3cs9fbf047b5b03f995867985709f6” is my Tractive tracker device id (changed some numbers in it before sharing to avoid funny business). The “activitylogger” part can be skipped, this is just a way for me to log activities and events on one of my dashboards.

alias: Fix Tractive integration
sequence:
  - parallel:
      - service: input_button.press
        data: {}
        target:
          entity_id: input_button.activitylogger
      - service: homeassistant.reload_config_entry
        data: {}
        target:
          device_id: xa3cs9fbf047b5b03f995867985709f6
        enabled: true
mode: single
icon: mdi:dog

I’m sure there are bettery ways to do this, but this is what I’ve come up with for my needs. I’m using the same logic to handle some of my other integrations which occasionally need restart, like Sonoff or Xiaomi Miot Auto and helps a lot to avoid manual effort.

Really appreciate you posting the YAML here. My Nexia integration for my new American Standard HVAC keeps dropping and needed a way to restart it. I was able to use the code here to hack something together.

alias: Reload Nexia when Unavailable
description: ""
trigger:
  - platform: state
    entity_id: sensor.system_####_humidity
    to: unavailable
condition: []
action:
  - service: homeassistant.reload_config_entry
    metadata: {}
    data: {}
    target:
      device_id:
        - ################################
        - ################################
mode: single

2 Likes

One of my integrations needs reloading every couple of days.

The following did not work:

service: homeassistant.reload_config_entry

Though maybe I messed something up (though I used the correct IP and integration ID), from here, this placed in configuration.yaml also did not work:

rest_command:
reload_myintegration:
url: http://[IP]:8123/api/config/config_entries/entry/[Config Entry]/reload
method: POST
headers:
authorization: 'Bearer [Long-Lived Access Token]’
content-type: ‘application/json’

But this worked: Create a token by clicking your name, Security tab, scrolling down to Long-lived access tokens and clicking create token. Insert that token in the code below [token]. Place the code in configuration.yaml and restart HA. You can rename “myintegration_restart” to the name of your integration(s).

shell_command:
myintegration_restart: “/usr/bin/curl -X ‘POST’ -H ‘authorization: Bearer [token]’ http://localhost:8123/api/config/config_entries/entry/[integration id]/reload”

Then in your automation:

actions:

  • data: {}
    action: shell_command.myintegration_restart
    enabled: true
1 Like