Z-Wave PIR and automations

Hi Community!

I’ve been struggling for several years with this same problem and I’m not sure if it’s a matter of not seeing the forest through the trees.

I have several Z-Wave PIR sensors and they work perfectly fine for me. The problem I have is they all have a “cool-down” period before the binary_sensor that represents it changes states from ON/OFF and in my case, 30 seconds. Changing the default has by non-scientific observation impacted battery life and is the default from the manufacturer.

My problem is how do I align to this? I’ve tried dozens of methods to work around this (and with it) such as parallel, queued and restart mode for my automations but every once in a while, I hit that 30 second gap where the automation won’t fire because it’s still in a non-matching state and as a result, lights won’t come on after a separate automation which waits for OFF state turns them off.

IE: I enter a room, PIR picks me up, makes several OR checks (lux,elevation,below_horizon) and then turns on the lights if it should. 30 seconds later, another automation sees the OFF state for 5 seconds and turns off the lights.

The 5 seconds is new but it makes no difference if it waits or not and was added to accommodate people moving around in the room and not having the lights turned off while they’re there.

This really bugs me. Can someone see the tree through the forest for me here?

- id: lights_auto_mudroom_on
  alias: Lights Auto Mudroom On
  trigger:
    - platform: state
      entity_id: binary_sensor.mudroom_pir_motion
      to: "on"
  mode: restart
  condition:
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ (state_attr('sun.sun','elevation')|int) <= 0 }}"
        - condition: template
          value_template: "{{ (states('sensor.mudroom_pir_lux')|int) <= 12.5 }}"
        - condition: template
          value_template: "{{ (states('sun.sun') == 'below_horizon') }}"
    - condition: and
      conditions:
      - condition: state
        entity_id: binary_sensor.mudroom_dw_open # door is not open, light would come on if it was
        state: "off"
      - condition: state
        entity_id: light.mudroom # room light group is off
        state: "off"
      - condition: state
        entity_id: light.mudroom_door # light above door is off
        state: "off"
  action:
    - service: scene.turn_on
      data_template:
        entity_id: >
          {% if now().hour >= 21 or now().hour <= 7 %}
            scene.mudroom_nightlight
          {% else %}
            scene.mudroom_bright
          {% endif %}
- id: lights_auto_mudroom_off
  alias: Lights Auto Mudroom Off
  trigger:
    - platform: state
      entity_id: binary_sensor.mudroom_pir_motion
      to: "off"
      for: "00:00:05"
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: light.mudroom # room light group is on
        state: "on"
      - condition: state
        entity_id: light.mudroom_door # light above door is on
        state: "on"
  action:
    - service: light.turn_off
      entity_id:
        - light.mudroom_window
        - light.mudroom_door
        - light.mudroom

I should note that normally I only have the light above the door turn on, not both lights in the room. They’re HUE lights and I have the second one installed mostly as a relay in physical space of my layout of the house which as a side-note is unfortunate because I have several like this used pretty much in the same vein as a Z-Wave extender which I also use.

In all cases of the described gap, both lights are off and entering the room the lights don’t turn on. I initially was basing it on Lux only to discover that the Z-Wave update is 90 seconds so next best metric was the sun thus the mighty OR condition.

Really thought I had this licked for sure this time.

Many thanks in advance!

I just ensure I don’t turn off light before any cooldown has expired. Seems to work well enough.

Hi!

The problem I’ve run into with that is that at night time, one of the light sets affected is a hallway leading off into bedrooms and even with “nightlight” some people still wake up so I’d like them off as soon as possible otherwise I’m waiting 30 seconds for lights to turn off.

Also seems kind of non-eco friendly to keep the lights on longer than they need to be. Maybe I’m old-fashioned that way :slight_smile:

Yeah increasing this time should do it:

  trigger:
    - platform: state
      entity_id: binary_sensor.mudroom_pir_motion
      to: "off"
      for: "00:00:35"

Also you don’t need both these conditions, either one alone will do:

        - condition: template
          value_template: "{{ (state_attr('sun.sun','elevation')|int) <= 0 }}"

        - condition: template
          value_template: "{{ (states('sun.sun') == 'below_horizon') }}"
1 Like

Then you need to buy better sensors or wire power to your existing sensors so you can keep the short cool-down time.

1 Like

Perhaps a different strategy is in order then for the hallway at night.

I appreciate the light disturbance scenario when trying to sleep.

I grabbed a “neon” light strip with silicon cover over it and ran it along baseboards. At 1% brightness on a ShellyRGBW is consumes <1W and is more than bright enough to navigate. Think, “runway strip lighting”.

The Philips Hue motion sensor is 8 sec natively. Two AAA’s and still lasts forever.

Yes, exactly that.

Here are the setting of my Fibaro Eye’s, having no any trouble as described above:

Appreciate all the responses. My takeaway from this thread was better hardware, different approach (that’s a cool idea btw, I’ve seen it under kitchen cabinets and gaming rooms isle-style and movie theaters) or provide a constant power source to allow faster resets as battery would be a non-issue.

I’m currently testing one device (mudroom) with altered Z-Wave settings to see if previous findings were still the same (so far, it’s not but it’s only 24 hours.) For my particular devices (Neo CoolCam) the default ON/OFF duration is 30 seconds by OEM.

I Googled the device itself, read other a lot of discussions and documentation out there and saw some defaults were 60 seconds for some devices and I would think in different uses I could see why it may be set that way. My use-case is high-traffic areas/entrances so there’s a lot of movement/doors/lights being acted upon.

