Hue Light Automation Bug? Or bad automation?

Hi, I think I may have found a bug with the light services used in the automation configs in 2022.9.7. Or not. Can I please have some help? I think that the light.turn_off service isn’t interacting with my zigbee lights correctly because automations don’t work whereas manual dashboard control does.

Devices:

  • Philips Hue Bridge V2.0
  • Philips Hue Zigbee Downlights

Both automations (configs below) turn on the lights when motion is detected, and off when there is no motion detected. But the automations don’t actually turn the lights off even though the HA dashboard and Philips Hue app think they do. The steps and results are as follows.

  1. Start with the lights off.
  2. Wave hand in front of both motion sensors.
    • The lights turn on.
    • The HA dashboard shows the lights turning on.
    • The Philips Hue app also shows the lights turning on.
  3. Wait for the motion sensors to change their states to “clear” and then wait the delay time set by the automations.
    • The lights stay on.
    • But HA incorrectly shows the lights as off.
    • And Philips Hue also incorrectly show the lights as off.

The reason I think there’s a problem with the light services in the automations is because this problem doesn’t occur with manual state changes. From both HA and the Philips Hue app, I can very reliably toggle the lights on and off with the virtual switches in their dashboards. And when I do that through one, the other updates its dashboard to reflect the light state changes with a <1s delay.

Have I found a bug? Or have I done something wrong?

The lights are clearly still on.

But HA thinks the automation successfully turned them off.
Screenshot of Home Assistant

And Philips Hue agrees.

This automation uses the west light and motion sensor.

alias: Motion Nightlight - Hall 2 W
description: Motion Nightlight - Hall 2 W
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hall_2_motion_w_motion
    from: "off"
    to: "on"
condition: []
action:
  - alias: Turn on the lights
    service: light.turn_on
    data:
      brightness_pct: 20
    target:
      entity_id: light.bedroom_3_light_w
  - alias: Wait until there is no motion
    wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.hall_2_motion_w_motion
        from: "on"
        to: "off"
  - alias: Wait the number of seconds that has been set
    delay:
      seconds: 5
  - alias: Turn off the lights
    service: light.turn_off
    data: {}
    target:
      entity_id: light.bedroom_3_light_w
mode: single
max_exceeded: silent

This automation uses the east light and motion sensor.

alias: Motion Nightlight - Hall 2 E
description: Motion Nightlight - Hall 2 E
trigger:
  - platform: state
    entity_id: binary_sensor.hall_2_motion_e_motion
    from:
      - "off"
      - "on"
    to:
      - "on"
      - "off"
condition: []
action:
  - if:
      - condition: template
        value_template: "{{ trigger.to_state.state == 'on' }}"
    then:
      - alias: Turn on the light when motion is detected
        service: light.turn_on
        data:
          brightness_pct: 20
        target:
          entity_id: light.bedroom_3_light_e
    else:
      - alias: Wait a number of seconds after no motion is detected
        delay:
          seconds: 1
      - alias: Turn off the light if no motion is detected
        service: light.turn_off
        data: {}
        target:
          entity_id: light.bedroom_3_light_e
mode: single
max_exceeded: silent

Thank you to 123 Taras for writing that last config.

This is a terrible way of doing that

Instead do

  - alias: Wait until there is no motion
    wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.hall_2_motion_w_motion
        from: "on"
        to: "off"
        for: '00:00:05'

Awesome. Thanks Tinkerer. I’ve made that correction in my configs now, and I really appreciate the help.

That change doesn’t solve the issue where manual control on the HA dashboard and the Philips Hue app can turn the lights off, but the automation can’t. When the automation turns the lights off (or so it thinks) both the HA dashboard and Philips Hue app also think the lights are off, but the lights are physically still on.

Do you have any ideas about that? I think it’s a bug; either in HA, or in the light or bridges firmware. I’m not skilled enough to debug this without direction.

It’s definitely the brightness setting that’s causing this (and maybe colour but I still need to check properly). The default motion-light blueprint works reliably (with 1 exception), but adding a brightness settling broke the automation again. I have no idea why that affects turning the light off though.
The blueprint exception is that the lights initial state is ignored when light.turn_on is called. 2% starting brightness will turn on with 100% brightness.

I added a new selector to the inputs:

light_brightness:
  name: Brightness
  description: Percentage brightness to set the light to.
  default: 100
  selector:
    number:
      min: 0
      max: 100
      unit_of_measurement: percentage

And I called that value in the light.turn_on service:

