Add service integration.reload

I’m trying to reload my Shark IQ integration automatically and I’m having issues as well.Hoping someone can help me…

Here’s my shell script:

shell_command:
  shark_restart: "/usr/bin/curl -X 'POST' -H 'authorization: Bearer <token>' http://10.107.112.240:8123/api/config/config_entries/entry/dbcb446bd8800e799abeb5ad0a0eec38/reload"
 

where is a long lived access token I generated and this is my automation

alias: Shark IQ - Upstairs
description: Restarts the Shark IQ Integration if the Upstairs Shark Is Unresponsive
trigger:
  - platform: state
    entity_id:
      - vacuum.r5_d_floor
    to: unavailable
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - service: shell_command.shark_restart
    data: {}
mode: single

Then when I run the automation I see the following in the logs:

Logger: homeassistant.components.http.ban
Source: components/http/ban.py:125
Integration: HTTP (documentation, issues)
First occurred: 8:35:20 AM (3 occurrences)
Last logged: 8:44:25 AM

Login attempt or request with invalid authentication from localhost (127.0.0.1). (curl/7.79.1)

It seems like it does not like my token for some reason but I did create it so I’m not sure what’s going on. Maybe there’s something obvious the group can see that I cannot?

EDIT: Now that I’ve played with this a bit more… the trigger doesn’t appear to be working for some reason. This automation seems to work fine if I manually run it, but the trigger doesn’t appear to fire… so something is a bit off.

You shouldn’t need an access token. If you just use the reload config command from HA, it works by specifying the associated devices/entities.

Here’s what I just got working for my Shark vacuum based on input from others above.

id: '1659564071500'
alias: Reload Shark Integration If Unavailable
description: ''
trigger:
  - platform: state
    entity_id:
      - vacuum.sharkbait
    to: Unavailable
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      device_id: 3f155d4bd130b7d171b9545ac98205a0
mode: single

Note, I created this through the UI in HA, so it just looked up the device ID for me.

trigger:
  - platform: state
    entity_id:
      - vacuum.sharkbait
    to: unavailable #<-- case matters
    for:
      hours: 0
      minutes: 5
      seconds: 0

Thanks, I wondered about that too, but it’s odd to me that the front end shows it as “Unavailable”. I updated the casing to lowercase. I’ll watch it and see how it performs now.

It really is odd that it’s uppercase on the front-end but lowercase on the back-end.

It’s called separation of concerns: internal state and display should be handled separately. Simple case: The internal state for a weather condition could be sunny, but if you set your language to some non-English language, you’d want that translated. Same for unavailable. In fact, an internal state doesn’t even need to be text. Could well be that it’s just a number or ID. So, in the end, a state trigger works by using the internal state, and not how it’s displayed.

you should be able to use that integration entity itself, and not have to find the config_entry numbers.

check it in the dev tools and you’ll see that works

than adapt the automation to simply use the same entity you use in the trigger. trigger.entity_id :wink:

the service will find the correct config_entry automagically

If I have a pure yaml-configured integration. Can I reload the whole integration as well somehow?

Shouldn’t matter if it’s yaml or not. You should still be able to use the reload config entry code like I did above.

Edit: Apologies, I misunderstood when I replied… ignore my response.

Either I’m doing it wrong or it is not working.

Need: I want to reload the Powercalc-Integration (because I have changed the config, added something or whatever.

Then you say I can take a random already generated entity and put it in the service-call?

  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: sensor.fritz_repeater_power

is then throwing Unexpected error for call_service at pos 1: There were no matching config entries to reload

If I use

  - service: homeassistant.reload_config_entry
    data:
      entry_id: xxxxxxxxxxxxxxxxxxxxxxxx

because I have

      {
        "area_id": null,
        "capabilities": {
          "state_class": "measurement"
        },
        "config_entry_id": null,
        "device_class": null,
        "device_id": null,
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "sensor.fritz_repeater_power",
        "hidden_by": null,
        "icon": null,
        "id": "xxxxxxxxxxxxxxxxxxxxxxxx",
        "has_entity_name": false,
        "name": null,
        "options": {},
        "original_device_class": "power",
        "original_icon": null,
        "original_name": "Fritz Repeater POWER",
        "platform": "powercalc",
        "supported_features": 0,
        "unique_id": "unique_id_powercalc_fritz_repeater_power",
        "unit_of_measurement": "W"
      },

for this entity in the entity_registry, then I get Error handling message: Unknown error (unknown_error). Same If I use the entity_id in data.

This only works for integrations with a config_entry. (Setup via config flow)

In my setup, that is not happening for Powercalc…

And why then the answer

If I ask exactly this?

Just checked and it is available for Config flow.

Needs a lot of rework in my config… a lot.
But it is possible :wink:

No. For integrations that are purely in YAML and do not create a config entry on startup this service does nothing.

It also won’t work for integrations that are configured in YAML but create a config entry (at least not hte way you want it to). There are some integrations that do this. But when they do that they use your YAML config to define the config entry on startup. So like if you set a url field in the YAML then there’s probably a corresponding url field in the config entry.

For integrations like this when you call homeassistant.reload_config_entry it sets up the integration all over again starting from the config entry. But it won’t do the extra step it does at startup where it reads in your YAML and uses that to define the config entry. It doesn’t look at your YAML at all.

When it comes to YAML configuration, the things listed on Developer Tools → YAML are the only things that support reloading your YAML without a restart. For everything else you must restart HA.

4 Likes

I misunderstood the question. Sorry about that. I assumed it was still creating a config entry, just doing the configuration via YAML.

Thanks for that. It’s a pity, but at least I can stop my playing and trying around.

Technically, I don’t understand, why the yaml could not be reloaded and partially re-parsed for such integrations, but most probably only, because no one has implemented it. :joy:

1 Like

Thanks for this, Sky - Just what I needed for the LG integration that looses Ice+ control.

No problem, there is now actually an easier way to reload integration, you can just call a service with one of the entities that the integration is using. For example

service: homeassistant.reload_config_entry
data: {}
target:
  entity_id:
    - climate.kantoor
10 Likes

That I need to do an automation with a script, the problem is that since 2022.8 the Switchbot bot doesn’t work without reload the bluetooth integration in my RPi4, but the bluetooth integration doesn’t have any entity in there…so I have to reload with the older one method below?

Do you know the bluetooth id integration?

Thanks in advance

It exist already and I used it. It works. I had a Huawei LTE dropping integration which I keep up with this reload.

Check this:

Follow the link at solved by Frenck.

3 Likes

config/.storage/core.config_entries no longer seems to exist, but you can get the url by opening your browser development tools and watching the network tab while manually performing the reload you want. If there’s a “proper” way, I couldn’t find it, and this way is pretty easy.