Philips Hue - Power Outage Script

I have a few Philips Hue bulbs and they have this “feature” where if they lose and regain power they turn on.

Does anyone have a good way to automate turning them off if this happens?

1 Like

I have similar issue. One lamp sometimes just turns on during the night …and in addition it is a lamp in a children’s room … Very annoying if the small wakes up because hue powers light on… ice request.woukd also be interested

1 Like

The only thing I can imagine would be a time trigger to x seconds or minutes and set condition to luminance or time also .I have those for lights if someone turns on lights but it is not dark enough it turns off after x minutes

I was thinking about this, and presuming you mean like a power cut (ie HA loses power too), then an automation that fires when HA loads to wait a few minutes for the Hue hub and bulbs and everything to synchronise and then switches them all off should do it. I haven’t actually done it yet, but it’s on my list.

If you have power problems in just one room or a different problem that is causing the bulbs to loose power and reconnect but HA is still running, you’re probably stuck tbh.

I’ve a script that turns off a lights that turns on automatically if I’m not home. And it gives me a notification about it.

Hue sometimes, not often, turns on randomly and that’s why I did the automation.

One way that works if you’re home or not, is to check every time a light is on if a rule in the hue bridge is triggered. This let’s you know if it was a intentional to turn on the light or not.
You can use CURL to check when each rule was triggered in the hue bridge.

  • if light A turns on and none of corresponding rules has been triggered in last 120s -> False trigger
  • if light A turns on and on off corresponding rules has been triggered in last 120s -> True trigger
1 Like

Can u please give me those CURL command … wanna have those a a notifier

In my situation, HA, Hue hub, router and modem are on a UPS, so if power does get cut for less than 45 minutes all that stuff is immediately available when it restores.

So I would not be able to use the HA start event to trigger that, but that would work otherwise.

I was hoping there’d be a way to track if a Z-wave device or even something like a Wemo plug could be tracked to see if its online to determine power was loss in the house.

1 Like

Some folks using SmartThings monitor a “canary bulb” that only turns on when power is restored.

Checking a Z-wave device or two sounds like the perfect solution, though. I have a couple zooz Z-wave plugs on separate breakers. Please share if you implement this, a_ndy.

I was surprised at this “feature” when I got the Hue lights (my first “smart home” tech). It was one of the reasons I realized I needed to look into a hub and found out HA is awesome. Seems like Philips could easily make this a lot better by simply restoring the previous state when power is restored and setting the bulb to white @ 100% when the switch is flipped twice in a short time.

I’ve noticed that when my bulbs turn themselves on/off they usually show up as “unreachable” in the Hue app. It’s definitely not a distance from the hub problem. I’ve only seen this happen on bulbs that have knob and tube wiring, so I’m wondering if it’s just that the bulbs require clean power.

1 Like

I think I figured out a doable solution at least for my situation.

NMAP

I currently use it for presence detection, but will need to see if I can setup another instance with different settings for considered home value so its more immediate.

This could poll a device like a Wemo plug, smart thermostat or even the Hue hub if its not on a UPS backup.

When the power goes out, the device tracker would be registered as not_home and when it came back on, it would register as home. Then just run an appropriate script for the state change.

I think this would even work if the power was just flicked off then on because the device being tracked would take a minute to register back on the network.

Will need to test out later, but food for thought.

1 Like

For me, I have configured an automation that turns off the lights every two mins if its color temp is within the 378-380 range. It’s usually the temp if turned on by a dumb switch or power outage.

`  - condition: numeric_state
      entity_id: light.entertainment
      value_template: "{{ states.light.entertainment.attributes.color_temp | int}}"
      below: 370
      above: 368

`

2 Likes

Same problem here but different hardware and a different solution idea…

I have some Mi-Light bulbs that turn on every power outage…
My HASS is connect to a nobreak, so it never turns off…
Mi-light turns on and never send its status… so I can not monitor other than looking at it…

I have a Humidity mysensors node that presents itself to gateway without calibration (10% less than real).
I would like to trigger an automation to turn lights off when this humidity sensor reports a >10% variation from its last report.

Could it be done?

It’s very simple (though maybe some work for all your lights.):

- alias: 'Overloop Ging Hard aan'
  trigger:
  - platform: numeric_state
    entity_id: light.hue_white_lamp_4
    value_template: '{{ state.attributes.brightness }}'
    above: 253
  action:
    - service: light.turn_on
      data: 
        entity_id: light.hue_white_lamp_4
        color_temp: 353
        brightness: 1
    - delay:
        minutes: 1
    - service: light.turn_off
      data: 
        entity_id: light.hue_white_lamp_4

As you see I first lower the brightness to 1 because I prefer that, but you can take that out of course (as the delay)

Thanks @PuckStar, but it will only work with lights that inform its status…

My Mi-Lights are cheap RGBW 2.4Ghz from China and they only receive commands, never sending its status, so, unless I build a light sensor close to them, HASS will never know if they are on or off.

Because of that I need to know about power outage from another stuff and then send the OFF action for the lights…

Any idea?

Yeah I was still replying to the topic starter, who has Hue lights :).

Sorry I don’t know a solution for your problem.

I have similar issue to @thundergreen: one of my bulbs goes on sometimes. But because I have groups (a-la 3-4 bulbs together), I could verify one single bulb against other from group. So I’ve created AppDaemon app which checks if single bulb from group went on and turning it off after 10 seconds + sending notification.

import appdaemon.appapi as appapi

