ilo
21
Hi! I’ve tried to use the timedelta function described here.
The following automation works:
alias: Testi
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.date_time') ==
as_timestamp(states.sensor.oms8_next_alarm.state)|
timestamp_custom('%Y-%m-%d, %H:%M') }}
condition: []
action:
- service: light.turn_on
data:
effect: "1"
target:
entity_id: light.all_lights
mode: single
However, when I try to make it trigger one minute earlier, nothing happens:
alias: testi5
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.date_time') ==
as_timestamp(states.sensor.oms8_next_alarm.state) - timedelta(minutes=1)|
timestamp_custom('%Y-%m-%d, %H:%M') }}
condition: []
action:
- service: light.turn_on
data:
effect: "2"
target:
entity_id: light.all_lights
mode: single
i’ve tried to debug this now for hours. Please help! ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=12)
123
(Taras)
22
as_timestamp
produces an integer value (representing the number of seconds since the Unix Epoch).
timedelta(minutes=1)
produces a timedelta object. You can use it for subtracting from a datetime object but not from an integer value.
Just subtract 60 seconds from the integer value.
value_template: >-
{{ states('sensor.date_time') ==
as_timestamp(states.sensor.oms8_next_alarm.state) - 60 |
timestamp_custom('%Y-%m-%d, %H:%M') }}
ilo
23
Thanks for your reply! This is what I suspected myself, but adding that " - 60" to the code doesn’t trigger the automation anymore at all:
alias: Testi - 60s
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.date_time') ==
as_timestamp(states.sensor.oms8_next_alarm.state) - 60 |
timestamp_custom('%Y-%m-%d, %H:%M') }}
condition: []
action:
- service: light.turn_on
data:
effect: "2"
target:
entity_id: light.all_lights
mode: single
So weird!
123
(Taras)
24
I need additional information to help you fix this problem.
- Go to Developer Tools > States.
- Find
sensor.date_time
and sensor.oms8_next_alarm
- Let me know the value of each sensor’s
state
.
1 Like
ilo
25
Thanks for the help! Here are the details: