Trigger id with repeat / until

Hi All,

Trying to take advantage of the new trigger id, all seems to work until I have added in a repeat / until function. This seems to break it all. please help.

- id: '1500'
  alias: 'garden lights garden gate - backdoor'
  trigger:
    - platform: state
      id: "normal" 
      entity_id:
        - binary_sensor.kitchen_door
        - binary_sensor.garden_gate
      to: "on"
    - platform: state
      id: "gate_open" 
      entity_id: 
        - binary_sensor.garden_gate
      to: "on"
      for:
        minutes: 10
  action:
    - choose:
        - conditions:
            - condition: trigger
              id: "normal"
            - condition: state
              entity_id: binary_sensor.lights
              state: "on"
          sequence:
            - service: light.turn_on
              entity_id: 
                - light.garden_lights
            - wait_for_trigger:
                platform: state
                entity_id: 
                  - binary_sensor.kitchen_door
                  - binary_sensor.garden_gate
                from: "on"
                to: "off"
            - delay: 00:01:00
            - service: light.turn_off
              entity_id:
                - light.garden_lights
        - conditions:
            - condition: trigger
              id: "gate_open"
          repeat:    
            sequence:
              - service: notify.mobile_app_rich_phone
                data:
                  message: >
                    Gates has been left open!
              - delay:
                  milliseconds: 200
            until:
              - condition: trigger
                entity_id: binary_sensor.garden_gate
                state: "on"
  mode: restart
  max_exceeded: silent

Cheers

Rich

binary_sensor.garden_gate appears in both trigger ids. So the second choose option will never occur as the first chose option will always happen instead. If you want two separate choose cases instead of a “do one thing or another” you need to specify it like this:

  action:
    - choose:
        - conditions:
            - condition: trigger
              id: "normal"
            - condition: state
              entity_id: binary_sensor.lights
              state: "on"
          sequence:
            - service: light.turn_on
              entity_id: 
                - light.garden_lights
            - wait_for_trigger:
                platform: state
                entity_id: 
                  - binary_sensor.kitchen_door
                  - binary_sensor.garden_gate
                from: "on"
                to: "off"
            - delay: 00:01:00
            - service: light.turn_off
              entity_id:
                - light.garden_lights
    - choose:
        - conditions:
            - condition: trigger
              id: "gate_open"
          repeat:    
            sequence:
              - service: notify.mobile_app_rich_phone
                data:
                  message: >
                    Gates has been left open!
              - delay:
                  milliseconds: 200
            until:
              - condition: trigger
                entity_id: binary_sensor.garden_gate
                state: "on"

But fix this first:

Sending 5 notifications a second until someone closes the gate is not a good idea.

Why don’t you use an alert for this? This is the exact use case for it. :slight_smile:

1 Like

I don’t mean to spoil your sunny Saturday but the automation you posted still contains a syntax error.

I pasted it into my test system and ran Check Configuration. As expected, it reported the following error:

Logger: homeassistant.config
Source: config.py:443
First occurred: 09:39:40 (1 occurrences)
Last logged: 09:39:40

Invalid config for [automation]: [repeat] is an invalid option for [automation]. Check: automation->action->0->choose->1->repeat. (See ?, line ?).

The error is precisely what I described in my previous post.

Just seen the new update will check later :slight_smile: @123

@123

Thanks very much for this! I gave it a go, but it only seems to trigger the notification once. I might be wrong but it does not seem to get into a loop.

@paddy0174 had a look at Alerts seem the way forward if you don’t have an Android phone like me :wink: Alerts don’t come in until I unlock the phone grr…

I am going to try and push forward and work out what I am missing in @123 post.

Thanks for the help guys and sorry I have only just gotten back to you all.

What do you mean? You get the notification in Android only after you unlock your phone? Then something isn’t configured correctly. :slight_smile:

I’m running an excessive notification management that includes five Android phones, a few TVs and a few Android tablets. In all of them the alerts come up right when they “land” on the phones (or TVs or tablets).

Hey Paddy, I have got the Alert’s working ish I believe it is due to the fact I have a Samsung S10.
When I run a test notification, in the dev tools section of HA it works fine.

When I unlock the phone I do get the message but don’t get the option to acknowledge etc.

Do you know if it is possible in Alerts to change the priority or should I just set this up with a Boolean switch and make my own notifications?

service: notify.mobile_app_rich_phone
data:
  title: Alarm!
  message: testing
  data:
    ttl: 0
    priority: high
    channel: alarm_stream

Cheers

Rich

What do you mean by “acknowledge”? What do you want to do? I’m sorry, I don’t get it. :slight_smile:

Yes, there is a setting for the priority, it is used as you did above, take a look here:

Maybe an example helps, this is my alert for the refrigerator.

The alert:

alert:
  kitchen_refrigerator_high_usage:
    name: Kitchen Refrigerator High Usage
    entity_id: binary_sensor.kitchen_refrigerator_high_usage
    state: 'on'
    repeat:
      - 150
      - 5
    can_acknowledge: true
    skip_first: true
    notifiers:
      - notification_refrigerator_high

The notification that is send, in my case via a group; I deleted some of my entries, just for clarity.

notify:
- platform: group
  name: notification_refrigerator_high
  services: 
    - service: mobile_app_paddy
      data:
        message: >
          The fridge is using too much power...
        data:
          actions: 
            - action: "refrigerator_alarm"
              title: "Cancel alarm"

And this is the automation I’m using to disable the alert, if I push the button on my notification on the phone.

automation:
  - id: Disable Refrigerator Alarm
    alias: Disable Rerigerator Alarm
    trigger: 
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "refrigerator_alarm"
    action:
      - service: alert.turn_off
        target:
          entity_id: alert.kitchen_refrigerator_high_usage

Is it this, you are looking for, especially the last part? :slight_smile:

Thanks for Sharing, sorted out the priority / alarm_stream_max notifications sound and popups on the phone and all looks to be working OK.

Only one niggle is not having the done message unless I am missing something.

done_message: The gate is closed

but this is not the end of the world as everything else is working. So mega Thanks.

alert:
 - garden_gate:
   name: Garden gate is open
   entity_id: binary_sensor.garden_gate
   state: "on"
   repeat: 20
   can_acknowledge: true
   skip_first: true
   notifiers:
     - notification_gate_left_open

notify:
  - platform: group
    name: notification gate left open
    services:
      - service: mobile_app_rich_phone
        data:
          message: >
            The Gate has been left open! 
          data:
            ttl: 0
            priority: high
            channel: alarm_stream_max
            actions: 
              - action: "back_gate_alarm"
                title: "Cancel alarm"

automation:
- id: Disable Gate left open
  alias: Disable Gate left open
  trigger: 
    - platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: "back_gate_alarm"
  action:
    - service: alert.turn_off
      target:
        entity_id: alert.garden_gate

Cheers
Rich