Help with a complex zone automation

So I have a large number of zones that I have set up for my job and I want to track when I stop at the locations so that later I can generate a report for mileage. I don’t have to keep track of the actual miles between locations, I just need to create a spreadsheet telling where I went from and where I went to. For this I have an automation that I am setting up for when I enter and leave the different zones. I have input_boolean helpers set up for each zone that I want to trigger on when I enter the zone an off when I leave the zone. This will allow me if needed to easily track how long I was at each location. This is the yaml for the automation that I have configured. The problem is that it is not triggereing the helpers on and off that I have set up.

Any help is appreciated.

- id: '1723628315460'
  alias: trigger on zone enter/leave
  trigger:
    # Entering zones
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.bannach
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.ben_franklin
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.bliss
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.ips_warehouse
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.jefferson
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.kennedy
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.madison
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.mcdill
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.mckinley
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.pj_jacobs
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.plover_whiting
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.roosevelt
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.spash
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.support_services
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.transportation
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.washington
      event: enter
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.pods
      event: enter
    # Leaving zones
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.bannach
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.ben_franklin
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.bliss
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.ips_warehouse
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.jefferson
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.kennedy
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.madison
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.mcdill
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.mckinley
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.pj_jacobs
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.plover_whiting
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.roosevelt
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.spash
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.support_services
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.transportation
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.washington
      event: leave
    - platform: zone
      entity_id: person.dan_bemowski
      zone: zone.pods
      event: leave
  action: 
    - variables:
        event: "{{ 'left' if trigger.event == 'leave' else 'arrived at' }}"
        person: "{{ trigger.to_state.attributes.friendly_name }}"
        zone: "{{ trigger.zone.attributes.friendly_name }}"
        helper: "'input_boolean.me_at_' + {{ trigger.zone.attributes.friendly_name | lower | replace(' ','_') }}"
        action_type: "{{ 'off' if trigger.event == 'leave' else 'on' }}"
    - service: input_boolean.turn_{{ action_type }}
      entity_id: {{ helper }}
    - service: notify.mobile_app_sm_f936u1
      data:
        message: >
          {{ person + ' ' + event + ' ' + zone + ' ' + helper + ' ' + action_type }}
  mode: single

There are a couple little errors that need to be addressed.

  1. In the definition of helper, perform the concatenation inside the expression or “print” the static part outside the expression without any spaces between it and the {{ delimiters. Either of the following should work:
helper: "{{ 'input_boolean.me_at_' + trigger.zone.attributes.friendly_name | slugify }}"

helper: "input_boolean.me_at_{{ trigger.zone.attributes.friendly_name | slugify }}"

The slugify filter above will do everything that you were doing with | lower | replace(' ','_'), but will also handle punctuation marks.

  1. Use block scalars like > or place quotes around all the templates.
  2. The key target is missing from the input boolean service call action.
  action: 
    - variables:
        event: "{{ 'left' if trigger.event == 'leave' else 'arrived at' }}"
        person: "{{ trigger.to_state.attributes.friendly_name }}"
        zone: "{{ trigger.zone.attributes.friendly_name }}"
        helper: "input_boolean.me_at_{{ zone | slugify }}"
        action_type: "{{ 'off' if trigger.event == 'leave' else 'on' }}"
    - service: "input_boolean.turn_{{ action_type }}"
      target:
        entity_id: "{{ helper }}"
    - service: notify.mobile_app_sm_f936u1
      data:
        message: "{{ [person, event, zone, helper, action_type] | join(' ') }}"
  mode: single

You might also want to consider using the File integration or Google Sheets integration so you have a sequential log. It might be easier in the long run than a bunch of input booleans.

Didgeridrew

Thank you. I will do testing with that tomorrow. I really appreciate the help. I am pretty new to templating and have a lot to learn.

This might help simplify/reduce changes as you add zones (if you do).

I use the following:

trigger:
  - platform: state
    entity_id:
      - person.your_name
      - person.other_name
condition:
  - condition: template
    value_template: >-
      {{ trigger.from_state.state not in 'unavailable,unknown' and
      trigger.to_state.state not in 'unavailable,unknown' }}
action:
  - variables:
      event: "{{ 'arrived at' if trigger.from_state.state == 'not_home' else 'left' }}"
      person: "{{ trigger.to_state.name }}"
      zone: >-
        {{ trigger.to_state.state if trigger.from_state.state == 'not_home' else
        trigger.from_state.state }}