Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout behavior has changed #119

Open
kwerner72 opened this issue Nov 13, 2024 · 12 comments
Open

Timeout behavior has changed #119

kwerner72 opened this issue Nov 13, 2024 · 12 comments

Comments

@kwerner72
Copy link

In the new version 2.x the behavior of timeout has changed.

In version 1.x the timeout startet when no more motion was detected. Now it starts right after detecting a motion.
That means with version 2.x the screen will always turn off after given timeout, no matter if there is still motion detected.

@htilburgs
Copy link

Just my info:
when it does a countdown and then have again a motion detection, it resets the countdown and start over.
So in my case it works OK.

@kwerner72
Copy link
Author

Another motion detection of a PIR sensor can only happen if no motion was detected before. If there is an ongoing motion the sensor will not send another motion event. At least my sensor behaves this way.
So if you stay in front of a MagicMirror it will turn off after the configured amount of time and not if there is no more motion.

My timeout configuration is/was 10s.
In version 1.x the screen turned off 10s after no motion was detected.
In version 2.x the screen turns off 10s after a motion was detected, even if someone is still in front of it.

@bugsounet
Copy link
Owner

Hi, I'm having trouble understanding your problem.

It was programmed like this with PIR or Motion:

  • on MM start --> launch count down (ScreenLib)
  • When Pir (pirLib) or Motion (motionLib) detected --> reset count down (callback to screenLib)
  • When count down is over (00:00) --> turn off display (ScreenLib)

Library Notes:

  • ScreenLib v1/v2 engine is the same except any mode
  • pirLib in v2 engine have major change (new node library used) but result is the same -> send detected callback when a Pir motion is detected (Library ported from EXT-Pir)
  • motionLib in v2 is newer (Library ported from EXT-Motion)

Can you give me your configuration, if you find that the operation described is not the same?

@kwerner72
Copy link
Author

I've compared version 2.x with version 1.54 (SHA bb0b190) and found the difference.

In both versions PIR is set to mode 1.

Version 1.x is starting gpioSensor.py which queries presence in a loop once each second. If in this loop no more presence is detected the countdown starts.

Version 2.x is starting MotionSensor.py which sends only one presence detection event/message. Right after this message the countdown starts.

In version 2.x mode 0 there is also a loop for detecting motion. So maybe this loop is missing in mode 1?!

Instead of polling current status the 'when_no_motion' event could be used.
I've already implemented it in this commit.

You can see the difference also in the logs...
In version 1.54 the presence get detected every second:

[2024-11-14 10:15:45.091] [LOG]   [MMM-Pir] [LIB] [SCREEN] [POWER] Display from true ---> false 
[2024-11-14 10:16:12.153] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:12.154] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:12.155] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:12.156] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:12.192] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_SHOWING  
[2024-11-14 10:16:12.528] [LOG]   [MMM-Pir] [LIB] [SCREEN] Response PY -- Check State: 0 
[2024-11-14 10:16:12.530] [LOG]   [MMM-Pir] [LIB] [SCREEN] Display -- Actual: false - Wanted: true 
[2024-11-14 10:16:12.532] [LOG]   [MMM-Pir] [LIB] [SCREEN] Display ON. 
[2024-11-14 10:16:12.922] [LOG]   [MMM-Pir] [LIB] [SCREEN] Relay is ON 
[2024-11-14 10:16:13.129] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_POWERSTATUS true 
[2024-11-14 10:16:13.131] [LOG]   [MMM-Pir] [LIB] [SCREEN] [POWER] Display from false ---> true 
[2024-11-14 10:16:13.198] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 
[2024-11-14 10:16:14.157] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:14.159] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:14.161] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:14.165] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:15.170] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 
[2024-11-14 10:16:16.162] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:16.163] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:16.166] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:16.172] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:17.180] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 
[2024-11-14 10:16:18.162] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:18.164] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:18.166] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:18.168] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:19.173] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 
[2024-11-14 10:16:20.165] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:20.167] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:20.169] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:20.171] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:21.181] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 
[2024-11-14 10:16:22.165] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 10:16:22.167] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 10:16:22.168] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 10:16:22.169] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 10:16:23.172] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT { timer: '00:10', bar: 0 } 

