I have many automations running fine and I have just set up an automation to turn on my blue bedroom lights on and after a few seconds to turn off the bedroom lights all together if the state of the bedroom lights is “on”.
I have a script that turns on the bedroom lights initially and then the script stops running leaving the bedroom lights turned on with state ‘on’.
So in the morning between 7:51:00 and 7:53:00 I expect the above automation to turn the bedroom lights to blue i.e. turn on the blue bedroom lights before switching off the bedroom lights all together. However, nothing happens and my bedroom lights continue to remain turned on with none of the action(s) taking place.
When I trigger the above automation for testing purposes without turning the bedroom lights on i.e. bedroom lights have a state of “off” in this case, the action(s) takes place i.e. the blue bedroom lights are triggered on and I assume the next action which is to turn off the bedroom lights all together also takes place.
Can anyone help me with this? All I am trying to do is when the bedroom lights are on between 7:15:00 and 7:50:00, the blue bedroom lights should turn on and then the bedroom lights should turn off all together.
Why can’t you use a standard state is on trigger? rather than a template? If you trigger manually the state of the switches doesn’t matter as only the action takes place. Why do you assume the second action takes place? it’s only 3 seconds later!
OK I see why you are doing the template, however I think it will only be evaluated when it changes so if the light is on before the conditions time I expect it will never trigger. So I expect you will need to run an automation trigger on time per min and then the condition of time and state of lights being on.
For instance…
- alias: 'Wake Me Up'
trigger:
- platform: time
minutes: '/1'
seconds: '0'
# at: states.sensor.alarm_time.state
condition:
condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmstatus
state: 'on'
- condition: state
entity_id: input_boolean.alarmweekday
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- condition: template
value_template: '{{ now().time().strftime("%R") == states.sensor.alarm_time.state }}'
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmstatus
state: 'on'
- condition: state
entity_id: input_boolean.alarmweekday
state: 'off'
- condition: template
value_template: '{{ now().time().strftime("%R") == states.sensor.alarm_time.state }}'
action:
# - service: notify.mypushbullet
# data:
# title: "Alarm"
# message: "Good morning Sir. Time to Wake Up!"
- service: switch.turn_on
data:
entity_id:
- switch.pibotlamps
- switch.pibedroomceilingdimmer
I am now trying to turn on my kitchen lights between 09:00:00 and 09:05:00. The kitchen lights are in the off state prior 09:00:00. I have used the code you provided and changed the state to off but unfortunately the lights do not turn on at all.
Here is my code:
- id: kitchen_lights_on
alias: Kitchen Lights On
trigger:
- platform: state
entity_id: switch.kitchen_lights
to: 'off'
- platform: time
at: '09:00:00'
condition:
condition: and
conditions:
- condition: time
after: '09:00:00'
before: '09:05:00'
- condition: state
entity_id: switch.kitchen_lights
state: 'off'
action:
- service: switch.turn_on
entity_id: switch.kitchen_lights
Hey, so to check, you want to run that automation:
Any time the lights are turned off - and then check that the time is after ‘09:00:00’ and before ‘09:05:00’
At ‘09:00:00’, when the lights are off
I wonder if the problem is that ‘09:00:00’ when the event triggers, isn’t after ‘09:00:00’. What if you change that to ‘08:59:00’?
The same sanity check though, if you manually trigger the automation in the time window, does it work? If the lights are on, and you turn them off during that time, do they turn back on again?