Can’t figure out why my lights aren’t turning off when I reboot HA.
PHYSCAL SETUP
Rpi3 + Hassio installation + Aeotec Zwave USB Stick gen5
GE Zwave On/Off Switch
GE Zwave Outlet
CONFIG
Both switch and outlet have been successfully included to the network. I can turn them on and off through my Hassio dashboard but I can’t tell if my automations are working. The goal is very simple: turn lights on at sunset and off at sunrise. So why do the lights stay on when I reboot HA? Shouldn’t HA see that the sun is up and turn off my living room outlet and my backyard switch? My Lat/Long are correct and sun is correctly reporting as up. The following is in my automations.yaml file.
Think of sunrise and sunset as a specific time not as a status. What I mean by that is where I am, sunrise occurred at 7:10 am. That means the automation will only trigger at 7:10 am. It doesn’t switch to sunrise and keep that state until sunset.
when you (re)boot that itself is a separate trigger. your automatons are a completely different trigger (time based upon sun). If you want to turn the lights on or off at (re)boot add a separate automation that does a condition check for sunrise or sunset.
- alias: On Startup
trigger:
platform: homeassistant
event: start
I think I’m starting to understand… using the state condition of sun.sun and “below_horizon” would solve the problem that shire210 pointed out correct? Now instead of a trigger based on a specific time I have a state that can be checked by a certain trigger.
marthocoo I should ADD your code to my automations if I want to ensure that any time HA restarts the lights will be on if the sun is down and vice versa? In addition to that I can use my existing triggers to ensure that at the specific time when the sun sets my lights will be turned on and vice versa.
Outside of those specific times (sun rise&set) I can manually turn on/off the lights with the physical switch but whenever HA restarts or sunrise/set occurs the lights will reset to their correct states (on when dark and off when light).
Totally correct. Here’s the opposite automation to the one I posted earlier, add both to your automations.yaml to take care of what happens when HA restarts during the day and at night, in addition to your sunrise and sunset automations:
- alias: Lights off after sunrise (if HA restarts)
trigger:
- platform: homeassistant
event: start
condition:
- condition: state
entity_id: sun.sun
state: "above_horizon"
action:
- service: switch.turn_off
entity_id:
- switch.living_room_outlet_switch
- switch.backyard_light_switch
you could just try making 1 action at boot time that is runs an if statement. Not 100% sure of the syntax of the top of my head but essentially it would follow as
boot -> sun up? Turn lights on ELSE turn light off
no need to check a second condition with a second automation because your lights are either ON or OFF
I like that idea, feels more succinct. Also have no idea about the syntax. Is there a section of the HA website that just talks more about yaml syntax basics? Or maybe another website entirely? I still get confused about the indenting and use of of the dash.
Why do you want it to specifically do anything when you reboot it? Just get the automation right and it will work correctly regardless of whether you reboot or just leave it alone.
I was also thinking this might be why it’s not doing what you want.
Also, what does rebooting HA have to do with anything? Are the lights turning on when you reboot in the middle of the day?
How would I write the trigger/condition if I wanted the lights to go on if it was 1:50 before sunset and HA restarts - so the original above is great but I’d like the lights to come back on when HA restarts if it’s 1:50 before sunset.
The initial state only pertains to the automation either being on or off at startup, it it is off then that automation won’t run until either the user turns it back on in the frontend or another automation that is on turns them back on. Or am I missing something here?
you are correct. Initial state only refers to the automation being active or not. It has nothing to do with the output(s) from that automation (eg: I have a light which is affected by multiple automation’s, depending on the case at hand but only one automation for that particular light is active during the daytime)
I always set initial_state: on as if you restart HA a few times in a row, HA will decide to turn off all automations and if you don’t notice then none of your automations will run till you notice and turn them back on in the frontend, which can make for a lot of hair pulling and shouting at the computer
I’m using this one (modified) but would like my lights to come on on restart of Home Assistant if sunset is within 1:50 or already occurred. I can already set the lights to come on at 1:50 before sunset but would be great if on a restart of Home Assistant they would also come on.
Is your HA server being stopped/restarted enough that it’s frequently not running the moment sunset occurs? I’m just trying to understand what your need for this automation is. It seems like since you’re using the below_horizon state it should still work if it gets started and it’s now below_horizon where it wasn’t before it stopped