oh i see… thanks for clearing that up.
i think i figured out how to use the timer helper to calculate the remaining time, and it does seem to return the number of seconds correctly.
{{ (state_attr('timer.alarm_trigger','finishes_at') | as_datetime | as_local - now()).total_seconds() | int }}
i don’t really know how i got this to work, it was really pieced together from bits of information from here and there.
i also found your example, but i couldn’t understand how to apply it. was i supposed to define this under the variables
section or i was supposed to create a template
section inside my automation? your code looks nicer than mine. i would like to steal it and use it for my own.
here is my automation that seems to work for me. i used if-else to use a hardcoded response if the timer helper didn’t have any value (which took me a good while to figure out why the automation didn’t
work when the helper’s state was idle).
i’m sure it will have loads of mistakes or bad practices, so please let me know!
alias: Alert Motion Detected when alarm armed home
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.zone_attic_motion_open
- binary_sensor.zone_main_door_open
- binary_sensor.zone_kitchen_door_open
- binary_sensor.zone_laundry_door_open
- binary_sensor.zone_gate_open
- binary_sensor.zone_laundry_motion_open
- binary_sensor.zone_kitchen_boundary_open
- binary_sensor.zone_porch_boundary_open
- binary_sensor.zone_laundry_boundary_open
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: alarm_control_panel.partition_area_1
state: armed_home
action:
- if:
- condition: state
entity_id: timer.alarm_trigger
state: idle
then:
- service: timer.start
data:
duration: '60'
target:
entity_id: timer.alarm_trigger
- service: script.announce_with_voice
data:
speaker_device: media_player.bedroom_2
announce_volume: 0.35
announcement_msg: '{{ phrases }}'
check_sensor: '{{ wait_sensor }}'
check_condition: '{{ wait_condition }}'
enabled: true
mode: single
variables:
config_location:
binary_sensor.zone_attic_motion_open: attic motion
binary_sensor.zone_main_door_open: main door
binary_sensor.zone_kitchen_door_open: kitchen door
binary_sensor.zone_laundry_door_open: laundry door
binary_sensor.zone_1st_flr_motion_open: first floor motion
binary_sensor.zone_gate_open: gate
binary_sensor.zone_laundry_motion_open: laundry motion
binary_sensor.zone_kitchen_boundary_open: kitchen boundary
binary_sensor.zone_porch_boundary_open: porch boundary
binary_sensor.zone_laundry_boundary_open: laundry boundary
location_name: |
{{ config_location.get(trigger.to_state.entity_id, 'unknown' ) }}
phrases: >-
{{ (
"pardon me...",
"excuse me...",
"sorry to interrupt..."
) | random }}
the alarm is being triggered... movement was detected by the {{ location_name }} sensor...
{% if is_state('timer.alarm_trigger','active') %}
alarm in {{ (state_attr('timer.alarm_trigger','finishes_at') | as_datetime | as_local - now()).total_seconds() | int }} seconds
{% else %}
alarm in 58 seconds.
{% endif %}
wait_sensor: alarm_control_panel.partition_area_1
wait_condition: armed_home