Restart / Reload HA with bookmarklet

Small project share:

Wanted to skip the hassle of visiting the path steps config -> server control -> reload every time :slight_smile:
So I made a HA Webhook with the reload and restart service of HA and called this with JavaScript inside a browser bookmark that is sitting in the browser bookmark bar right above my HA page.

Webhooks config in “automations”:

- alias: Reload automations
  initial_state: 'on'
  trigger:
    platform: webhook
    webhook_id: 'reload-automations'
  action:
  - service: automation.reload

- alias: Restart Homeassistant
  initial_state: 'on'
  trigger:
    platform: webhook
    webhook_id: 'restart-homeassistant'
  action:
  - service: homeassistant.restart

Bookmark code (not usable):

(function() {
  fetch('http://homeassistant.local:8123/api/webhook/reload-automations', {
    method: 'POST'
  })
  .catch((error) => {
    alert(error);
  });
}());

Bookmark code (usable)
note: javascript: is importend to add

javascript:(function()%7B(function()%20%7Bfetch('http%3A%2F%2Fhomeassistant.local%3A8123%2Fapi%2Fwebhook%2Freload-automations'%2C%20%7Bmethod%3A%20'POST'%7D).catch((error)%20%3D%3E%20%7Balert(error)%3B%7D)%3B%7D())%7D)()

You can replace an existing bookmark-url with above code and rename the url in above encoded code with appropriate url.

3 Likes

this is really cool. thank you. do you know the script to run it externally?
I replaced homeassistant.local with my corresponding https, but it says error “fetch”

thank you.

Thx @juan11perez.

I think this only runs when you have the home assistant webpage active. But it should also work with https. Is that the problem?

If you’re asking if this will run when you are not on homeassistant.local, then the anser is: “it doesn’t”. Then you need a Server Side script that does a post call to the Webhook url (not clientSide like this JavaScript). But then you can also use the homeassistant API without a webhook.

Thank you. I was wondering if it worked while out of my network, when I’m logged in via https.