Add service integration.reload

+1 - this would be a great function

2 Likes

I have the same problem
The xiaomi integration become disconnected after 2 hours

1 Like

Hi all, the same for me.
I have 2 Xiaomi gateway: one of them is disconnected from home assistant after a couple of hours. I can reload this integration manually through UI.
The other one is always connected.
Can you help me write down an automatic reload of integration every 2 hours?
The @Mariusthvdb integration.reload didn’t work
Thanks

That’s because it doesn’t exist… hence the feature request :wink:

@Mariusthvdb I had a lot to looking for :rofl:

To reset the IKEA connection automatically, I’m using this in an automation:

- alias: "Keep IKEA running" 
  mode: single
  description: 'Check IKEA HUB down'
  trigger:
  - platform: state
    entity_id: switch.kerstverlichting # use any entity that is an IKEA device 
    to: unavailable
    for: 00:05:00
  condition: []
  action:
  - service: rest_command.reload_ikea
    data: {}

An this in the configuration.yaml

rest_command:
  reload_ikea:
    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'

IP: is your home assistant IP
Config Entry: is the unique config entry for your Tradfri and can be found in your directory config/.storage/core.config_entries. Search for Tradfri and use code Identity
Long-Lived Access Token can be created in the HA menu under your instance name

21 Likes

that would be very nice, but unfortunately I can not get it to work, keep getting the client error. using either http or https.

also tried the https://homeassistant:8123 variant, which works fine in rest sensors, same error though.

rest_command:
  reload_ikea:
    url: http://192.168.1.71:8123/api/config/config_entries/entry/00identity3c7edc4ff/reload
    method: POST
    headers:
      authorization: !secret api_bearer_token
      content-type: application/json

identity as found in:

            {
                "entry_id": "377entry_id951",
                "version": 1,
                "domain": "tradfri",
                "title": "192.168.1.99",
                "data": {
                    "gateway_id": "7Gatewayherea2",
                    "host": "192.168.1.99",
                    "identity": "00identity3c7edc4ff", ##<<-----------
                    "import_groups": false,
                    "key": "IJMTKEYHEREH"
                },
                "options": {},
                "system_options": {
                    "disable_new_entities": false
                },
                "source": "zeroconf",
                "connection_class": "unknown",
                "unique_id": "66:UN:iQ:UE:ID:6D"
            },

BIG +1 from me :+1:
would be great to have this service available

1 Like

Make sure this secret does not only contain the config entry that you have looked up, but also the wordt ’ Bearer’. Maybe it is already correct in your secret file, but I made the mistake myself before.

An example in het REST call would be:
authorization: 'Bearer xxxxxxxxxxxxxx’, where x is your code

yes, it does, I use it for many other rest sensors too. Also I have tried it with the full token in the config, with the same result.

but wait, what do you say now:

? it should not contain the config entry shouldn’t it, it should contain the bearer token…?

Sorry, my bad. Of course the bearer token. But also the word bearer in front of it.

ok no worries, and yes, I have Bearer included

shell_command:
  shark_restart: "/usr/bin/curl -X 'POST' -H 'authorization: Bearer <token>' http://localhost:8123/api/config/config_entries/entry/b11d6ff3d1b17655fcba7649d1703d70/reload"
alias: SharkIQ
description: ''
trigger:
  - platform: state
    entity_id: vacuum.baby_shark
    to: unavailable
    for: '00:05:00'
condition: []
action:
  - service: shell_command.shark_restart
    data: {}
mode: single

Does the job for me (where <token> is long lived token I’ve generated in profile section)

6 Likes

@dmatora: any ideas what I am doing wrong as this is not working? I would guess it has to do with my https URL or the fact that I am on Ubuntu with a supervised install? Thanks.

shell_command:
  shark_restart: "/usr/bin/curl -X 'POST' -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhNhNTU5Mjg5OSIsImlhdCI6MTYxMDM5MDcyMywiZXhwIjoxOTI1NzUwNzIzfQ.51pmUUiCAuYLNuIKVRrYVZ2bVBsd7eijkbfPhEPO3jY' https://192.168.1.57:8123/api/config/config_entries/entry/fbf820a4e4e76b9fa/reload"

