Will this automation work?

Never called a script in an automation. Is below ok?

# Covers Up IF Alarm disarmed with above automation ****************************
- id: Cover Up
  alias: Cover Up when alarm disarmed
  trigger:
    platform: time
    at: '07:28:00'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: alarm_control_panel.mqtt_alarm
        state: "disarmed"
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
  action:
    - service: script.turn_on
    - service: script.open_cover
      entity_id: cover.50758014840d8e918632 
    - delay:
        seconds: 60
    - service: script.turn_on        
    - service: script.open_cover
      entity_id: cover.50758014840d8e91eaa2
    - delay:
        seconds: 60
    - service: script.turn_on     
    - service: script.open_cover
      entity_id: cover.50758014840d8e91f036
    - delay:
        seconds: 60
    - service: script.turn_on     
    - service: script.open_cover
      entity_id: cover.50758014840d8e91f4fd 

script

      
open_cover:
  sequence:
  - condition: template
    value_template: "{{ states(entity_id) in ['close', 'unknown'] }}"
  - service: cover.open_cover
    data_template:
      entity_id: "{{ entity_id }}"

Try it out?

1 Like

yes, just did.

Cover Up when alarm disarmed: Error executing script. Invalid data for call_service at pos 1: must contain at least one of entity_id, area_id.
Logger: homeassistant.components.automation.cover_up
Source: core.py:1269
Integration: Automation (documentation, issues)
First occurred: 10:51:09 PM (1 occurrences)
Last logged: 10:51:09 PM

While executing automation automation.cover_up
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 128, in validate
    raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
voluptuous.error.Invalid: must contain at least one of entity_id, area_id.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 426, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 944, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 198, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 206, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 416, in _async_call_service_step
    await self._async_run_long_action(service_task)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 375, in _async_run_long_action
    long_task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1269, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 208, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 287, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 283, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 276, in __call__
    raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: must contain at least one of entity_id, area_id.

You have way too many hyphens in your action, so youā€™re calling the service ā€˜script.turn_onā€™ with no service data. Even without the hyphens youā€™re not passing the data to the script correctly.

See hereā€¦

Also the _template is unneeded now.

Thanks, to difficult for me for my first script.
I rewrote it like this, but can I not test right now because my family is sleeping.
Hopefully it will work tomorrow

# Covers Up IF Alarm disarmed with above automation ****************************
- id: Cover Up
  alias: Covers Up if alarm disarmed
  trigger:
    platform: time
    at: '07:28:00'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: alarm_control_panel.mqtt_alarm
        state: "disarmed"
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
  action:
  #
    - condition: state
      entity_id: cover.50758014840d8e918632
      state: "close"
    - condition: state
      entity_id: cover.50758014840d8e918632
      state: "unknow"
    - service: cover.open_cover
      entity_id: cover.50758014840d8e918632
    - delay:
        seconds: 60
  #
    - condition: state
      entity_id: cover.50758014840d8e91eaa2
      state: "close"
    - condition: state
      entity_id: cover.50758014840d8e91eaa2
      state: "unknow"
    - service: cover.open_cover
      entity_id: cover.50758014840d8e91eaa2
    - delay:
        seconds: 60
  #
    - condition: state
      entity_id: cover.50758014840d8e91f036
      state: "close"
    - condition: state
      entity_id: cover.50758014840d8e91f036
      state: "unknow"
    - service: cover.open_cover
      entity_id: cover.50758014840d8e91f036
    - delay:
        seconds: 60
  #
    - condition: state
      entity_id: cover.50758014840d8e91f4fd
      state: "close"
    - condition: state
      entity_id: cover.50758014840d8e91f4fd
      state: "unknow"
    - service: cover.open_cover
      entity_id: cover.50758014840d8e91f4fd

Thatā€™s not going to work. As soon as one condition fails all the actions are aborted.

Try the choose action. https://www.home-assistant.io/docs/scripts/#choose-a-group-of-actions

I will try it tomorrow. I think in my case I must go
with ā€œifā€, ā€œelifā€ and ā€œelseā€
but I am not sure what to do in the ā€œelseā€
I mean
if cover=close then open
elif cover = unknown then open
else = ?

Or you could just fix your automation and script based on the script syntax requirements detailed on the page I linked to earlierā€¦

- id: Cover Up
  alias: Cover Up when alarm disarmed
  trigger:
    platform: time
    at: '07:28:00'
  condition:
    - condition: state
      entity_id: alarm_control_panel.mqtt_alarm
      state: "disarmed"
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
  action:
    - service: script.open_cover
      data:
        blind: cover.50758014840d8e918632 
    - delay:
        seconds: 60
    - service: script.open_cover
      data:
        blind: cover.50758014840d8e91eaa2
    - delay:
        seconds: 60
    - service: script.open_cover
      data:
        blind: cover.50758014840d8e91f036
    - delay:
        seconds: 60
    - service: script.open_cover
      data:
        blind: cover.50758014840d8e91f4fd 
open_cover:
  sequence:
    - condition: template
      value_template: "{{ states(blind) in ['close', 'unknown'] }}"
    - service: cover.open_cover
      data_template:
        entity_id: "{{ blind }}"
1 Like

I never could have come up with a solution like this. I will test it tomorrow morning
Thanks

You did come up with the solution (all Iā€™ve done is edit your post), you just didnā€™t write it in the required way.

Also, double check the condition template in the script, should it not be ā€˜closedā€™ rather than ā€˜closeā€™?

1 Like