Timer autom. question

Hello,
maybe someone can help me.
I want to restart a timer when
either the timer is in idle state or
when the remaining time is less than 90 seconds.
my code so far:

alias:  Flurlicht oben 
description: ''
trigger:
  - type: motion
    platform: device
    device_id: 8e90e0a81858b7b86377bc537c37fe37
    entity_id: binary_sensor.presence_11
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: 0c8e49aa3d89a7375e1ce9ef8a58f737
    entity_id: binary_sensor.pir_sensor_3
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: timer.flurlichtaus
        state: idle
      - condition: numeric_state
        entity_id: timer.flurlichtaus
        below: '90'
action:
  - type: turn_on
    device_id: 4e05945435ead3ab8c7d0fc619556748
    entity_id: light.color_temperature_light_2
    domain: light
    brightness_pct: 5
  - service: timer.start
    data:
      duration: '90'
    target:
      entity_id: timer.flurlichtaus
mode: restart
max: 10

Many thanks and greetings

What are you trying to achieve, exactly…

I have a lamp in the hallway, this should be
via a motion detector when needed
be switched on for 90sec via a timer.
In addition, I want to switch on and off this lamp with an extra switch.
For this I set the timer to 360sec.
This is done in an extra automation for the switch.
But if now the motion detector is triggered, then the timer is set again to 90sec. I want to prevent this by:

- condition: state
        entity_id: timer.hallwaylightoff
        state: idle

so that in normal mode, triggered by motion, the light does not go out and then come back on, the automation should reset the timer to 90sec when motion is detected and the remaining time is less than 90sec.
This shall be done by:

      - condition: numeric_state
        entity_id: timer.hallwaylightoff
        below: '90'

my english is not so good and i used deepl Translator.

many greetings

I don’t quite understand the logic, but for a Timer of 90sec, if the timer is in state active, it means it is running, and thus < 90 sec.
There is no way to check the actual remaining time easily (you could use the last_changed value of the Timer, and compare to now() but not sure you actually need it).

I’ll try to describe it again.
The motion detector loads the timer with 90sec.
and the light goes on.
When a new movement is detected, e.g. after 70sec,
(the timer has now 20sec left) the timer is set again to
90sec so that the light does not go out.
When the timer has expired (idle status) the light is switched off.
The brightness is here 5%
Now I would like to have the possibility to switch on the lamp with a switch longer time.
I do this with a Zigbee switch and set the timer to 360sec and brightness 90%.
Pressing the switch again cancels the timer and the light goes out again.
If I forget, then it goes off after an hour.
If I turned on the light with the switch, the timer was loaded to 360sec and the brightness is 90% then it should not happen that the motion detector sets the timer to 90sec and the brightness to 5%. That would be bad.

I hope my description is now understandable.

Many greetings

Translated with DeepL Translate: The world's most accurate translator (free version)

Got it.

The most straightforward way would be to have 2 timers, I think. One for the motion sensor (90sec) and one for the switch (360sec).
When either reach their timeout, only shut down the light if the other one is not running.

If you like a one timer solution, add a condition like

- '{{ is_state("timer.test", "idle") or (state_attr("timer.test", "finishes_at")|as_timestamp - now()|as_timestamp) < 90 }}'

Thank you very much for the quick help,
I will test it

many greetings…

Hi,

unfortunately it does not work for me.
Can you help me with the syntax?
how do I have to insert it at this point?

condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: timer.flurlichtaus
        state: idle
      - condition: numeric_state
        entity_id: timer.flurlichtaus
        below: '90'

thanks…

condition:
  - '{{ is_state("timer.flurlichtaus", "idle") or (state_attr("timer.flurlichtaus", "finishes_at")|as_timestamp - now()|as_timestamp) < 90 }}'

hi,

thank you very much.
I had tried different variants, but now it works!
I think I still have to learn something there.

many greetings

Hi,

what I noticed,
I make the syntax, as written by you,
in my automation.
I then looked at it in the visual editor and then back to ‘Edit YAML’.
Then I saw that:

condition:
  - condition: template
    value_template: >-
      {{ is_state("timer.flurlichtaus", "idle") or
      (state_attr("timer.flurlichtaus", "finishes_at")|as_timestamp -
      now()|as_timestamp) < 90 }}

But everything still works…

Greetings

One the “quirks” of the UI editor, I guess. Never use it myself…