Motion sensor sends only first state change

I have a “LSC Smart Connect” WiFi motion sensor that I use with Tuya integration. Problem is the sensor only sends one “on” or “Detected” state and I use a Python script to manually change the state of the binary sensor to “off” after set amount of time.

This works for the front porch when someone walks to the door and it only needs to work for 5 minutes, but when I want to have the state ‘refreshed’ when someone stays at the door for more than 5 minutes it still turns off the lights and at next ‘movement’ detection it lights them up again.

I tried the suggestions from here (Last time motion was detected (not last changed nor cleared)) but it seems this sensor doesn’t report intermediate states, nor it reports every time it detectcs motion, or at least I can’t find the place and the type of event.

Anyone has any suggestions?

Thanks!

It would help to post your code. Or you can try another example.

Sure I can post the code. I wonder if putting the first automation to “restart” mode will make a difference? Problem is I can’t see the motion sensor sending an event when the HA binary sensor is already “on”.

  1. This is for turning the lights on when motion is detected:
alias: Koridor lights up when motion
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.smart_motion_sensor
    to: "on"
condition: []
action:
  - type: turn_on
    device_id: 1020cece6c4057e922f4e3ef238a3d62
    entity_id: light.ap_9_koridor_kartina_1
    domain: light
    brightness_pct: 100
  - type: turn_on
    device_id: 9100e1581144d0d53fd2421600df1616
    entity_id: light.9_2
    domain: light
    brightness_pct: 100
mode: single
  1. This is to manually switch the binary sensor to off after some time:
alias: Koridor set motion sensor to off in 15 minutes
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.smart_motion_sensor
    to: "on"
condition: []
action:
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - service: python_script.set_state
    data_template:
      entity_id: binary_sensor.smart_motion_sensor
      state: "off"
mode: single
  1. And this is to turn off the lights is motion sensor is off:
alias: Koridor lights off if there is no motion
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.smart_motion_sensor
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - type: turn_off
    device_id: 1020cece6c4057e922f4e3ef238a3d62
    entity_id: light.ap_9_koridor_kartina_1
    domain: light
  - type: turn_off
    device_id: 9100e1581144d0d53fd2421600df1616
    entity_id: light.9_2
    domain: light
mode: single

It seems this problem has been around for a while and remains outstanding.

Your code manually turns the sensor off after 15 minutes, and this (presumably) triggers the lights to be turned off immediately (since h/m/s are all zero). You could try turning the sensor off after 10 minutes and change the “for” of the “no motion” script to require it to be off for 5 minutes. This would give plenty of time for new motion to ‘cancel’ the off automation.

I already tried this and it didn’t work. What I didn’t try, and will try now, is to put the Automation in ‘restart’ mode. Hopefully this will ‘restart’ the ‘no motion’ Automation if the binary sensor gets from ‘on’ to ‘off’ to ‘on’ again before the ‘no motion’ Automation timer expires.

At least this is how I understand it according to the Automation Modes - Home Assistant article.

TESTED and not working. Even if the ‘sensor to off’ automation is set to 5 min and ‘no motion’ automation is set to trigger after two minutes and on ‘restart’ mode, the lights still turn off after 7 minutes total. No matter if there is motion or not infront of the sensor.

This however, might be yet another layer of limitation of the sensor itself.