- alias: "Turn on the light"
  service: light.turn_on
  data:
    brightness_pct: !input light_brightness
  target: !input light_target

I made no other changes to the blueprint.

This is the default unchanged blueprint:

blueprint:
  name: Motion-activated Light
  description: Turn on a light when motion is detected.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/cb909b4b05ba4c1732be022134d857d4c2991be3/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target

What does the log file tell you? What does the automation trace show?

The trace and related logbook entries say the light was turned off. But it wasn’t.
The Philips Hue app also says the light was turned off.

There are no changed variables though.

I think the first screenshot says it all, but here’s the rest, just in case.

Logbook

October 4, 2022

Bedroom 3 turned off
6:49:55 PM - 16 minutes ago

Bedroom 3 Light E turned off triggered by automation Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion
6:49:55 PM - 16 minutes ago

Hall 2 Motion E Motion cleared (no motion detected)
6:49:54 PM - 16 minutes ago

Bedroom 3 turned on
6:49:45 PM - 16 minutes ago

Bedroom 3 Light E turned on triggered by automation Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion
6:49:45 PM - 16 minutes ago

Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion detected motion
6:49:44 PM - 16 minutes ago - Traces

Hall 2 Motion E Motion detected motion
6:49:44 PM - 16 minutes ago

Hall 2 Motion E Motion cleared (no motion detected)
6:49:40 PM - 16 minutes ago

Bedroom 3 turned off
6:49:39 PM - 16 minutes ago

Bedroom 3 Light E turned off
6:49:39 PM - 16 minutes ago

Bedroom 3 turned on
6:49:30 PM - 16 minutes ago

Bedroom 3 Light E turned on triggered by automation Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion
6:49:30 PM - 16 minutes ago

Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion detected motion
6:49:29 PM - 16 minutes ago - Traces

Hall 2 Motion E Motion detected motion
6:49:29 PM - 16 minutes ago

Bedroom 3 turned off
6:49:26 PM - 16 minutes ago

Bedroom 3 Light E turned off triggered by automation Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion
6:49:26 PM - 16 minutes ago

Hall 2 Motion E Motion cleared (no motion detected)
6:49:25 PM - 16 minutes ago

Motion Nightlight - Bedroom 3 E - Brightness triggered by state of Hall 2 Motion E Motion detected motion
6:49:15 PM - 16 minutes ago - Traces

Hall 2 Motion E Motion detected motion
6:49:15 PM - 16 minutes ago

Bedroom 3 turned on
6:48:47 PM - 17 minutes ago

Bedroom 3 Light E turned on triggered by automation Motion Nightlight - Bedroom 3 E - Brightness triggered
6:48:47 PM - 17 minutes ago

Motion Nightlight - Bedroom 3 E - Brightness triggered triggered by service automation.trigger
6:48:46 PM - 17 minutes ago - Traces

Bedroom 3 turned off triggered by service light.turn_off
6:48:40 PM - 17 minutes ago - Dan

Bedroom 3 Light E turned off
6:48:40 PM - 17 minutes ago

Bedroom 3 Light W turned off
6:48:40 PM - 17 minutes ago

Motion Nightlight - Bedroom 3 E - Brightness turned on triggered by service automation.turn_on
6:47:48 PM - 18 minutes ago - Dan

Bedroom 3 turned on triggered by service light.turn_on
6:46:33 PM - 19 minutes ago - Dan

Bedroom 3 Light E turned on
6:46:33 PM - 19 minutes ago

Bedroom 3 Light W turned on
6:46:33 PM - 19 minutes ago

Trace 1

