May sound like a silly question, but if you have motion sensors, why do you need timers?
you could instead use triggers based on motion sensor state and see which was was triggered first based on either the last_updated attribute or a trigger template to see which sensor triggered the automation (and have a condition that the automation doesn’t run if it was last triggered less than [say] 5 sec ago)…
so something like:
- alias: test timer compare
trigger:
- platform: state
entity_id:
- binary_sensor.motion_driveway_1
- binary_sensor.motion_driveway_2
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(state_attr("automation.test_timer_compare", "last_triggered") | default(0)) | int > 5)}}'
action:
- service: notify.email
data_template:
message: >
motion detected from
{% if is_state(trigger.entity_id,"binary_sensor.motion_driveway_1") %} binary_sensor.motion_driveway_1 to binary_sensor.motion_driveway_2 {% else %} binary_sensor.motion_driveway_2 to binary_sensor.motion_driveway_1 {% endif %}
- alias: test timer compare
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.switch_1
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.switch_2
from: 'off'
to: 'on'
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(state_attr("automation.test_timer_compare", "last_triggered") | default(0)) | int > 5)}}'
action:
- service: notify.lounge_tv
data_template:
message: >
driveway vehicle {% if trigger.entity_id == 'binary_sensor.switch_1' %} approaching {% else %} departing {% endif %}
It currently notifies as soon as either switch is triggered.
Any idea why that would be?
What I need it to do is report the direction of travel. If switch_1 triggers first and then switch_2 within the next 5 seconds it notifies ‘approaching’. If switch_2 triggers first and then switch_1 triggers within the next 5 seconds it notifies ‘departing’.
I had to use from 'off' to 'on' as I’m using mechanical switches to test this, rather than motion sensors and the changeover isn’t always clean.