Automation to turn off and turn integration

I have looked and tried everything but I am not able to get Integration to be turned off by automation.

When I click Settings->Devices & services, I see installed integrations like below.

I click Frigate, for example, and I see the one below.

I click three dots on the top right and I see “Disable” as below.

When I click “Disable”, Frigate is disabled and there is no more live feed on lovelace.

I want do this “Disable” with automation.

For example, I want to “disable” Frigate at 1:00AM by automation as if I clicked “Disable” from the menu shown above at 1:00AM so I get no live feed on lovelace.

Is this possible?

In automation, I tried “Call service” (now “Perform action”) and “integration.disable” as suggested by google. I cannot find “integration.disable” under “Perform action”.

I tried other suggestions by google but I still cannot get Frigate to stop by automation.

Any help would be appreciated.

You cannot trust AI to give you sane answers about HA. The Spook integration adds the functionality you seek:

1 Like

Thank you. I try Spook.

I’m using this automation with Spook to enable/disable an integration based on the state of the plug that powers a printer:

alias: Integration - En/DisAble for Printer
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.plug_6
    from: "off"
    to: "on"
    id: enable
  - trigger: state
    entity_id:
      - switch.lug_6
    from: "on"
    to: "off"
    id: disable
conditions: []
actions:
  - action: homeassistant.{{ trigger.id }}_config_entry
    data:
      config_entry_id: 98377f1234567f4bb2092ce331bd41adaa
mode: single

The tricky bit is to find the config_entry_id :stuck_out_tongue:

I’ve done this by going to the Developer Tools, select the UI Mode, type in ‘homeassistant.disable_config_entry’ as the action and select the device from the dropdown menu.

Once you’ve done this, switch to YAML Mode and you’ll see the config_entry_id here:

action: homeassistant.disable_config_entry
data:
  config_entry_id: 98377f1234567f4bb2092ce331bd41adaa

Or you use

config_entry_id: "{{ config_entry_id('some entity id provided by the integration you want to disable') }}"
1 Like

That one seems like it could solve a problem for me. I would like to deactivate some Scrape sensors, and from your code I thought this would work. The trigger is from an MQTT message, with payloads from 1-9.

action: homeassistant.enable_config_entry
metadata: {}
data:
  config_entry_id: |-
    {{ config_entry_id('media_player.foobarsone
    {{
    trigger.payload}}_artist') }}

But nothing happens, and I get this in the logger. The problem is that I can’t see from the logger what it actually tries to execute, I think. So I don’t know if something is missing or wrong. Do you have any idea what’s wrong here?

Logger: homeassistant.components.automation.aktivere_scrape_sensorer_og_foobar_integrasjon_nar_foobar_starter
Kilde: components/automation/__init__.py:717
integrasjon: Automasjon (dokumentasjon, problemer)
Første forekomst: 12:30:41 (1 occurrence)
Sist logget: 12:30:41

While executing automation automation.aktivere_scrape_sensorer_og_foobar_integrasjon_nar_foobar_starter
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 717, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        variables, trigger_context, started_action
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1833, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 556, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 524, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1009, in _async_step_call_service
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2816, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2859, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 939, in _async_admin_handler
    return await task
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/__init__.py", line 344, in async_handle_reload_config_entry
    raise ValueError("There were no matching config entries to reload")
ValueError: There were no matching config entries to reload

that template is broken, you are nesting templates.

Do this instead:

action: homeassistant.enable_config_entry
metadata: {}
data:
  config_entry_id: |-
    {{ config_entry_id('media_player.foobarsone' ~ trigger.payload ~ '_artist') }}

BTW, you can test your templates in Developer tools > Templates
Open your Home Assistant instance and show your template developer tools.

Thank you very much for the lightning quick answer! There is something still wonky there, because it doesn’t activate the integration, even if the error is gone. But I think maybe I can solve that if I understand how to use a trigger payload in Templates in Dev tools. Could you please tell me that? I have used that for lots of things, but I don’t know how to put in a trigger payload. I tried with trigger.payload == 9 as the first line in the Templates, but that of course did not work.

Edit: I may be closer, but still not there for something that works in Dev tools, Templates:

{% set test = 9 %}
"{{ config_entry_id('sensor.foobarsone_' ~ test ~ '_artist') }}"

use

{% set trigger = {"payload": 9} %}
{{ config_entry_id('media_player.foobarsone' ~ trigger.payload ~ '_artist') }}

alternatives:

{% set trigger = dict(payload=9) %}

or

{% set trigger = namespace(payload=9) %}

All result in trigger.payload returning 9

1 Like

Thank you very much! That worked, and I found the error. A simple, missing underscore. :joy:

1 Like

Sorry, one more question: How do I call the parent integration of this? To make it clear, the actual code was not media_player, but sensor for this one:

actions:
  - action: homeassistant.enable_config_entry
    metadata: {}
    data:
      config_entry_id: >-
        {{ config_entry_id('sensor.foobar_sone_' ~ trigger.payload ~ '_artist')
        }}

That gives me the config_entry_id of that. But for another part of the system I need the config_entry_id of media_player.foobarsone9. So I tried:

{{ config_entry_id('media_player.foobarsone' ~ trigger.payload ~ ) }}

And a bunch of other permutations, but of course I could not find the correct way…

Does it work if you use it without templates? So

{{ config_entry_id('sensor.foobarsone9' }}

BTW, you are using foobar_sone in the first template, but foobarsone in the 2nd. Could that be the issue?

The naming is different. But this doesn’t work either. Btw there is a missing end paranthesis in your code, but I tried with this:

{{ config_entry_id('media_player.foobarsone9') }}

And the result is null.

Edit: Wait a minute. Can this be because the Foobar integration is set up from configure.yaml, not from the GUI?

If this isn’t possible I can deactivate both the _artist and _title integrations, but I don’t know if it will still be sniffing for the parent integration and not find it because that zone is not playing radio.

Only integrations set up with the config flow have a config entry id.
You also won’t be able to use those actions on YAML integrations.

1 Like

Got it, thanks! Then I will disable the two sub-integrations and leave the main. I think that should be enough to stop it constantly polling.