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