Repeat in automation not valid

Hi,

trying to use the new repeat feature in automation but coming across the below error when validating?

Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['repeat']['sequence'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['repeat']['sequence'][0]['message']. Got None
extra keys not allowed @ data['action'][0]['repeat']['sequence'][0]['target']. Got None
extra keys not allowed @ data['action'][0]['repeat']['sequence'][0]['title']. Got None. (See /root/.homeassistant/configuration.yaml, line 1680). 

this is the code I am using

- id: id_157
  alias: alexa notify on flood detection
  trigger:
  - platform: state
    entity_id: sensor.kitchen_flood_sensor_flood
    to: '2'
  - platform: state
    entity_id: sensor.master_bed_bath_flood_sensor_flood
    to: '2'
  - platform: state
    entity_id: sensor.water_tank_flood_sensor_flood
    to: '2'
  condition:
  action:
  - alias: Repeat the sequence UNTIL the conditions are true
    repeat:
       sequence:
         - service: notify.alexa_media
           data_template:
           target: 
            - media_player.living_room
            - media_player.kitchen_spot
            - media_player.hallway_dot
            - media_player.1st_floor
            - media_player.man_cave
            - media_player.master_bed
           title: "Flood Detected in the {{ trigger.to_state.attributes.friendly_name }}"
           message: >
            "Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}. Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}"
           data:
             type: announce
             method: all
         - delay:
           minutes: 2
           until:
            # Did it work?
           - condition: state
             entity_id: alert.master_bathroom_flood
             state: 'off'
           - condition: state
             entity_id: alert.kitchen_flood
             state: 'off'
           - condition: state
             entity_id: alert.water_tank_flood
             state: 'off'

You have some bugs… YAML is indentation-sensitive. (Not tested)

- id: id_157
  alias: alexa notify on flood detection
  trigger:
  - platform: state
    entity_id: sensor.kitchen_flood_sensor_flood
    to: '2'
  - platform: state
    entity_id: sensor.master_bed_bath_flood_sensor_flood
    to: '2'
  - platform: state
    entity_id: sensor.water_tank_flood_sensor_flood
    to: '2'
  condition:
  action:
  - alias: Repeat the sequence UNTIL the conditions are true
    repeat:
       until:
         - condition: state
           entity_id: alert.master_bathroom_flood
           state: 'off'
         - condition: state
           entity_id: alert.kitchen_flood
           state: 'off'
         - condition: state
           entity_id: alert.water_tank_flood
           state: 'off'
       sequence:
         - service: notify.alexa_media
           data_template:
             target: 
              - media_player.living_room
              - media_player.kitchen_spot
              - media_player.hallway_dot
              - media_player.1st_floor
              - media_player.man_cave
              - media_player.master_bed
             title: "Flood Detected in the {{ trigger.to_state.attributes.friendly_name }}"
             message: >
              "Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}. Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}"
             data:
               type: announce
               method: all

Great thanks that seems to pass validation. How to add the delay though? Thats missing from your revision?

Just add it to the repeat’s sequence section, after the other action.

Also I like to have “until” come after “sequence”. It doesn’t really affect the operation at all, but it helps to remind that the conditions in the “until” part are tested after the actions in the “sequence” part run.

Lastly, those three triggers can be combined into one.

Anyway:

- id: id_157
  alias: alexa notify on flood detection
  trigger:
  - platform: state
    entity_id:
      - sensor.kitchen_flood_sensor_flood
      - sensor.master_bed_bath_flood_sensor_flood
      - sensor.water_tank_flood_sensor_flood
    to: '2'
  condition:
  action:
  - alias: Repeat the sequence UNTIL the conditions are true
    repeat:
       sequence:
         - service: notify.alexa_media
           data_template:
             target: 
              - media_player.living_room
              - media_player.kitchen_spot
              - media_player.hallway_dot
              - media_player.1st_floor
              - media_player.man_cave
              - media_player.master_bed
             title: "Flood Detected in the {{ trigger.to_state.attributes.friendly_name }}"
             message: >
              "Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}. Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}"
             data:
               type: announce
               method: all
         - delay:
             minutes: 2
       until:
         - condition: state
           entity_id: alert.master_bathroom_flood
           state: 'off'
         - condition: state
           entity_id: alert.kitchen_flood
           state: 'off'
         - condition: state
           entity_id: alert.water_tank_flood
           state: 'off'

great thankyou for the tips

Oh, just realized, based on another recent improvement, the three conditions in the until part can be combined as well:

- id: id_157
  alias: alexa notify on flood detection
  trigger:
  - platform: state
    entity_id:
      - sensor.kitchen_flood_sensor_flood
      - sensor.master_bed_bath_flood_sensor_flood
      - sensor.water_tank_flood_sensor_flood
    to: '2'
  condition:
  action:
  - alias: Repeat the sequence UNTIL the conditions are true
    repeat:
       sequence:
         - service: notify.alexa_media
           data_template:
             target: 
              - media_player.living_room
              - media_player.kitchen_spot
              - media_player.hallway_dot
              - media_player.1st_floor
              - media_player.man_cave
              - media_player.master_bed
             title: "Flood Detected in the {{ trigger.to_state.attributes.friendly_name }}"
             message: >
              "Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}. Attention. a flood has been detected in the {{ trigger.to_state.attributes.friendly_name }}"
             data:
               type: announce
               method: all
         - delay:
             minutes: 2
       until:
         - condition: state
           entity_id:
             - alert.master_bathroom_flood
             - alert.kitchen_flood
             - alert.water_tank_flood
           state: 'off'
1 Like

building on this example, I am trying my first repeat automation, after having had a setup with rather complex structure of intermediate automations and time_pattern triggers…

automation:
  - id: Party mode
    alias: Party mode
    trigger:
      - platform: state
        entity_id: input_boolean.home_mode_party
        to: 'on'
    condition:
      condition: template
      value_template: >
        {{states('input_select.activity') not in ['Naar bed','Slapen']}}
    action:
      - service: automation.turn_off
        entity_id:
          - automation.sense_lights_change
          - automation.low_light_hallway_motion_sensors
      - delay:
          seconds: 2
      - repeat:
           sequence:
              - service: script.turn_on
                entity_id: script.lights_partying_on
              - delay:
                  seconds: 1
              - service: script.turn_on
                entity_id: script.lights_partying_on_2
              - delay:
                  seconds: 5
           until:
             - condition: state
               entity_id: input_boolean.home_mode_party
               state: 'off'
      - service: script.lights_partying_reset
      - delay:
          seconds: 2
      - service: script.lights_partying_off
      - delay:
          seconds: 10
      - service: automation.turn_on
        entity_id:
          - automation.sense_lights_change
          - automation.low_light_hallway_motion_sensors

things work perfectly until the bit after the until condition. The repeat stops alright, but the services after that dont get fired. Am I wrong in the syntax, or, does the turn_off of the input_boolean somehow interfere with the automation as a whole? (since it is also the trigger for that)

thanks for having a look

I don’t seen anything that would explain that behavior.

I wonder, though, why do you repeat a sequence that only turns on a couple of lights? If it runs again the lights are already on, right? So why repeat?

Note that the condition test in the until part is only evaluated when it actually gets to that part (i.e., after the delays in the sequence.)

How does that input_boolean behave? Since the automation is in the default single mode, the first time that entity changes to on the automation will start running. After that the trigger will have no effect until the automation completes. Also, since the until part is only getting evaluated every 6 seconds, if that input_boolean is going on and off while the automation is running it may not be seen as off.

You say the repeat stops but the remaining actions don’t get executed? Why do you say that? What does home-assistant.log say? (I don’t need to see the log, I’m just asking what you saw there to make you conclude what you did.)

because these are the scripts:

  lights_partying_on:
    alias: Lights partying on
    mode: restart
    sequence:
      service: light.turn_on
      data_template:
        entity_id: >
          light.{{['frontdoor','dining_corner','symfonisk','kist','serre_chair',
                   'lounge_chair_long','home_theater','world_map']|random}}
        rgb_color: ['{{ (range(0, 255)|random) }}',
                    '{{ (range(0, 255)|random) }}',
                    '{{ (range(0, 255)|random) }}']
        brightness: '{{ (range(50, 250)|random) }}'
        transition: '{{ (range(1, 3)|random) }}'

  lights_partying_on_2:
    alias: Lights partying on 2
    mode: restart
    sequence:
      service: light.turn_on
      data_template:
        entity_id: >
          light.{{['frontdoor','dining_corner','symfonisk','kist','serre_chair',
                   'lounge_chair_long','home_theater','world_map']|random}}
        rgb_color: ['{{ (range(0, 255)|random) }}',
                    '{{ (range(0, 255)|random) }}',
                    '{{ (range(0, 255)|random) }}']
        brightness: '{{ (range(50, 250)|random) }}'
        transition: '{{ (range(1, 3)|random) }}'

:wink: it’s supposed to be a wild party, but this is as wild as it gets I HA …

this is a simple input_boolean which is used to trigger this automation only, and has a button in the frontend. click turn_on: party, click turn_off, party is over.
should I be using another mode here? I did think of parallel, but thought that might be interfering with the repeat section.

nothing in the log really. the 2 final scripts simply were not fired. Which is quite visible in the house, because the lights were left in all colored states, while the scripts should first reset them to a default color, and after that turn them off.

must admit 2 successful runs happened, where the full automation was executed. Maybe this happened before:

Ah, ok. Fair enough. I didn’t look closely enough; I thought I saw it just calling the light.turn_on service and overlooked the fact that it was calling scripts.

No, single seems appropriate.

That should not be true. It should show you every script/automation running and every action they execute. You shouldn’t have to guess what happened. We’ve been here before.

o but it does, indeed. I meant to say I didn’t see an error logged which would prevent the firing of these last 2 scripts and delay.
gave it some extra runs now, and that all finished nicely. Including a parallel script triggering on the same boolean I made to send a few notifications and tts announcements.

thanks for your feedback!

So you might be better off doing something like these automations:

  - id: Party mode
    alias: Party mode
    trigger:
      - platform: state
        entity_id: input_boolean.home_mode_party
        to: 'on'
    condition:
      condition: template
      value_template: >
        {{states('input_select.activity') not in ['Naar bed','Slapen']}}
    mode: restart
    action:
      - service: automation.turn_off
        entity_id:
          - automation.sense_lights_change
          - automation.low_light_hallway_motion_sensors
      - delay: 2
      - service: script.lights_partying
  - id: Party mode stop
    alias: Party mode stop
    trigger:
      - platform: state
        entity_id: input_boolean.home_mode_party
        to: 'off'
    mode: restart
    action:
      - service: script.turn_off
        entity_id: script.lights_partying
      - service: script.lights_partying_reset
      - delay: 2
      - service: script.lights_partying_off
      - delay: 10
      - service: automation.turn_on
        entity_id:
          - automation.sense_lights_change
          - automation.low_light_hallway_motion_sensors

and this script:

  lights_partying:
    sequence:
      - repeat:
          # Do forever
          while: []
          sequence:
            - service: script.turn_on
              entity_id: script.lights_partying_on
            - delay: 1
            - service: script.turn_on
              entity_id: script.lights_partying_on_2
            - delay: 5

wow, thanks! using the boolean as a trigger, and not only as a condition to stop the repeat. This is closer to what I had before… but way neater because of the new repeat. will rewrite. thanks!

Actually, I think both automations should use restart mode. But play around; you’ll figure it out what works best for you. :smile:

1 Like