How to start/stop Add-ons via command in HA

I am new at Home Assistant. I installed Home Assistant OS on Raspberry. I want to start/stop Add-ons via the command
ha addons stop/start ADDON

Works fine at the command line. But how can I create a switch? I added the following to the configuration.yaml

switch:
  - platform: command_line
    switches:
      ADDON_switch:
        command_on: "ha addons start ADDON-NAME"
        command_off: "ha addons stop ADDON-NAME"
        friendly_name: ADD-ON Switch

Nothing happens. I think the “command_line” is wrong. How can I use HA command in Home Assistant for that?

Thanks for support!

1 Like

Do you have a supervised HA?
f.e.

service: hassio.addon_stop
data:
  addon: core_mosquitto

  • create an input_boolean (toggle) in helpers
  • create an automation using the helper switch

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - input_boolean.addon_toggle
    to: "on"
    id: swichted_on
  - platform: state
    entity_id:
      - input_boolean.addon_toggle
      - switch_off
    to: "off"
    id: swichted_off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: swichted_on
        sequence:
          - service: hassio.addon_start
            data:
              addon: core_mosquitto
      - conditions:
          - condition: trigger
            id: swichted_off
        sequence:
          - service: hassio.addon_stop
            data:
              addon: core_mosquitto
alias: start-stop-mqtt
5 Likes

Yes, I have supervised HA. Your solutions helps me a lot!

Thanks!

Now, as an followup question, can this be done for integrations (:weary: looking @ kodi integration)

Yes.

Find the appropriate ID in /config/.storage/core.config_entries, then do a (example ID here)

service: homeassistant.reload_config_entry
data:
  entry_id: 97092915b445e81b8483e2f304258e93
1 Like

What are you trying to achieve?
Maybe if you share your end goal it would be easier to help maybe with a different approach other than stopping Add-ons and integrations, which is odd.

The Kodi integration really slows down my HA startup (~2m) if the Kodi instance is not present while booting up. (Kodi is on my pc so if the exe is not running or the pc is off then I have an issue)

But there are several posts about it, I don’t want to hijack this thread :slight_smile:

Yes, you can reload ENTIRE integrations using @swa72’s script.

In order to get your entry_id, (at least this is what I did), view the latest backup that has the integration available (you may need to do a backup if this is a new integration).

  • Download the backup to your Desktop computer.
  • Open the Backup file (I use Winrar for my PC), and locate .\homeassistant.tar.gz (double-click this)
  • Then open the folder “data”
  • Then open the folder “.storage”
  • Locate the file “core.config_entries” and open it (choose “Notepad” as the program that reads it)
  • Do a search for the integration, and you’ll see the entity_id right above the integration name.

Finally, write a script using the template (copied from above post by @swa72 for convenience):

service: homeassistant.reload_config_entry
data:
  entry_id: 97092915b445e81b8483e2f304258e93

You can now run the script or even have this script run in an automation.

If your integration have an entity, you can try going to Developer Tools, Template tab and then type this (please replace the entity_id for the one you are looking for):

{{ device_attr(device_id('switch.kitchen_dishwasher_outlet'), 'config_entries') }}

You will also find this info under /config/.storage/core.config_entries, but that is a dangerous area so you should avoid going there.

2 Likes

I would’ve liked this to work, but when I try this I receive a list of 3-4 possible entry_ids. When I swap to a different entity some of the numbers from the first list remain. I have tested a number of entity and sometimes the correct entry id is listed in the last place, sometimes not.

I personally pulled the information from a backup file as I couldn’t get to this information any other way (this includes File Editor, Studio Code Server or Samba Share beforehand. So I think your way is pulling in additional numbers besides the entry_id? Or might all of these ids be needed to reload that device?

I did do some more digging and found the the way to pull only a single entry that corresponded to that entity (ie. light/switch rather than light/switch AND power consumption):

{{ config_entry_id('switch.kitchen_dishwasher_outlet') }}

I tested the above in Template tab of Developer Tools and matched the test results with my core.config_entries file (in my backup file of HA) of a light entry and they match.

Yeah, that can happen. 8ne device could have entities provided by different integrations, like whe a tuya wifi bulb have a device tracker from your router integration and a power entity from powercalc, as an example, all the 3 integrations would be shown.

Great!
Good catch!

But by the way, I’m pretty sure this will do the job in the same way:

service: homeassistant.reload_config_entry
data: {}
target:
  entity_id: switch.kitchen_dishwasher_outlet

HA is a team sport and we’re all here to learn with each other and improve :wink:

Very nice, I haven’t tried it on entities, but I know this won’t work for integrations. Still, it’s a great idea in creating an automation that would reload an entity that goes unavailable (I had issues with my Kasa smart switches going unavailable until I created an Asus aiMesh network - couldn’t get the Zigbee thing to work for the few Zigbee devices that I had, which had a constant stream of AC power)

1 Like