-
Notifications
You must be signed in to change notification settings - Fork 61
Description
I have a script that turns on a light when a person is detected and turns it off after a delay if detection stops.
The triggers are @state_trigger("binary_sensor.person_detected == 'on'") on one function and ...=='off' on the other, respectively.
Sometimes detections are very short, the sensor entity can change value within a second, and when that happens, my functions may be triggered in the wrong order even though the events are recorded in the correct order.
An example event straight from the events table of HA, with timestamps and formatted dates, first turning on then off:
on|1740940619.45155|2025-03-02 19:36:59|
off|1740940619.45191|2025-03-02 19:36:59|
And a snippet of the pyscript logs; the last two lines correspond to the above events, except the functions were called in the reverse order:
2025-03-02 19:36:49.551 INFO (MainThread) [custom_components.pyscript.file.lights.light_off] person detected OFF
2025-03-02 19:36:59.453 INFO (MainThread) [custom_components.pyscript.file.lights.light_off] person detected OFF
2025-03-02 19:36:59.456 INFO (MainThread) [custom_components.pyscript.file.lights.light_on] person detected ON
The result being that my light stays on indefinitely after such a "hiccup". Is this a bug or more like a fundamental system limitation where the order of triggers cannot be guaranteed at such short time intervals?
Thanks!