Timer - remaining time in automation

Hello guys!

I’ve a hallway with regular switch and motion sensor. I want to configure it so motion sensor would turn on the lights for 60s while clicking the switch would do so for 5 minutes. However even when timer was started by switch then motion sensor kicks in and reset timer to 60 seconds.
So what I want to achieve is to test remaining time in seconds of a timer in motion sensor automation and if it’s lower than say 60 restart the timer.
Seems ideal case for https://www.home-assistant.io/docs/scripts/conditions/#numeric-state-condition but I’m unable to get it working. I vas trying Developer Tools -> Template editor to fetch remaining time but no avail ( my timer was manually set to 1 hour for debugging, and it shows proper remaining time in UI):

1: {{states.timer.hallway_timer}}
2: {{states.timer.hallway_timer.remaining}}
3: {{states.timer.hallway_timer.finishes_at}}
4: {{states.timer.hallway_timer}}
5: {{state_attr('states.timer.hallway_timer','remaining') }}
6: {{state_attr('states.timer.hallway_timer','duration') }}
7: {{state_attr('states.timer.hallway_timer','finishes_at') }}
8: {{states['timer.hallway_timer'].state == 'idle'}}

result:

1: <template TemplateState(<state timer.hallway_timer=idle; duration=0:01:00, editable=False, friendly_name=Hallway lights time remaining @ 2021-04-01T21:35:46.001739+02:00>)>
2: 
3: 
4: <template TemplateState(<state timer.hallway_timer=idle; duration=0:01:00, editable=False, friendly_name=Hallway lights time remaining @ 2021-04-01T21:35:46.001739+02:00>)>
5: None
6: None
7: None
8: True

How can I get it working?

How about this instead:

In the actions for your button press automation, disable (turn off) the 60s automation(s) You can turn it/them on again when your 5 minute automation is triggered.

1 Like

Have two input booleans, each controlled by the respective timers.
Combine them into a group and then use the group state to.turn the light on or off

1 Like

thank you guys for all suggestions! @tom_l - I’ve never thought of enabling automation from another, will keep that in mind. I finally go with two timers as it seemed easier:
configuration.yaml:

timer:
  hallway_timer_motion:
    name: Hallway lights by motion time remaining
    duration: 45 
  hallway_timer_switch:
    name: Hallway lights by switch time remaining
    duration: 300 

automation.yaml:

alias: '[Hallway] Turn off lights on Timer end'
description: ''
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.hallway_timer_motion
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.hallway_timer_switch
condition:
  - condition: state
    entity_id: timer.hallway_timer_motion
    state: idle
  - condition: state
    entity_id: timer.hallway_timer_switch
    state: idle
action:
  - service: light.turn_off
    data: {}
    entity_id: light.shelly_shsw_1
mode: single
1 Like