However it also has a re-trigger setting of 8 seconds by default. I altered the ON/OFF duration to 10 seconds (+/- either way I figure) and so far, it’s been working until someone in the house hits the possible 15 second gap (at least, that to me seems worst case as I’ve added the additional 5 seconds so 10 + 5 before flipping ON/OFF and activity within 8 seconds allows the device to re-trigger.

At least, this is how I understand it to work. So far, it seems to be working fine. As a plus, the lights turn off a lot sooner than before (it’s noticeable versus other non-test areas) and activity in the area is producing the expected results.

My only concern is battery life. These use CR123A batteries and it’s really hard to find GOOD inexpensive sources of these online (that don’t die after a month or two) and the usual suspects locally don’t carry these kinds of batteries.

EDIT: I should note previous tests of this nature were not done using the existing Z-Wave stack so it’s a totally different beast now ((zwavejs2mqtt: 6.1.1 zwave-js: 8.9.0-beta.1)) vs way-back-then.

I do have some NeoCoolcams too, and they indeed are 30 seconds and can’t go lower. But even with them, I have no problems at al.
But that’s, because any light, i switch on with a motion detector, is programmed to stay on for at lest two minutes.
That way:

  1. the lights do not go out that fast, when someone is still in the zone, but does not move
  2. there is no annoyance from lights going on off like a stroboscope
  3. there is enough time to re-trigger and ad the two minutes again, so the lights stay on as long, as someone is there.

With those settings and the temp/iluminance reports set to most frequent possible, the Neo Coolcams are running now for 5 months and the batteries are still 100%

They can go lower:

I must either be a masochist or just obtuse but I don’t want my lights on longer than they need to be and 30 seconds feels like forever. 2+ minutes must be an eternity :slight_smile:

I also have the use-case where I don’t want lights going off on people (hence the additional 5 seconds in a OFF state) but they don’t strobe; it’s always that circumstance where I’ll go into the room (more often than not, my wife not me) and forget something and go back into it and the lights wouldn’t come on.

Made me real popular at first (and not Gandalf-the-wizard-popular) thus all the re-inventing the wheel scenarios only to find out my wife was left in the dark (literally) but so far the battery is 100% and the lights/automations are firing much faster that fits my use-case.

1 Like

And here I am with my light out delay of 2 hours :yum:

2 Likes

@chrisw I know this is not quite what you after but it might be useful nonetheless …

My hallway light which triggers via either a ZWave PIR or a Zigbee doorbell and has been working flawless for a couple of years now. The key part is the wait_for_trigger with a 3 min delay that waits for the PIR to turn off before turning off the light. If the PIR re-triggers during the 3 min delay then the automation restarts.

- id: '1998183160475'
  alias: Hall Light Control
  description: Controls hall light based on motion sensor and doorbell
  trigger:
  - entity_id: binary_sensor.neo3
    platform: state
    to: 'on'
  - device_id: f12a042cd06945cf8de93be563ccfc12
    domain: zha
    platform: device
    subtype: remote_button_short_press
    type: remote_button_short_press
  condition:
  - condition: or
    conditions:
    - after: sunset
      after_offset: -00:30:00
      condition: sun
    - before: sunrise
      before_offset: 00:30:00
      condition: sun
    - type: is_illuminance
      condition: device
      device_id: 607cb4197754ca295c3646d022602574
      entity_id: sensor.neo3_luminance
      domain: sensor
      below: 25
  action:
  - data:
      entity_id: switch.sonoff01
    entity_id: switch.sonoff01
    service: switch.turn_on
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.neo3
      to: 'off'
      for: 00:03:00
  - data:
      entity_id: switch.sonoff01
    entity_id: switch.sonoff01
    service: switch.turn_off
  initial_state: 'on'
  mode: restart

One possible way to achieve what you are after would be to use a dimable light with the above code so that the light can stay on longer than the cooldown period however it appears more or less off because it has been dimmed after whatever short duration you need.

1 Like

@Jonah1970 The wait_for_trigger seems to be the secret sauce to my problem. Very much appreciated. I had two automations (one to handle ON one to handle OFF) which I was able to bring down to a single automation (and thanks to @tom_l for the condition cleanup advice.)

My PIRs now reset state every 10 (instead of 30) seconds and waits an additional 1 minute after OFF state before turning the lights off and with the short reset time, it works. Lights stay on when people enter and move about the room and nobody has been left in the dark so far :slight_smile:

Battery seems to not be impacted in any way based on the Z-Wave dashboard. I’ll probably change the timings a bit to make it turn the lights off sooner but I think this might be solution for me.

- id: lights_auto_mudroom_on
  alias: Lights Auto Mudroom On
  trigger:
    - platform: state
      entity_id: binary_sensor.mudroom_pir_motion
      to: "on"
  mode: restart
  condition:
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ (states('sensor.mudroom_pir_lux')|int) <= 12.5 }}"
        - condition: template
          value_template: "{{ (states('sun.sun') == 'below_horizon') }}"
  action:
    - service: scene.turn_on
      data_template:
        entity_id: >
          {% if now().hour >= 21 or now().hour <= 7 %}
            scene.mudroom_nightlight
          {% else %}
            scene.mudroom_bright
          {% endif %}
    - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.mudroom_pir_motion
        to: 'off'
        for: 00:01:00
    - service: light.turn_off
      entity_id:
        - light.mudroom_window
        - light.mudroom_door
        - light.mudroom