klogg
(Klogg)
April 3, 2018, 11:01pm
1
I’m struggling a little with simple time triggers.
A simple switch triggers to go on at a set time.
The same switch triggers to go off at a set time.
Is the only way to ensure these events happen to use:
trigger:
platform: time
minutes: "/1"
seconds: 0
condition:
condition: time
after: '23:00:00'
Any other trigger may not get activated if for any reason HA isn’t running at that precise time. If I am right it seems a little inelegant to me. IfI am wrong, please tell me
Rich_Paul
(Rich Paul)
April 3, 2018, 11:16pm
2
` automation reduce stairs brightness:
alias: Stairs - Reduce brightness at 11pm
initial_state: True
hide_entity: False
trigger:
platform: time
at: '23:00:00'
action:
- service: scene.turn_on
entity_id: scene.dim_s
- delay: '00:01:00'
- service: scene.turn_on
entity_id: scene.dim_s
I give up trying to format it!! You get the idea
petro
(Petro)
April 4, 2018, 1:37am
3
If i understand you correctly, you just want to fire something at 11pm. This is what you would want:
trigger:
platform: time
at: "23:00:00"
action:
- service: light.turn_on
entity_id: light.mylight1
using “/1” in the minutes catagory will execute that every minute. With the condition you posted, your automation would occur every minute, on the minute from 11pm to midnight (excluding midnight).
are you asking how to ensure the automation runs if home assistant is down at 11pm for example?
there’s obviously a lot of overhead with triggering every minute. if it’s an important automation, i’d instead have additional automations when home assistant starts. so something like:
automation:
trigger:
platform: homeassistant
event: start
condition:
condition: time
after: '23:00:00'
before: '06:00:00'
action:
...
actually, to make it cleaner and not repetitious, i might do this:
- alias: "turn on light"
trigger:
platform: time
at: '23:00:00'
action:
- condition: time
after: '22:59:59'
before: '06:00:00'
- service: light.turn_on
entity_id: light.some_light
- alias: "turn off light"
trigger:
platform: time
at: '06:00:00'
action:
- condition: time
after: '05:59:59'
before: '23:00:00'
- service: light.turn_off
entity_id: light.some_light
- alias: "startup"
trigger:
platform: homeassistant
event: start
action:
- service: automation.trigger
entity_id: automation.turn_on_light
- service: automation.trigger
entity_id: automation.turn_off_light
automation.trigger will only run the “action” (the usual trigger: and condition: statements are ignored).
klogg
(Klogg)
April 4, 2018, 8:32am
6
Thanks everyone, I have gone with something like @creakyshrimp suggested. It seems to cover everything.
- alias: check lights at startup
trigger:
platform: homeassistant
event: start
action:
- service: automation.trigger
entity_id: automation.dining_room_light_on_at_dusk
- service: automation.trigger
entity_id: automation.dining_room_light_off_at_11pm
- service: automation.trigger
entity_id: automation.dining_room_light_off_if_everyone_goes_out
- alias: dining room light on at dusk
trigger:
- platform: template
value_template: '{{states.group.family_presence.state == "home"}}'
- platform: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 5.0
condition:
condition: and
conditions:
- condition: state
entity_id: group.family_presence
state: "home"
- condition: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 5.0
- condition: time
before: "23:00:00"
action:
service: homeassistant.turn_on
entity_id: switch.dining_room_light
- alias: dining room light off at 11pm
trigger:
platform: time
at: "23:00:00"
condition:
condition: time
after: '22:59:59'
action:
service: homeassistant.turn_off
entity_id: switch.dining_room_light
- alias: dining room light off if everyone goes out
trigger:
platform: state
entity_id: group.family_presence
from: 'home'
to: 'not_home'
action:
service: homeassistant.turn_off
entity_id: switch.dining_room_light
petro
(Petro)
April 4, 2018, 11:55am
7
condition in this template is pointless because the trigger will always occur after 22:59:59. Other than that, everything else looks good.
klogg
(Klogg)
April 4, 2018, 12:05pm
8
@petro
I think I might be starting to get the hang of this
And yes, the condition is unnecessary, it was a throwback to some old logic before I was using
platform: homeassistant
event: start
Thanks!!
petro
(Petro)
April 4, 2018, 12:06pm
9
Yes yes, that makes sense. If you had another trigger in that automation, the condition would be useful!