How to switch an Automation on/off with an automation?

Hello there,

how may I switch an automation on/off with an automation?

- service: switch.turn_off
  entity_id: switch.testswitch

So what I want to do is:

- service: automation.turn_off
  entity_id: automation.testautomation

…and that won’t work. Why?

Thanks
mny

Try

- service: homeassistant.turn_off

2 Likes

Hm,

- service: homeassistant.turn_off
  entity_id: automation.testautomation

does not work and

- service: homeassistant.turn_off
  entity_id: switch.testautomation

won’t work either…

Can you post the entire automation?

This is my automation:

   w_off:
      sequence:
        - service: light.turn_off
          entity_id: group.wohnzimmer
        - service: homeassistant.turn_off
          entity_id: automation.testautomation

The lights will turn off, but in HA the switch of automation ‘testautomation’ stays on…

That is a script, not an automation… The spacing is wrong before sequence, it has three spaces and should have only two. Apart from that I can’t see anything wrong.

Please post the automation testautomation

Thanks for looking into that topic!

  • The spacing is correct (2 spaces). In my message it’s displayed as 3 spaces, I don’t know why.

  • The content of the automation shouldn’t be of importance here since I just want to trigger the switch of the automation in HA. Here is the automation anyway (all spaces correct), it works perfectly:

    • id: testautomation
      initial_state: ‘on’
      trigger:
      • platform: state
        entity_id: binary_sensor.fibaro_motion_sensor
        from: ‘off’
        to: ‘on’
        action:
      • service: script.turn_on
        entity_id: script.w_on

When you activate the script and the light turns off, do you see the automation switch turn off and back on or does it stay on?

It stays on, no movement at all.

For what i can see on the forums and on the docs, it is possible to turn on/off an automation from an automation. But i don’t see nothing saying that you can do it from a script…

I think that your best bet is to create an automation that turns off testautomation (for example testautomation_off) and then call it from the script, like this:

w_off:
  sequence:
    - service: light.turn_off
      entity_id: group.wohnzimmer
    - service: automation.trigger
      entity_id: automation.testautomation_off

I do this inside an automation. I don’t use a script/sequence for it.

action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.parentshome
  - service: automation.turn_on
    entity_id: automation.doors
  - service: automation.turn_on
    entity_id: automation.windows
  - service: notify.HomeNinjaBot
    data:
      message: 'Parentals are gone. Arming Windows and Doors.'

I tested this automation:

  • id: ‘testoff’
    trigger:
    • platform: time
      at: ‘15:43:30’
      action:
    • service: script.turn_on
      entity_id: script.hue_w_gedimmt_1
    • service: automation.turn_off
      entity_id: automation.bewegung_w

The light gets dimmed but no movement in the switch.

It’s difficult to see if the code is correct or not if you don’t use </> when posting…

I’m sorry:

- id: 'testoff'
  trigger:
    - platform: time
      at: '15:43:30'
  action:
    - service: script.turn_on
      entity_id: script.hue_w_gedimmt_1
    - service: automation.turn_off
      entity_id: automation.bewegung_w

Try:

- id: 'testoff'
  trigger:
    - platform: time
      at: '15:43:30'
  action:
    - service: script.turn_on
      entity_id: script.hue_w_gedimmt_1
    - service: homeassistant.turn_off
      entity_id: automation.bewegung_w

Light gets dimmed but no movement at the switch

This is in my log:

2018-01-13 16:00:35 ERROR (MainThread) [homeassistant.core] Invalid service data for script.turn_on: Entity ID is an invalid entity id for dictionary value @ data[‘entity_id’]. Got ‘’
2018-01-13 16:00:41 ERROR (MainThread) [homeassistant.core] Invalid service data for script.turn_on: Entity ID is an invalid entity id for dictionary value @ data[‘entity_id’]. Got ‘’

you can use automation.turn_on/off homeassistant.turn_on/off is not required.

Neither of them works…