All codes have been replaced by dummy ones.

I would suggest to install ssh addon, run your command in terminal in sidebar and see what is it complaining about. Otherwise I would try

  1. replacing https with http
  2. replacing 192.168.1.57 with localhost
  3. make sure you are using long lived token you’ve generated in profile section
  4. make sure you are using correct integration id (capture it using chrome inspector while reloading your integration from gui)
1 Like

how exactly do we do that?

Click Reload on integration settings while checking Network tab on Chrome inspector

1 Like

thx, so reloading IKEA Tradfri results in this:

what does that teach me on the integration id to use in the shell_command?

Click on network request line and check request url

thanks, though still somewhat confused because I dont see a ‘network request line’, a column called ‘Name’ is displayed, in which a line ‘reload’ appears upon reloading…
clicking reload, makes the right field show General, Response headers, and Request headers. Under General, I can see the Request URL, under Response headers the content-type is shown, and under Request Headers the authorization is displayed.

Which makes it possible indeed to collect all necessary field for the rest_command:

rest_command:
  reload_ikea:
    url: https://mydomain.duckdns.org:port/api/config/config_entries/entry/3770284redacted51/reload
    method: POST
    headers:
      authorization: !secret api_bearer_token
      content-type: application/json

Also, the post by @Henk72 contains 1 significant typo, that caused my mishaps unto now :blush:

the [Config Entry] should be the data in the top line, ‘entry_id’ field in the config/.storage/core.config_entries and not the Identity field.

thanks!

update

to make it a bit more flexible, I use a template in the rest_command url (stored in secrets) and an input_select:

  select_integration:
    name: 'Select Integration:'
    options:
      - Gdacs
      - Ikea
      - Ipp
      - Life360
      - Luftdaten Rotterdam P
      - Luftdaten Rotterdam T
      - Luftdaten Tilburg P
      - Luftdaten Tilburg T
      - Owntracks
      - Philips Hue 1
      - Philips Hue 2
      - Plugwise
      - Plex
      - Synology Dsm
      - Weatherbit
    initial: Weatherbit

and:

script:
  reload_integration:
    alias: Reload integration
    mode: restart
    sequence:
      service: rest_command.reload_integration
      data:
        entry_id: >
          {% set mapper =
            {'Gdacs':'058redacted18a',
             'Ikea':'37redacted1951',
             'Ipp':'99redacted716',
             'Life360':'2aredactede7c',
             'Luftdaten Rotterdam P':'c6aredacted1',
             'Luftdaten Rotterdam T':'01redacted12e',
             'Luftdaten Tilburg P':'9redacted09c',
             'Luftdaten Tilburg T':'85redacted1bf8',
             'Owntracks':'6b2042redacted22a',
             'Philips Hue 1':'7afbredactedc5',
             'Philips Hue 2':'aredacted31e',
             'Plugwise':'474redacted412',
             'Plex':'dd13e18redacted4e05',
             'Synology Dsm':'fd8redacted367',
             'Weatherbit':'79aredacted5c'} %}
          {% set state = states('input_select.select_integration') %}
          {% set id = mapper[state] if state in mapper %}
          {{id}}

rest_command:
  reload_integration:
    url: !secret reload_integration_url #https://mydomain.duckdns.org:port/api/config/config_entries/entry/37redacted1951/reload
    method: POST
    headers:
      authorization: !secret api_bearer_token
      content-type: application/json
    payload: >
      {{entry_id}}

in secrets, have the url be:

reload_integration_url: https://mydomain.org:port/api/config/config_entries/entry/{{entry_id}}/reload

Lovelace:

    input_select.select_integration:
      templates:
        entity_picture: >
          var path = '/local/images/integrations/';
          return state.includes('Luftdaten')
                 ? path + 'luftdaten.png'
                 : state.includes('Philips') ? path + 'hue.png'
                 : path + state.toLowerCase() + '.png';

only thing is I dont see a confirmation box yet, so not sure if everything works :wink: no errors either :wink:

update
can confirm the above setup to work meanwhile, so for the time being this will do.

12 Likes