I bought Ikea Tradfri and Osram Smart+ bulbs and connected them to Conbee and I noticed that after power outage all of them turn on.
I would like to create a rule that every time hass.io boots up it will turn all lights off.
I bought Ikea Tradfri and Osram Smart+ bulbs and connected them to Conbee and I noticed that after power outage all of them turn on.
I would like to create a rule that every time hass.io boots up it will turn all lights off.
Use the HA start event. Then turn off all lights.
- alias: Home Assistant Started turn off lights
trigger:
platform: homeassistant
event: start
action:
- service: light.turn_off
entity_id: group.all_lights
Be aware that this will turn all your lights off anytime you restart HA, so be sure to turn the automation off whenever you are going to restart manually.
I think Iâd have another automation set a Boolean on shutdown so it can be checked against as a condition of the first automation.
Thank you very much @silvrr now all my lights will stay turned off in case of power outage!
@samnewman86, it would be great if home assistant could ârememberâ the state before power outage but I donât think itâs possible to do it this way because the system will not shut down, it will just stop working.
I was thinking about the possibility to add an exception when the restart is triggered on demand, for instance to update or to apply new configuration. Would it be possible to detect such âmaintenance modeâ?
Just to be clear, note that they will likely turn on, when the power is restored (this is the default for a number of bulbs) Then after HA boots, they will turn off.
You may want to check in the settings options for your bulbs and see if the power restore state is an option.
Yes, thatâs the reason why I want to make this automation I can easily imagine the scenario when power outage occurs in the middle of the night or when I am not at home and all my lights will be turned on all the time. Home Assistant takes around 5 minutes to boot so itâs not the best solution but so far I couldnât find anything better
I was reading about it before creating post and it seems that so far only Philips Hue implemented this feature (but youâll need Philips Hue Hub to upgrade firmware and change these settings). Ikea and Osram bulbs do not have it
It strikes me that these lights are not very âwife friendlyâ (something most of use here strive for, just to avoid the complaints involved as we are trying to make their lives easier !!! 8 - 0 ) ( IMHO )
Bear in mind that building and testing interfaces, automations and scripts involves a LOT of restarts, so donât expect a happy âother halfâ if you want to test a new timing action whist they are âinsert ANY activity hereâ
Do you get a lot of power outages ?
You may need to invest in equipment that retains last state as suggested above (I like z-wave gear but thatâs just my opinion)
Silvrrâs automation should do exactly as you asked but there are caveats as noted, if you canât move to retentive memory devices you may have to employ a complete hardware abstraction layer where you interact with HA and it then interacts with your equipment.
The issue there is that you canât just switch a light on, you have to get a switch that tells HA to then turn the light on.
HA will retain last states (as long as you donât use initial values in the store locations) and then uses a varient of Silvrrâs automation to run a script which goes though each stored value and maps that to the appropriate light.
The cost of the separate switches and the time involved to implement - would mean that Iâd just change the equipment.
YMMV
Create an input Boolean called unexpected power off
Create an automation that sets this to false when ha is restarted manually. Then another automation that sets this to true 30seconds after power on.
Then create an automation to turn all lights off on power up if the unexpected power off Boolean is true.
Thanks @Mutt but I just need simple rule to turn off all lights in case of power outage because itâs a deal breaker for me.
@samnewman86, I tried to follow your instructions but my configuration doesnât work. Lights still turn off when I restart Home Assistant manually.
configuration.yaml
input_boolean:
maintenance_mode:
name: HA restarted on demand
icon: mdi:restart
automation.yaml
- id: '1567199368534'
alias: HA boot - turn off all lights
trigger:
- event: start
platform: homeassistant
condition:
- condition: state
entity_id: input_boolean.maintenance_mode
state: 'off'
action:
- delay: 00:01
- service: light.turn_off
entity_id: group.all_lights
- data:
entity_id: input_boolean.maintenance_mode
service: input_boolean.turn_off
- id: '1567201768135'
alias: HA - enter maintenance mode
trigger:
- event: shutdown
platform: homeassistant
condition: []
action:
- alias: ''
data:
entity_id: input_boolean.maintenance_mode
service: input_boolean.turn_on
Sebastien,
Your code looks good, though itâs not quite the way I write mine, so Im guessing you have used the automation writing editor ?? Either way no bother.
The only thing I can see that may have tripped up your intended operation is that (to me at least) it seems that âoftenâ two lines have been reversed.
The creation of the input_boolean looks spot on.
The automation(s), Iâd have written like this : -
- id: '1567199368534'
alias: HA boot - turn off all lights
trigger:
- platform: homeassistant
event: start
condition:
- condition: state
entity_id: input_boolean.maintenance_mode
state: 'off'
action:
- delay: '00:00:01'
- service: light.turn_off
entity_id: group.all_lights
- service: input_boolean.turn_off
entity_id: input_boolean.maintenance_mode
- id: '1567201768135'
alias: HA - enter maintenance mode
trigger:
- platform: homeassistant
event: shutdown
action:
- service: input_boolean.turn_on
entity_id: input_boolean.maintenance_mode
Iâm groping a bit as Iâm doing this from memory, generally you need to call the service before you demand an action from it. (light.turn_on, input boolean.toggle etc.).
Though as always you need to check indentation and ensure that it passes the âconfigurationâ, âserver controlâ, âcheck configâ
Any errors you get here âshouldâ help you narrow down where you need to concentrate your efforts
Regards
Mutt
I should also say that this work around, given that your lights normally ALL come on after a restart, (as silvrr pointed out, they will come on briefly) and will now ALL switch OFF.
So on any restart, youâll get ALL the lights coming on regardless, but if it was NOT a âmanualâ restart they will ALL go off again (after the boot delay, restart time and the small timer you have placed in the code above.
(Edit: Sorry, got the cases reversed, corrected now)
Still not working. I set input boolean maintenance_mode manually to true and it works right. I checked the logs and I noticed that âHA - enter maintenance modeâ is not triggered on restart. Is there any other way to set this input_boolean to true before HA shuts down?
Sebastian,
Sorry, still not got an HA instance near to me, to test on.
Iâve used the homeassistant start event myself before so with that and your comment that it works if you set the boolean manually, it seems that it âmayâ be around the âshutdownâ event.
Just Checking : - did you replace your automations with the ones I gave ? did they throw up any errors in the âcheck cofigâ ? if so, what ?
If anything goes wrong with an automation, the system will just quit running it, so you may need to look at the logs. What Iâd do is add some steps to the shutdown and monitor how they go. For example : -
- id: '1567201768135'
alias: HA - enter maintenance mode
trigger:
- platform: homeassistant
event: shutdown
action:
- service: input_boolean.turn_on
entity_id: input_boolean.maintenance_mode
- service: input_boolean.turn_on
entity_id: input_boolean.debug1
- delay: '00:00:10'
- service: input_boolean.turn_off
entity_id: input_boolean.debug1
so create another input boolean, create a bit of ui so you can watch what happens to your maintenace bit and the debug bit and watch on your phone/tablet/another computer when you hit the restart
Another point, is restart the same as shutdown - maybe they are different events ???
Yes, I used your code and it passed validation without problems.
Start event works fine, automation on shutdown not, so I think itâs not the right trigger to change boolean before restart but I donât see any other event for homeassistant platform except âstartâ and âshutdownâ
Sebastian,
Okay, did you modify the shutdown code to include debuging ?
Did you observe the debugging on another device ? (what happens ?)
Have you tried âshutdownâ (Iâm assuming this is âstopâ instead of ârestartâ) just to see if this triggers your automation ?
What do the logs show at the âstopâ (restart will clear the log, but âstopâ may leave the log intact) ?
Worst comes to worst, you will just have to remember to set your bit manually before you restart manually.
(Sorry, idiot question but ⊠you did create the input_boolean.debug1 (or whatever) didnât you ? as HA may go " yeah did all that, now what the hell does he mean by âdebug1â ⊠crash out of that ⊠")
Maybe somebdy else has more knowledge/experience of the shutdown event ???
Regards
Disable the 2nd automation and see what state the maintenance mode Boolean is in after a restart.
Maybe it isnt getting set correctly
If you manually set it to on then restart does the 2nd automatically work as expected?
Everything works fine except automatically setting input boolean.
I tried all your suggestions but none of them worked. I tried homeassistant shutdown
trigger, homeassistant_close
and homeassistant_stop
events but after checking logs I cannot see any of them being triggered either on restart or shutdown.
My workaround for now is to use the switch on dashboard every time I plan to reboot to prevent switching off all lights
Just need to remember to switch it off before leaving.
Sebastian,
Not sure I understand.
You restart with the bit set and you "donât"get your lights turned off.
It also resets the bit on start up so should the system then crash ⊠and restart ⊠it then checks the bit and says âthis was unplanned, turn ALL the lights offâ - I thought thatâs what you wanted ?
So you âONLYâ have to set the bit, 5 secs before you initiate a manual restart and you are good to go.
What do you have to remember ?
Even my attention span is greater than 5 seconds
Hi, apologies for being newbie but if I paste this in my automation.yaml I get
Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/automations.yaml", line 2, column 11
I tried several indenting and I canât get it to go through. What am I missing? Thanks
No need to apologise for being new to HA, we have all been there. HA itself is only 6 years old so in a year youâll be helping others on this forum
From a quick glance, assuming that this is a direct copy from your config (itâs pasted in correctly, so weâll done for that) it looks like your final line entity_id: has 1 too many spaces before it.
Yaml spacing is alway two spaces at a time.
My first debugging is always just counting spaces.
Try that and come back to us.
Cheers