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

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…

yeah, but from your log, you have a problem with your script. Seems to me like the script fires, doesn’t complete, so it never gets to the automation.turn_off

try leaving your script out of it for testing.

@flamingm0e is right. From the error is in the script

Unfortunately neither works:

   - id: 'testoff'
      trigger:
        - platform: time
          at: '16:10:00'
      action:
    #    - service: script.turn_on
    #      entity_id: script.hue_w_gedimmt_1
        - service: homeassistant.turn_off
          entity_id: automation.bewegung_w


- id: 'testoff'
  trigger:
    - platform: time
      at: '16:13:00'
  action:
#    - service: script.turn_on
#      entity_id: script.hue_w_gedimmt_1
    - service: automation.turn_off
      entity_id: automation.bewegung_w

You have something else going on.

I use the automation turn off/on every day. When my wife and I leave, it arms the door and window sensors automation notifications that I have set up.

It works 100% every day.

Did you found a solution for this? I am struggeling with the same problem. Everything in a list of actions is working except the automation.turn_on/off… :frowning:

I use homeassistant.turn_x all the time, and it works fine. for example:

initial_state: 'on'
alias: 'Dark TV on'
trigger:
  ...
action:
  ...
  - service: homeassistant.turn_on
    entity_id: automation.lounge_in_daylight_2

If it’s not working for you, then the chances are you’ve got an error in your automation - please share it.

Okay, found my misstake, i used the wrong entity_id.

Test Automation to turn on/off:

- id: 'TestAutomation01'
  alias: Test-Automation 01

NOT working:

- service: automation.turn_on
  entity_id: automation.TestAutomation01

NOT working:

- service: automation.turn_on
  entity_id: 'automation.Test-Automation 01'

WORKING:

- service: automation.turn_on
  entity_id: automation.TestAutomation_01
1 Like

No, I did not find a solution so far.

It would be extremely nice if HA would provide specific hints what’s wrong…

try to add directly automation on frontend (lovelace is mine, it works

  • automation.name

or under switch ,

  • platform: template
    switches:
    automation_onof_name:
    value_template: “{{ is_state(‘automation.name’, ‘on’) }}”
    turn_on:
    service: automation.turn_on
    entity_id: automation.name
    turn_off:
    service: automation.turn_off
    entity_id: automation.name

Thanks tayfunulu,

A cold restart of my Pi solved the issue!

A post was split to a new topic: Switch off one automation

In my Hass.io, the service

automation.turn_off

will turn off my automation but will not stop the execution until it completes. Once turned off, it won’t run until turned on again.

Sure, turning an automation off means it won’t trigger anymore. If it already has been triggered and is still running you should be able to use homeassistant.turn_off to cancel the running automation.

See this for how to abort a running automation.

Thanks @cgtobi

I did see that post but it didn’t work for me running Hass.io 88.1. Like you said, I can turn off the automation and it won’t run again until it is turned on again. But it failed to stop it’s execution or abort in the middle of the sequence.

You might add a couple of conditions into your action part, that way you can check states of whatever might interrupt your automation.