ENTITIES = "bulbs"

WAIT_TIME = 10


class HueBugControl(appapi.AppDaemon):
    def initialize(self):
        self._handle = None
        self.CONSTANTS = self.get_app("Constants")
        for entity in self.args[ENTITIES]:
            self.listen_state(self.bulb_on, entity, new="on")

    def bulb_on(self, entity, attribute, old, new, kwargs):
        if self._handle is not None:
            self.cancel_timer(self._handle)
        self._handle = self.run_in(self.check_bulbs, 10)

    def check_bulbs(self, kwargs):
        num_on = 0
        last_on = ""
        for entity in self.args[ENTITIES]:
            if self.get_state(entity) == "on":
                num_on += 1
                last_on = entity

        if 1 == num_on:
            self.turn_off(last_on)
            self.call_service(self.CONSTANTS.TELEGRAM_SERVICE,
                              message="_MALFUNCTION_ Bulb {0} went on".format(self.CONSTANTS.prepare_entity(last_on)))

        self._handle = None

I dont want the lights to turn off certain times so i came up with:

Sensor

  - platform: template
    sensors:
      period_of_day:
        friendly_name: 'period of the day'
        value_template: >-
          {% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
            dusk
          {% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
            dawn
          {% elif (states.sun.sun.attributes.elevation) < -4 %}
            night
          {% else %}
            day
          {% endif %}
        icon_template: >-
          {% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
            mdi:weather-sunset-down
          {% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
            mdi:weather-sunset-up
          {% elif (states.sun.sun.attributes.elevation) < -4 %}
            mdi:weather-night
          {% else %}
            mdi:weather-sunny
          {% endif %}

Automation

- alias: 'Reset after power failure'
  trigger:
  - platform: numeric_state
    entity_id: light.kitchen_window
    value_template: '{{ state.attributes.brightness }}'
    above: 253
  condition:
      - condition: template
        value_template: "{{ states.sensor.period_of_day.state != 'night' }}"
  action:
    - service: light.turn_on
      data: 
        entity_id: light.bedroom_light, light.bedroom_window_light, light.book_shelf_color_two, light.bookshelf_color, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.kitchen_window, light.living_room_right_sofa, light.living_room_window_light
        color_temp: 454
        brightness: 135
    - delay:
        seconds: 1
    - service: light.turn_off
      entity_id: light.bedroom_light, light.bedroom_window_light, light.book_shelf_color_two, light.bookshelf_color, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.kitchen_window, light.living_room_right_sofa, light.living_room_window_light, light.onoff_plug_1
    - service: notify.push
      data_template:
        title: Power failure
        message: 'Strömavbrott'
    - alias: 'Reset after power failure two'
      trigger:
      - platform: numeric_state
        entity_id: light.kitchen_window
        value_template: '{{ state.attributes.brightness }}'
        above: 253
      condition:
          - condition: template
            value_template: "{{ states.sensor.period_of_day.state != 'dawn' }}"
      action:
        - service: light.turn_on
          data: 
            entity_id: light.book_shelf_color_two, light.bookshelf_color, light.living_room_right_sofa, light.living_room_window_light
            rgb_color: [255,189,84]
            brightness: 150
        - service: light.turn_on
          data: 
            entity_id: light.bedroom_window_light, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.kitchen_window
        - delay:
            seconds: 1
        - service: light.turn_off
          entity_id: light.bedroom_light, light.bedroom_window_light, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.onoff_plug_1
        - service: notify.push
          data_template:
            title: Power failure
            message: 'Strömavbrott'
    - alias: 'Reset after power failure three'
      trigger:
      - platform: numeric_state
        entity_id: light.kitchen_window
        value_template: '{{ state.attributes.brightness }}'
        above: 253
      condition:
          - condition: template
            value_template: "{{ states.sensor.period_of_day.state != 'day' }}"
          - condition: time
            weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
      action:
        - service: light.turn_on
          data: 
            entity_id: light.bedroom_light, light.bedroom_window_light, light.book_shelf_color_two, light.bookshelf_color, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.kitchen_window, light.living_room_right_sofa, light.living_room_window_light
            color_temp: 454
            brightness: 135
        - delay:
            seconds: 1
        - service: light.turn_off
          entity_id: light.bedroom_light, light.bedroom_window_light, light.book_shelf_color_two, light.bookshelf_color, light.guest_room_1, light.guest_room_2, light.guest_room_3, light.hallway_1, light.hallway_2, light.hallway_3, light.hallway_hanger, light.kitchen_fan, light.kitchen_fan_2, light.kitchen_sink, light.kitchen_sink_two, light.kitchen_window, light.living_room_right_sofa, light.living_room_window_light, light.onoff_plug_1
        - service: notify.push
          data_template:
            title: Power failure
            message: 'Strömavbrott'

It would probably work fine with

condition:
  condition: time
  after: '19:00:00'
  before: '06:00:00'

I think the hue now has power recovery settings. I sometimes see the flicker when updates take place and I turn them off after x minutes regardless.

For the child room you might consider putting a smart light switch in place which doesn’t power on after a power outage. Then code the scripts to turn that on instead. You would need to add subsequent scripts to handle brightness/colour after that engages.

In terms of power outage detection, I ping a wemo smart plug and a powerline adapter… If they don’t reply for 10 mins then the power is down (rest of my gear is on a UPS). I then shut everything down. RPi’s first then the NAS is last since it has all the databases for HA, mqtt server, node red.