Trigger IDs and helpers, is this too much for one automation?

hello all,

I have an automation setup which utilizes a helper (mail counter), a binary door/window sensor, and USPS informed delivery integration. the amount of times the mailbox is opened is stored in the counter. the automation’s purpose is to send my wife and I an email everyday when the mail comes with the embedded scans of the mail items. The mailbox being opened once triggers this. The second time the box is open, it emails my wife and I that someone brought in the mail. Any further mailbox opening is ignored, and it resets at sunrise.

I used to accomplish this with 3 or 4 automations, and I recently tried to take advantage of trigger IDs to combine it, but the mail counter helper never resets, so it gets stuck at “3” and the automation stops sending notifications.

I’ve tried using a static time (5am) as a trigger, and moving the triggers and actions around, and can’t figure out a working combination. is this possible in this manner, or will I need a separate automation just to reset the helper?

- id: '1647196856842'
  alias: snail mail to email 
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.snail_mail
    to: 'on'
    id: mailbox open
  - platform: sun
    event: sunrise
    offset: 0
    id: 5AM
  condition: []
  action:
  - condition: trigger
    id: mailbox open
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.mail_helper
  - condition: trigger
    id: 5AM
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.mail_helper
  - choose:
    - conditions:
      - condition: state
        entity_id: counter.mail_helper
        state: '1'
      sequence:
      - data_template:
          data:
            html: '<img src="{{ states.sensor.mail_image_url.state }}">

              '
          message: snail mail has arrived
          title: snail mail has arrived
        service: notify.email
    - conditions:
      - condition: state
        entity_id: counter.mail_helper
        state: '2'
      sequence:
      - service: notify.email
        data:
          message: someone has brought in the mail
          title: snail mail update
    default: []
  mode: parallel
  max: 4

thank you for your help!

You just need to rearrange a few things… if you put the increment action and the reset action in their own Choose, it will be performed independently of the other Choose. The second Choose only handles the evaluation of the counter’s state and the related actions.

- id: '1647196856842'
  alias: snail mail to email 
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.snail_mail
    to: 'on'
    id: mailbox open
  - platform: sun
    event: sunrise
    id: 5AM
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: mailbox open
      sequence:
      - service: counter.increment
        data: {}
          target:
            entity_id: counter.mail_helper
    - conditions:
      - condition: trigger
        id: 5AM
      sequence:
      - service: counter.reset
        data: {}
          target:
          entity_id: counter.mail_helper
  - delay: "00:00:10"
  - condition: trigger
    id: mailbox open
  - choose:
    - conditions:
      - condition: state
        entity_id: counter.mail_helper
        state: '1'
      sequence:
      - data_template:
          data:
            html: '<img src="{{ states.sensor.mail_image_url.state }}">'
          message: snail mail has arrived
          title: snail mail has arrived
        service: notify.email
    - conditions:
      - condition: state
        entity_id: counter.mail_helper
        state: '2'
      sequence:
      - service: notify.email
        data:
          message: someone has brought in the mail
          title: snail mail update
    default: []
  mode: single
1 Like

Thank you so much. This has worked. I did not realize you couldn’t have several singular actions and a choose, but you can do multiple choose actions instead. I thought it would just go one by one down the chain. is it because they are handling the same entity/helper, or is it just the automation flow?

You can have both multiple actions in a choose, and have multiple conditions to choose from. But the problem was you placed some conditions and actions before the choose, outside of it. Those conditions halted the entire action part if they tested false. So because it wasn’t the mailbox open trigger, the counter did’t reset as well.