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
1 Like

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.

I’m using the same python script to reset the state of my LSC motion sensor.

Which by the way is supposed to have a 5 minutes grace periode but I noticed on mine it’s shorter (haven’t timed it though).

I combined turning the light on, resetting the sensor state and turning the light off all in one automation :sunglasses:

And by setting it in “restart” mode the time in which the light stays on gets extended if aditional motion is detected within that time.

alias: Badkamer Licht Auto aan/uit
description: ""
trigger:
  - type: motion
    platform: device
    device_id: a93239bfea1eefe1509384777ae1facf
    entity_id: binary_sensor.badkamer_beweging
    domain: binary_sensor
condition: []
action:
  - service: light.turn_on
    metadata: {}
    data:
      kelvin: 2500
      brightness_pct: 100
    target:
      entity_id: light.badkamer
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: python_script.set_state
    data_template:
      entity_id: binary_sensor.badkamer_beweging
      state: "off"
  - delay:
      hours: 0
      minutes: 7
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.badkamer
mode: restart

When motion is detected the light is turned on.
After 3 minutes the state of the motion sensor is changed to “off”.
After 7 more minutes the light is turned off.
Unless another motion is detected before that. The automation will then restart, which also restarts counting the minutes.

I noticed the LSC motion sensor is turned back on when Home Assistant (re)starts.
So I made an additional automation to reset the sensor at the start of Home Assistant :muscle:

alias: Reset motion sensors
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - service: python_script.set_state
    data_template:
      entity_id: binary_sensor.badkamer_beweging
      state: "off"
mode: single