Getting the new "Choose" option to pass condition

Ok, I will post my full automation code. I know its long, but I have done some work and have narowed the problem down to the conditions for the two Choose options. I extracted them each in turn and replaced with a “{{ ‘true’ }}” and watched the automation fire all the way through succesfully. I even had a phone notification so I could see if it fired to Box A or B.

Can anyone see an error in my conditions that is preventing them from firing. One additional note, I copied the condition for renata (my wife) when she was driving home tonight, into the developer tools and got it to return true, so it should have fired the action, but didnt… confused.

ok here is the automation.

- alias:  Populate MPH input_text
  trigger:
    - platform: state
      entity_id:
        - sensor.david_distance_to_home
        - sensor.renata_distance_to_home
        - sensor.cynthia_distance_to_home
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: >
                {% if trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_2')))|round(0) }}
                {% elif trigger.entity_id == 'sensor.renata_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_2')))|round(0) }}
                {% else %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_2')))|round(0) }}
                {% endif %}}
          sequence:
            - service: notify.mobile_app_davids_phone
              data_template:
                title: "{{ trigger.entity_id }}"
                message: "MPH - Box A"
            - service: input_datetime.set_datetime
              data_template:
                entity_id: "input_datetime.{{ trigger.entity_id.split('.')[1].split('_')[0] }}_mph_datetime_1"
                time: '{{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}'
                date: '{{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}'
            - service: input_text.set_value
              data_template:
                entity_id: "input_text.{{ trigger.entity_id.split('.')[1].split('_')[0] }}_mph_coordinates_1"
                value: >
                  {% if trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ state_attr('person.david_m', 'latitude') }},{{ state_attr('person.david_m', 'longitude') }}
                  {% elif trigger.entity_id == 'sensor.renata_distance_to_home' %}
                    {{ state_attr('person.renata_m', 'latitude') }},{{ state_attr('person.renata_m', 'longitude') }}
                  {% else %}
                    {{ state_attr('person.cynthia_m', 'latitude') }},{{ state_attr('person.cynthia_m', 'longitude') }}
                  {% endif %}
        - conditions:
            - condition: template
              value_template: >
                {% if trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_2')))|round(0)
                    > (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_1')))|round(0) }}
                {% elif trigger.entity_id == 'sensor.renata_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_2')))|round(0)
                    > (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_1')))|round(0) }}
                {% else %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_2')))|round(0)
                    > (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_2')))|round(0) }}
                {% endif %}}
          sequence:
            - service: notify.mobile_app_davids_phone
              data_template:
                title: "{{ trigger.entity_id }}"
                message: "MPH - Box B"
            - service: input_datetime.set_datetime
              data_template:
                entity_id: "input_datetime.{{ trigger.entity_id.split('.')[1].split('_')[0] }}_mph_datetime_2"
                time: '{{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}'
                date: '{{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}'
            - service: input_text.set_value
              data_template:
                entity_id: "input_text.{{ trigger.entity_id.split('.')[1].split('_')[0] }}_mph_coordinates_2"
                value: >
                  {% if trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ state_attr('person.david_m', 'latitude') }},{{ state_attr('person.david_m', 'longitude') }}
                  {% elif trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ state_attr('person.renata_m', 'latitude') }},{{ state_attr('person.renata_m', 'longitude') }}
                  {% else %}
                    {{ state_attr('person.cynthia_m', 'latitude') }},{{ state_attr('person.cynthia_m', 'longitude') }}
                  {% endif %}
input_text:
  david_mph_coordinates_1:
  david_mph_coordinates_2:
  renata_mph_coordinates_1:
  renata_mph_coordinates_2:
  cynthia_mph_coordinates_1:
  cynthia_mph_coordinates_2:
input_datetime:  
  david_mph_datetime_1:
    name: David MPH Date-Time 1
    has_time: true
    has_date: true
  david_mph_datetime_2:
    name: David MPH Date-Time 2
    has_time: true
    has_date: true
  renata_mph_datetime_1:
    name: Renata MPH Date-Time 1
    has_time: true
    has_date: true
  renata_mph_datetime_2:
    name: Renata MPH Date-Time 2
    has_time: true
    has_date: true
  cynthia_mph_datetime_1:
    name: Cynthia MPH Date-Time 1
    has_time: true
    has_date: true
  cynthia_mph_datetime_2:
    name: Cynthia MPH Date-Time 2
    has_time: true
    has_date: true

I don’t know enough about this thing works to comment on why the triggers don’t trigger. However, what I can offer is a simplification of the trigger templates.

All of this:

                {% if trigger.entity_id == 'sensor.david_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.david_mph_datetime_2')))|round(0) }}
                {% elif trigger.entity_id == 'sensor.renata_distance_to_home' %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.renata_mph_datetime_2')))|round(0) }}
                {% else %}
                    {{ (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_1')))|round(0)
                    >= (as_timestamp(now()) - as_timestamp(states('input_datetime.cynthia_mph_datetime_2')))|round(0) }}
                {% endif %}}

can be reduced to this:

                {% set person = trigger.to_state.object_id.split('_')[0] %}
                {% set dt = 'input_datetime.' ~ person ~ '_mph_datetime_' %}
                {{ (now().timestamp() - state_attr(dt~'1', 'timestamp'))|round(0)
                    >= (now().timestamp() - state_attr(dt~'2', 'timestamp'))|round(0) }}

All it does is leverage the fact your sensors and input_datetimes follow a naming convention:

sensor.david_distance_to_home
input_datetime.david_mph_datetime_1

To help others debug the triggers, it would be helpful if you could explain what they attempt to do. Checking if one timestamp delta is greater than another timestamp delta doesn’t give insight into why that operation is being performed.

Thanks for the simplification. That’s a new technique for me. Love learning new ways of doing things. I will implement it when I get home and see if it helps the greater problem.

So I am attempting to create a MPH sensor. (I am aware I can get that from Life360, just doing this to learn).

This automation will Populate, one of two inputs with location and time stamps. I then use a sensor to turn that into mph. The goal of the “choose” is to have it always dump current data into the “oldest” input_ that way I have the most recent two points to create a value with.

The trigger was a distance from home value. So when that value changes twice, it will calculate speed.