Can't figure out why lights are behaving this way

I have a set of rules that I have had in place ever since I started using HASS in early 2016, which turn on a couple lights in my basement (z-wave switches) if motion is detected from either of two motion sensors, and then turns them off again after x minutes of inactivity. It worked fine this way for most of the year.

Sometime in the past month, without me changing any of my rules whatsoever, the behavior changed and I cannot figure out what’s causing it.

Expected:

  • Motion sensor A OR B detects motion
  • Turn on lights (light.basement_hall_light_level_13_0 and switch.bar_cabinet_lights_switch_23_0)
  • After 5 minutes of inactivity, turn those lights off

What’s actually happening:

  • Motion sensor A detects motion, lights turn on as expected
    - As soon as motion sensor B detects motion, one of the lights immediately turns off (light.basement_hall_light_level_13_0). The bar lights remain on, and then turns off as expected 5 minutes later

That light should NOT be turning off when motion B goes from ‘off’ to ‘on’, and I cannot for the life of me figure out why this is happening. As I said, I changed no automation rules between when it was working and when it broke, and reading through my automation rules and scenes I can’t come up with any way this could be happening. The Activity Log only shows the “Basement motion on” automation getting triggered and the lights turning on; it shows nothing for the one light turning off.

Here are the relevant on/off automations:

- alias: Basement motion on
  trigger:
    - platform: state
      entity_id: binary_sensor.basement_hall_motion_sensor_9_0
      from: 'off'
      to: 'on'
    - platform: state
      entity_id: binary_sensor.basement_stairs_motion_sensor_24_0
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: light.basement_accent_lights_game_level_17_0
      state: 'off'
    - condition: state
      entity_id: input_boolean.detect_motion
      state: 'on'
  action:
    - service: light.turn_on
      entity_id: light.basement_hall_light_level_13_0
    - service: switch.turn_on
      entity_id: switch.bar_cabinet_lights_switch_23_0

- alias: Basement motion off
  trigger:
    - platform: state
      entity_id: binary_sensor.basement_hall_motion_sensor_9_0
      from: 'on'
      to: 'off'
      for:
        minutes: 5
    - platform: state
      entity_id: binary_sensor.basement_stairs_motion_sensor_24_0
      from: 'on'
      to: 'off'
      for:
        minutes: 5
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.basement_hall_motion_sensor_9_0
        state: 'off'
      - condition: state
        entity_id: binary_sensor.basement_stairs_motion_sensor_24_0
        state: 'off'
      - condition: state
        entity_id: light.basement_accent_lights_game_level_17_0
        state: 'off'
  action:
    - service: light.turn_off
      entity_id: light.basement_hall_light_level_13_0
    - service: switch.turn_off
      entity_id: switch.bar_cabinet_lights_switch_23_0

Lets look at what HA thinks is happening first. Does the log look like everything is happening as it should regardless of the fact that physically it isn’t? If it does then lets for the moment assume that HA is doing what it should be.

Have you checked the physical connections.

  1. Is the light screwed in good
  2. replace the bulb just for grins to see if the bulb is going bad.

At this point if HA says it’s doing things right, then I’m discounting any issues with the switch sending strange messages or the motion sensor being dirty because those would result in HA giving incorrect instructions to the switch.

Yes. According to the log, the correct events are firing and actions being taken.

It’s not the bulb. For one thing, it’s several bulbs on one circuit. Also, these are Linear z-wave switches, they fade on and off. It fades as it should when transitioning from off to on. The lights respond normally 100% of the time when actuated from the wall switch. Also, I can recreate this problem 100% of the time, completely reliably, by knowing exactly when I trigger the second motion sensor – and I know this because my motion sensors have little red LEDs in them that blink when you trigger them. The instant I see that red LED blink, the hall light turns off.

I’m starting to think there’s something funky going on in the z-wave layer. I have another switch in the same physical area that’s behaving oddly as well. I don’t know a ton about debugging z-wave but I’m going to mess around with Open z-wave control panel and see if I can spot anything odd in the raw z-wave events.

Do you need those condition statements in

  • alias: Basement motion off ?

They are already at the trigger statement

Are you using HA as your zwave hub, or are you using a wink hub or something in addition?

Does HA recognize that the light is turning off when it starts to turn off unexpectedly?

Have any new zwave hub type devices been introduced?

And just to refresh my memory, you haven’t upgraded HA or changed the code so nothing has changed there from when it was working properly. Right?

I have them in there because I need them as conditions – I only want the lights to turn off when BOTH motion sensors are in the ‘off’ state, and that other light I referenced is off. If I don’t have those as conditions, then the lights could turn off when just one of the motion sensors flips to inactive, and I don’t want that.

Good questions. For these devices in question, they are all linked directly to the Aeon z-stick I have plugged into my Raspberry Pi. I only am doing that with my basement devices; for the rest of my house, I’m using an MQTT bridge to a SmartThings hub which serves as the actual z-wave hub, which I’ve found to be much easier to manage devices on than Open Z-Wave. As part of my troubleshooting of this problem, I’m thinking about converting all my basement devices to the MQTT bridge → SmartThings setup.

There’s nothing in the activity log that indicates the light is turning off. In fact, the logbook lies and indicates the basement hall light is being turned off when it is supposed to, when in reality it’s already turned off when it wasn’t supposed to (which was not recorded in the log).

No. I haven’t touched my hardware setup in months.

The only thing that’s changed from when it was working properly has been HA version upgrades. The problem is I upgrade pretty much right away whenever a new version is available, and I don’t know when this first started (it may have taken me awhile to notice, and then I was too busy to correlate it to an upgrade date). However, I’ve done at least a half-dozen HA upgrades since then, and the problem has persisted, so I really don’t think it’s something b0rked with HA’s automation rules or else it would have been noticed by others by this point.

If HA is not logging anything when the light turns off, I really don’t think that it is HA turning it off. I don’t know much about zwave, but could another hub or software (maybe ST?) be doing that when the motion sensor fires? Try turning ST off and testing to see if the problem happens…