Please help me with automation while loop

So im trying to get reminded every minute we leave the pool gate open via Alexa -

I have no idea why this doesnt work, it looks good in the GUI, the actions work, the trigger works (first action fires) and I have tested this with the pool gate open and the ‘WHILE’ config returns back true… but its action never fires?

  alias: Pool Gate Opened
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: e5d17f6523d82e3f159ebb0a2ea4c505
    entity_id: binary_sensor.pool_gate_multipurpose_sensor_contact
    domain: binary_sensor
  condition: []
  action:
  - service: notify.alexa_media
    data:
      message: Pool gate has been opened
      target:
      - media_player.main_echo_dot
      - media_player.bedroom_echo_dot
      data:
        method: all
        type: announce
  - repeat:
      while:
      - type: is_open
        condition: device
        device_id: e5d17f6523d82e3f159ebb0a2ea4c505
        entity_id: binary_sensor.pool_gate_multipurpose_sensor_contact
        domain: binary_sensor
        for:
          hours: 0
          minutes: 1
          seconds: 0
      sequence:
      - service: notify.alexa_media
        data:
          message: Pool gate is open
          target:
          - media_player.main_echo_dot
          - media_player.bedroom_echo_dot
          data:
            method: all
            type: announce
  mode: single
alias: Pool Gate Opened
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.pool_gate_multipurpose_sensor_contact
    from: 'off'
    to: 'on'
  condition: []
  action:
  - repeat:
      while: "{{ is_state('binary_sensor.pool_gate_multipurpose_sensor_contact', 'on') }}"
      sequence:
      - service: notify.alexa_media
        data:
          message: Pool gate is open
          target:
          - media_player.main_echo_dot
          - media_player.bedroom_echo_dot
          data:
            method: all
            type: announce
      - delay: '00:01:00'
  mode: single
1 Like

THANKYOU!!!

the GUI was leading me astray. chucked in volume as well for anyone interested, works a treat:-

- id: '1655878094313'
  alias: Pool Gate Opened
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.pool_gate_multipurpose_sensor_contact
    from: 'off'
    to: 'on'
  condition: []
  action:
  - repeat:
      while:
      - condition: template
        value_template: '{{ is_state(''binary_sensor.pool_gate_multipurpose_sensor_contact'',
          ''on'') }}'
      sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.main_echo_dot
          volume_level: '0.6'
      - service: media_player.volume_set
        data:
          entity_id: media_player.bedroom_echo_dot
          volume_level: '0.6'
      - service: notify.alexa_media
        data:
          message: Pool gate is open
          target:
          - media_player.main_echo_dot
          - media_player.bedroom_echo_dot
          data:
            method: all
            type: announce
      - delay: 00:01:00
  mode: single
1 Like

You may wish to consider moving the volume service calls out of the repeat - while and placing them just before the repeat - while .

The reason is because there’s not much need to repeatedly adjust the volume for each iteration of the repeat - while (just once prior to entering the repeat - while ought to be sufficient).

yeh, I thought about that, however someone might turn the music down if its loud and then we will forget. However, if I wanted to do it, would it be this:

- id: '1655878094313'
  alias: Pool Gate Opened
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.pool_gate_multipurpose_sensor_contact
    from: 'off'
    to: 'on'
  condition: []
  action:
      - service: media_player.volume_set
        data:
          entity_id: media_player.main_echo_dot
          volume_level: '0.6'
      - service: media_player.volume_set
        data:
          entity_id: media_player.bedroom_echo_dot
          volume_level: '0.6'
  - repeat:
      while:
      - condition: template
        value_template: '{{ is_state(''binary_sensor.pool_gate_multipurpose_sensor_contact'',
          ''on'') }}'    
  sequence:
      - service: notify.alexa_media
        data:
          message: Pool gate is open
          target:
          - media_player.main_echo_dot
          - media_player.bedroom_echo_dot
          data:
            method: all
            type: announce
      - delay: 00:01:00
  mode: single