In version 2.x the presence gets detected only once:

[2024-11-14 11:11:54.007] [LOG]   [MMM-Pir] [LIB] [SCREEN] [POWER] Display from true ---> false 
[2024-11-14 11:12:12.647] [LOG]   [MMM-Pir] [LIB] [PIR] Detected presence 
[2024-11-14 11:12:12.648] [LOG]   [MMM-Pir] [CALLBACK] Pir: PIR_DETECTED  
[2024-11-14 11:12:12.649] [LOG]   [MMM-Pir] [LIB] [SCREEN] Restart. 
[2024-11-14 11:12:12.650] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_PRESENCE true 
[2024-11-14 11:12:12.652] [LOG]   [MMM-Pir] [CALLBACK] Screen for Governor: WORKING 
[2024-11-14 11:12:12.653] [LOG]   [MMM-Pir] [LIB] [GOVERNOR] working Governor: ondemand 
[2024-11-14 11:12:12.689] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_SHOWING  
[2024-11-14 11:12:12.697] [LOG]   [MMM-Pir] [LIB] [GOVERNOR] Actual: powersave 
[2024-11-14 11:12:12.736] [LOG]   [MMM-Pir] [LIB] [GOVERNOR] working Set: ondemand 
[2024-11-14 11:12:13.023] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_POWERSTATUS true 
[2024-11-14 11:12:13.025] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_POWER true 
[2024-11-14 11:12:13.027] [LOG]   [MMM-Pir] [LIB] [SCREEN] [POWER] Display from false ---> true 
[2024-11-14 11:12:13.698] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT {
  timer: '00:10',
  bar: '1.000',
  dimmer: 1,
  availabilityPercent: 46.2,
  availability: '00:00:18'
} 
[2024-11-14 11:12:14.698] [LOG]   [MMM-Pir] [CALLBACK] Screen: SCREEN_OUTPUT {
  timer: '00:09',
  bar: '0.900',
  dimmer: 1,
  availabilityPercent: 47.5,
  availability: '00:00:19'
} 

@bugsounet
Copy link
Owner

ha ok pir.mode: 1 !
I'm thinking that you says pir.mode:0

I don't use this mode in my prod mirror :/
I will inspect.
Warn with your purpose, you will broke mode 0 ;)

@yosland9
Copy link

I'm having the same issue in mode: 1 as well.

@bugsounet
Copy link
Owner

I finish to lint all my modules and i will take a look

@bugsounet
Copy link
Owner

@kwerner72 can you test current dev version and tell me if better ?

@kwerner72
Copy link
Author

Unfortunately the dev branch turns off screen after the timeout, regardless if there is still motion detected.

You may test the desired behaviour in MotionSensor.py, by deactivating the MotionSensor from gpiozero and just printing "Motion" and "NoMotion".
If "NoMotion" is delayed more than the configured timeout, the screen should not turn off.

@bugsounet
Copy link
Owner

bugsounet commented Dec 6, 2024

In all case there no change

v1.x: python code
v2.3: python code

Exec code is the same:
v1.x: There
v2.3: There

Callback is the same when Detected
v1.x: There
v2.3: There

In my case, i can't reproduce it and works as i code it

@kwerner72
Copy link
Author

It really looks quite similar. Though there is an important change in pirLib.js from 1.x to 2.x

In v1.x pirLib is using gpioSensor.py in mode 1 (line 90)
In v2.x pirLib is using MotionSensor.py in mode 1 (line 73)

So what you really need to compare is gpioSensor.py and MotionSensor.py
First one polls current motion state every second, while second just sends/prints a single motion event.

@bugsounet
Copy link
Owner

RPi.GPIO is not updated since 2022/02/06 (see there)

  • It don't works with pi5
  • It have some trouble with last OS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants