In it’s simplest form, this will create notifications of times you pass the PIR (to the microsecond).
trigger:
platform: state
entity_id: binary_sensor.garden_pir
to: 'on'
action:
service: persistent_notification.create
data_template:
message: "{{now()}}"
title: "Lap Timestamp"
To display how long it took to do the lap instead (in seconds, to the nearest 10th of a second):
Automation:
trigger:
platform: state
entity_id: binary_sensor.garden_pir
to: 'on'
action:
- service: input_text.set_value
data_template:
entity_id: input_text.this_time
value: "{{ as_timestamp(now()) }}"
- service: persistent_notification.create
data_template:
message: "{{ (states('input_text.this_time')|float - states('input_text.last_time')|float)|round(1) }}"
title: "Lap Time"
- service: input_text.set_value
data_template:
entity_id: input_text.last_time
value: "{{ states('input_text.this_time')|float }}"
Input Texts:
this_time:
name: This Time
initial: 0
last_time:
name: Last Time
initial: 0
This will miscalculate your first lap time unless you start running just before the PIR trigger area.
If you want to display the lap times in a Lovelace card you can use the custom homefeed card.