{
  "trace": {
    "last_step": "action/3",
    "run_id": "2dd1eda53e429f6f4976ac77f11370dd",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-10-04T10:49:15.039757+00:00",
      "finish": "2022-10-04T10:49:26.095150+00:00"
    },
    "domain": "automation",
    "item_id": "1664793030227",
    "trigger": "state of binary_sensor.hall_2_motion_e_motion",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-10-04T10:49:15.039977+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.motion_nightlight_bedroom_3_e_brightness",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-10-04T10:48:46.879916+00:00",
                "mode": "restart",
                "current": 1,
                "id": "1664793030227",
                "friendly_name": "Motion Nightlight - Bedroom 3 E - Brightness"
              },
              "last_changed": "2022-10-04T10:47:48.617352+00:00",
              "last_updated": "2022-10-04T10:48:46.880100+00:00",
              "context": {
                "id": "01GEH9SHGZAC25PBNH5J7FGPXR",
                "parent_id": "01GEH9SHGXW2CMKN5PKDBA180H",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "binary_sensor.hall_2_motion_e_motion",
              "from_state": {
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "state": "off",
                "attributes": {
                  "motion_valid": true,
                  "device_class": "motion",
                  "friendly_name": "Hall 2 Motion E Motion"
                },
                "last_changed": "2022-10-04T10:38:54.059040+00:00",
                "last_updated": "2022-10-04T10:38:54.059040+00:00",
                "context": {
                  "id": "01GEH97EKBRBP3YF2B8CSKA0E4",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "state": "on",
                "attributes": {
                  "motion_valid": true,
                  "device_class": "motion",
                  "friendly_name": "Hall 2 Motion E Motion"
                },
                "last_changed": "2022-10-04T10:49:15.036172+00:00",
                "last_updated": "2022-10-04T10:49:15.036172+00:00",
                "context": {
                  "id": "01GEH9TD0W691AC7EEZ2GV05ZN",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of binary_sensor.hall_2_motion_e_motion"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-10-04T10:49:15.045612+00:00",
          "changed_variables": {
            "context": {
              "id": "01GEH9TD0Z4TB7YAG3Q6VF53G2",
              "parent_id": "01GEH9TD0W691AC7EEZ2GV05ZN",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_on",
              "service_data": {
                "brightness_pct": 50,
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              },
              "target": {
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-10-04T10:49:15.162891+00:00",
          "result": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "state",
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "from_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "on",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:15.036172+00:00",
                  "last_updated": "2022-10-04T10:49:15.036172+00:00",
                  "context": {
                    "id": "01GEH9TD0W691AC7EEZ2GV05ZN",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "to_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "off",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:25.042533+00:00",
                  "last_updated": "2022-10-04T10:49:25.042533+00:00",
                  "context": {
                    "id": "01GEH9TPSJMY85DEQ99J3680YW",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "for": null,
                "attribute": null,
                "description": "state of binary_sensor.hall_2_motion_e_motion"
              }
            }
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2022-10-04T10:49:25.048002+00:00",
          "changed_variables": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "state",
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "from_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "on",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:15.036172+00:00",
                  "last_updated": "2022-10-04T10:49:15.036172+00:00",
                  "context": {
                    "id": "01GEH9TD0W691AC7EEZ2GV05ZN",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "to_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "off",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:25.042533+00:00",
                  "last_updated": "2022-10-04T10:49:25.042533+00:00",
                  "context": {
                    "id": "01GEH9TPSJMY85DEQ99J3680YW",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "for": null,
                "attribute": null,
                "description": "state of binary_sensor.hall_2_motion_e_motion"
              }
            }
          },
          "result": {
            "delay": 1,
            "done": true
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2022-10-04T10:49:26.050057+00:00",
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "mode": "restart",
      "max_exceeded": "silent",
      "trigger": {
        "platform": "state",
        "entity_id": "binary_sensor.hall_2_motion_e_motion",
        "from": "off",
        "to": "on"
      },
      "action": [
        {
          "alias": "Turn on the light",
          "service": "light.turn_on",
          "data": {
            "brightness_pct": 50
          },
          "target": {
            "entity_id": "light.bedroom_3_light_e"
          }
        },
        {
          "alias": "Wait until there is no motion from device",
          "wait_for_trigger": {
            "platform": "state",
            "entity_id": "binary_sensor.hall_2_motion_e_motion",
            "from": "on",
            "to": "off"
          }
        },
        {
          "alias": "Wait the number of seconds that has been set",
          "delay": 1
        },
        {
          "alias": "Turn off the light",
          "service": "light.turn_off",
          "target": {
            "entity_id": "light.bedroom_3_light_e"
          }
        }
      ],
      "id": "1664793030227",
      "alias": "Motion Nightlight - Bedroom 3 E - Brightness",
      "description": "Motion Nightlight - Bedroom 3 E - Brightness"
    },
    "blueprint_inputs": {
      "id": "1664793030227",
      "alias": "Motion Nightlight - Bedroom 3 E - Brightness",
      "description": "Motion Nightlight - Bedroom 3 E - Brightness",
      "use_blueprint": {
        "path": "homeassistant/motion_light_brightness.yaml",
        "input": {
          "light_target": {
            "entity_id": "light.bedroom_3_light_e"
          },
          "motion_entity": "binary_sensor.hall_2_motion_e_motion",
          "light_brightness": 50,
          "no_motion_wait": 1
        }
      }
    },
    "context": {
      "id": "01GEH9TD0Z4TB7YAG3Q6VF53G2",
      "parent_id": "01GEH9TD0W691AC7EEZ2GV05ZN",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Motion Nightlight - Bedroom 3 E - Brightness",
      "message": "triggered by state of binary_sensor.hall_2_motion_e_motion",
      "source": "state of binary_sensor.hall_2_motion_e_motion",
      "entity_id": "automation.motion_nightlight_bedroom_3_e_brightness",
      "context_id": "01GEH9TD0Z4TB7YAG3Q6VF53G2",
      "when": 1664880555.041579,
      "domain": "automation"
    },
    {
      "when": 1664880566.118277,
      "state": "off",
      "entity_id": "light.bedroom_3_light_e",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Motion Nightlight - Bedroom 3 E - Brightness",
      "context_message": "triggered by state of binary_sensor.hall_2_motion_e_motion",
      "context_source": "state of binary_sensor.hall_2_motion_e_motion",
      "context_entity_id": "automation.motion_nightlight_bedroom_3_e_brightness"
    }
  ]
}

Trace 2

{
  "trace": {
    "last_step": "action/3",
    "run_id": "ecaf53f94cf9f53ec86a84a3716f422c",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-10-04T10:49:29.983855+00:00",
      "finish": "2022-10-04T10:49:41.176190+00:00"
    },
    "domain": "automation",
    "item_id": "1664793030227",
    "trigger": "state of binary_sensor.hall_2_motion_e_motion",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-10-04T10:49:29.984046+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.motion_nightlight_bedroom_3_e_brightness",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-10-04T10:49:15.041661+00:00",
                "mode": "restart",
                "current": 0,
                "id": "1664793030227",
                "friendly_name": "Motion Nightlight - Bedroom 3 E - Brightness"
              },
              "last_changed": "2022-10-04T10:47:48.617352+00:00",
              "last_updated": "2022-10-04T10:49:26.091039+00:00",
              "context": {
                "id": "01GEH9TQTBK59CSSMWQX65T796",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "binary_sensor.hall_2_motion_e_motion",
              "from_state": {
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "state": "off",
                "attributes": {
                  "motion_valid": true,
                  "device_class": "motion",
                  "friendly_name": "Hall 2 Motion E Motion"
                },
                "last_changed": "2022-10-04T10:49:25.042533+00:00",
                "last_updated": "2022-10-04T10:49:25.042533+00:00",
                "context": {
                  "id": "01GEH9TPSJMY85DEQ99J3680YW",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "state": "on",
                "attributes": {
                  "motion_valid": true,
                  "device_class": "motion",
                  "friendly_name": "Hall 2 Motion E Motion"
                },
                "last_changed": "2022-10-04T10:49:29.975522+00:00",
                "last_updated": "2022-10-04T10:49:29.975522+00:00",
                "context": {
                  "id": "01GEH9TVKQVAV5X386X2V5RWHP",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of binary_sensor.hall_2_motion_e_motion"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-10-04T10:49:29.989481+00:00",
          "changed_variables": {
            "context": {
              "id": "01GEH9TVKZR1E3NWWFCBR2V4N8",
              "parent_id": "01GEH9TVKQVAV5X386X2V5RWHP",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_on",
              "service_data": {
                "brightness_pct": 50,
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              },
              "target": {
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-10-04T10:49:30.033546+00:00",
          "result": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "state",
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "from_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "on",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:29.975522+00:00",
                  "last_updated": "2022-10-04T10:49:29.975522+00:00",
                  "context": {
                    "id": "01GEH9TVKQVAV5X386X2V5RWHP",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "to_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "off",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:40.132316+00:00",
                  "last_updated": "2022-10-04T10:49:40.132316+00:00",
                  "context": {
                    "id": "01GEH9V5H4CRY2BGEDQGCRDKRC",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "for": null,
                "attribute": null,
                "description": "state of binary_sensor.hall_2_motion_e_motion"
              }
            }
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2022-10-04T10:49:40.139536+00:00",
          "changed_variables": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "state",
                "entity_id": "binary_sensor.hall_2_motion_e_motion",
                "from_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "on",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:29.975522+00:00",
                  "last_updated": "2022-10-04T10:49:29.975522+00:00",
                  "context": {
                    "id": "01GEH9TVKQVAV5X386X2V5RWHP",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "to_state": {
                  "entity_id": "binary_sensor.hall_2_motion_e_motion",
                  "state": "off",
                  "attributes": {
                    "motion_valid": true,
                    "device_class": "motion",
                    "friendly_name": "Hall 2 Motion E Motion"
                  },
                  "last_changed": "2022-10-04T10:49:40.132316+00:00",
                  "last_updated": "2022-10-04T10:49:40.132316+00:00",
                  "context": {
                    "id": "01GEH9V5H4CRY2BGEDQGCRDKRC",
                    "parent_id": null,
                    "user_id": null
                  }
                },
                "for": null,
                "attribute": null,
                "description": "state of binary_sensor.hall_2_motion_e_motion"
              }
            }
          },
          "result": {
            "delay": 1,
            "done": true
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2022-10-04T10:49:41.142159+00:00",
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "light.bedroom_3_light_e"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "mode": "restart",
      "max_exceeded": "silent",
      "trigger": {
        "platform": "state",
        "entity_id": "binary_sensor.hall_2_motion_e_motion",
        "from": "off",
        "to": "on"
      },
      "action": [
        {
          "alias": "Turn on the light",
          "service": "light.turn_on",
          "data": {
            "brightness_pct": 50
          },
          "target": {
            "entity_id": "light.bedroom_3_light_e"
          }
        },
        {
          "alias": "Wait until there is no motion from device",
          "wait_for_trigger": {
            "platform": "state",
            "entity_id": "binary_sensor.hall_2_motion_e_motion",
            "from": "on",
            "to": "off"
          }
        },
        {
          "alias": "Wait the number of seconds that has been set",
          "delay": 1
        },
        {
          "alias": "Turn off the light",
          "service": "light.turn_off",
          "target": {
            "entity_id": "light.bedroom_3_light_e"
          }
        }
      ],
      "id": "1664793030227",
      "alias": "Motion Nightlight - Bedroom 3 E - Brightness",
      "description": "Motion Nightlight - Bedroom 3 E - Brightness"
    },
    "blueprint_inputs": {
      "id": "1664793030227",
      "alias": "Motion Nightlight - Bedroom 3 E - Brightness",
      "description": "Motion Nightlight - Bedroom 3 E - Brightness",
      "use_blueprint": {
        "path": "homeassistant/motion_light_brightness.yaml",
        "input": {
          "light_target": {
            "entity_id": "light.bedroom_3_light_e"
          },
          "motion_entity": "binary_sensor.hall_2_motion_e_motion",
          "light_brightness": 50,
          "no_motion_wait": 1
        }
      }
    },
    "context": {
      "id": "01GEH9TVKZR1E3NWWFCBR2V4N8",
      "parent_id": "01GEH9TVKQVAV5X386X2V5RWHP",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Motion Nightlight - Bedroom 3 E - Brightness",
      "message": "triggered by state of binary_sensor.hall_2_motion_e_motion",
      "source": "state of binary_sensor.hall_2_motion_e_motion",
      "entity_id": "automation.motion_nightlight_bedroom_3_e_brightness",
      "context_id": "01GEH9TVKZR1E3NWWFCBR2V4N8",
      "when": 1664880569.984293,
      "domain": "automation"
    },
    {
      "when": 1664880570.988883,
      "state": "on",
      "entity_id": "light.bedroom_3_light_e",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Motion Nightlight - Bedroom 3 E - Brightness",
      "context_message": "triggered by state of binary_sensor.hall_2_motion_e_motion",
      "context_source": "state of binary_sensor.hall_2_motion_e_motion",
      "context_entity_id": "automation.motion_nightlight_bedroom_3_e_brightness"
    }
  ]
}

Then your problem is with Hue

HA can only know what Hue tells it. If Hue says it was turned off then clearly HA has to believe that.

Thanks Tinkerer. Do you think I will still have this problem if I replace the Philips Hue Bridge V0.2 with a generic ZigBee 3.0 coordinator?

But why is the automation different from manually toggling the lights from the dashboard? The dashboard has no problem turning off the lights, but the automation reliably fails.

Edit: Never mind… I just realised your problem is with the light status reported in Home Assistant.

Try this:

- alias: "Turn on the light"
  service: light.turn_on
  data:
    brightness_pct: !input light_brightness
  target: 
    entity_id: !input light_target
```<s>Text</s>

haha thanks Edward. I’d already tried that snippet of code in both of the configurations in my original post anyway. But I appreciate the help regardless.

Yeh, the status, and the inability to turn off the lights within an automation.

Have you tried to call those services one by one on the Developer tools window and see if you get it working properly?

I mean call the light.turn_on with the parameters you have on your automation, then call the light.turn_off, etc.

If everything works fine on Developer tools, then you probably have something in your automation.

Do you realize the mode: restart is an important part of that original blueprint? That is what allows the light to stay on while movement is around. By using single you will always turn off the light be or turn it on again if the movement is continuing.

Thanks, I didn’t think of that. The Developer Tools produced the same result as the automation.

In the screenshot below, I have the 2 windows with Home Assistant. On the left, I’ve set up the light.turn_on service with brightness_pct = 20%. On the right, I’ve set up the light.turn_off service.

When I click Call Service to call the turn on service, the light turns on with 20% brightness. The Call Service button is replaced by a green tick for a few seconds, and then fades back to the original blue Call Service button.

When I click Call Service to call the turn off service, the light stays on, but the Call Service button is still replaced by a green tick that fades back to the original blue button. And both the Home Assistant Dashboard and Philips Hue app think the light is off.

I don’t have this problem manually toggling the light from the dashboard (or Philips app), and I can reliably toggle it quite fast without any error.

EDIT: Just like with automations, removing the brightness setting from the Developer Tools turn on service allows the turn off service to work, further proving that the brightness setting is potentially doing something it shouldn’t.

I used to use restart, but I was told not to in a reply to this post I made.

Either way, comment 4 from this thread does use mode: restart and that produces the same result. If I don’t try to set brightness or colour when calling the light.turn_on service, the light cannot turn off when light.turn_off is called. However, without setting brightness or colour, the light can turn off ok. Comment 4 is a copy/paste of the original blueprint, but with a brightness setting added.

EDIT: comment 6 if you’re looking at the URL, or comment 4 if you’re looking at the side bar.

1 Like

The fact that Developer Tools also can’t turn the light off proves that it’s not the way the automation config YAML is done (but I still appreciate the feedback anyway because it helps me in the long run).

To simplify the problem, why does adding brightness or colour to the light.turn_on service prevent the light.turn_off service from working?

I ditched Hue and went direct with a CC2562 coordinator and haven’t looked back. Much more reliable and stable than I ever got Hue to be.

Developer tools doesn’t actually change the state of anything, just what HA thinks.

Your light target

Is that a single light bulb. Or a group of bulbs defined as a group in Home Assistant?

If the latter than it is common problem that some zigbee systems handle multiple almost simultaneous changes very badly. Especially when there are attributes involved like intensity and colour.

What can happen is that the zigbee net gets flooded with messages and the some bulbs never get the message

I have also seen bulbs go in limbo where they ignore direct messages but still turn on and off with true zigbee group messages.

You want to avoid sending messages to multiple bulb simultaneously and individual messages and instead send single messages to predefined zigbee groups. I believe both ZHA and Zigbee2mqtt supports defining zigbee groups now. I use deconz and it has always supported making light groups that appear as a single light entity in HA.

Creating a group of lights with the HA group feature means that HA sends a flood of individual messages and that is asking for trouble

Thanks Kenneth,
That’s especially good to know for when I start adding more automations.

It sounds like you’re describing intermittent problems. Is that correct?
What I’m describing is 100% repeatable. Every time the turn on service is called with a brightness setting, the turn off service fails.

I’ve used Hue/ZigBee groups, multiple lights individually, and also just single lights.
The traces and logs I posted earlier are from an automation with only a single motion sensor and a single light. Although, groups behave in the exact same way as individual lights.

Thanks. I’ve been thinking about switching to see what happens.

But this seems way too repeatable to just be a reliability problem. To quote myself:

Does anybody else have a Hue Bridge V2 and some Hue lights to run these same tests with? Or if nobody with that setup is seeing this post, maybe someone with a Hue Bridge V2 and 3A Nue lights that are meant to be a decent clone?

I can’t replicate the problem you’re experiencing where the physical light remains on yet both Home Assistant and the Hue app indicate it’s off. In my case, the physical light’s state is always in sync with the state reported by the Hue app and Home Assistant.

Here’s the experiment I performed (let me know if you want me to try something different):

I used this to turn on a Hue light.

        service: light.turn_on
        data:
          brightness_pct: 20
        target:
          entity_id: light.hallway_lamp

and this to turn it off

        service: light.turn_off
        target:
          entity_id: light.hallway_lamp

The physical Hue light successfully turned on to 20% brightness and then turned off.