Automate turn off lights after power outage and HA server restart

So I have this issue that happens neraly twice a week. At my location there are power outages that last for like 2 seconds. Since I have lights that don’t support last state behaviour, they all turn on after power is restored. I wish to write an automation that will change those lights to their last known state (or just turn off those lights).

I don’t have UPS, so my server and HA also restart. I wonder how to solve this issue and have come up with this idea:

When HA turns on (some state that identifies that HA is powered on) it turns off all lights. How could I do that, so that my house doesn’t lit up? I have ikea tradfri bulbs that don’t have the “power restore” function so this is happening for them. I also have philips hue lights, that have the “power restore” function and they properly turn to their last state (mostly off) during the power restore.

There is an automation trigger ‘home assistant’ which can fire when HA is powered up.

Thanks. It seems to be working, I tried restarting HASS and lights turned off with a delay (I thought there is a need for it to be sure that every light connected properly). This isn’t the most ideal way, but unless someone comes up with better idea, I will stick with that. Here’s my config:

- alias: HA startup
  trigger:
    platform: homeassistant
    event: start
  action:
  - delay: 00:01:00
  - service: light.turn_off
    data:
      entity_id: group.ikea_lights_all
4 Likes