Hello everyone,
It might be very simple, but I can’t seem to find it. Would like to set a trigger if a light has been on for more than 5 minutes.
Thank you for your response
Hello everyone,
It might be very simple, but I can’t seem to find it. Would like to set a trigger if a light has been on for more than 5 minutes.
Thank you for your response
You want holding a state.
automation:
trigger:
- platform: state
entity_id: light.kitchen
to: "on"
for: "00:05:00"
Thank you for your response
Don’t think this will work. The intention is to trigger if the lamp has been on for more than 5 minutes.
Try it.
Then take 00:05:01, if this is important for you.
Thank you for your reaction
I’ve tried it! But the action then starts running when the light is on! My intention is actually that the action starts when the light has been on for 5 minutes
The sample code should provide what you asked for. Can you provide your code? Use the pre-formatted text option in the forum.
Sorry, but I don’t think so.
With this code, the action is also activated when the lamp is still on, the intention is that the action is only activated after the lamp has been on for 5 minutes.
Below is my code.
The intention is therefore that the action only starts when light plug1 is turned off again and has been on for longer than 5 minutes.
alias: Probeer
description: ''
trigger:
- platform: state
entity_id: light.testplug1
to: "on"
for: "00:05:00"
condition: []
action:
- service: light.turn_on
data: {}
target:
entity_id: light.testplug2
mode: single
Maybe it’s not possible what I want?
That’s not what you’ve been saying though. This is the first time you’ve told us that rather important part.
You’ll need to use a trigger of it turning off, and use templating to check to see how long it was on for, by checking the previous state object.
Thanks for your response and sorry I wasn’t very clear at first!!
if i understand correctly should i use
trigger.from_state.state
But I really wouldn’t know how to set it that the minimum should be 5 minutes?
You can check when that last_changed
using the state object, rather than the state
{{ (now()-trigger.from_state.last_changed).seconds) > 300 }}
Leading to something like
alias: Probeer
description: ''
trigger:
- platform: state
entity_id: light.testplug1
to: "off"
condition:
- condition: template
value_template: "{{ (now()-trigger.from_state.last_changed).seconds) > 300 }}"
action:
- service: light.turn_on
data: {}
target:
entity_id: light.testplug2
mode: single
Great, I’m going to try this.
I’m fairly new to Home assistant and don’t really understand what is possible with templating and how to use it.!
Thank you very much for your response.
It didn’t work at first, but then I discovered a bug in the code
condition:
- condition: template
value_template: "{{(now()-trigger.from_state.last_changed).seconds) > 300 }}"
to
value_template: "{{((now()-trigger.from_state.last_changed).seconds) > 300 }}"
After the adjustment this works perfectly!!
Thank you!
This is what I was looking for (based on the original question in the title of this post)