rafalolb
(Rafal)
February 28, 2023, 1:06pm
1
I added DateTime helper and I set switch off time.
Next, I have automation:
alias: Korytarz - wyłącz
description: ""
trigger:
- platform: time
at: input_datetime.korytarz_wylaczenie
condition:
- condition: template
value_template: >-
now().timestamp() >= state_attr('input_datetime.korytarz_wylaczenie', 'timestamp')
enabled: true
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.korytarz_glowne
mode: single
The condition is wrong, why? What I doing wrong?
Help please.
Olivier1974
(Olivier Toussaint)
February 28, 2023, 1:10pm
2
A template must be written in Jinja, without verifying the condition, it must be
value_template: >-
{{ now().timestamp() >= state_attr('input_datetime.korytarz_wylaczenie', 'timestamp') }}
1 Like
tom_l
February 28, 2023, 1:12pm
3
The condition is also completely unnecessary because the the trigger ensures that already.
Troon
(Troon)
February 28, 2023, 1:13pm
4
If that’s the entire automation and you don’t have any other triggers, you don’t need that condition — it’s duplicating the trigger.
Alternative way to write the condition:
condition:
- condition: time
after: input_datetime.korytarz_wylaczenie
rafalolb
(Rafal)
February 28, 2023, 4:34pm
5
I have also other automation to set input_DateTime helper:
alias: Korytarz - włącz
description: ""
trigger:
- platform: state
entity_id:
- sensor.corridor_sensor
to: "1"
condition: []
action:
- if:
- condition: state
entity_id: switch.korytarz_glowne
state: "off"
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.korytarz_glowne
- service: input_datetime.set_datetime
data:
datetime: "{{ (now().timestamp() + 60) | timestamp_custom('%Y-%m-%d %H:%M:%S') }}"
target:
entity_id: input_datetime.korytarz_wylaczenie
mode: single
I have a PIR sensor, who have active state only by 1 second while motion is detect.
I want to create automation: If active state is trigered by PIR sensor, switch.korytarz_glowne is turn on by 60 secound. If PIR sensor set next active state in this period, the switch.korytarz_glowne should be turn on 60 second from last active state.
What may be wrong?