afuerhoff / ioBroker.fb-checkpresence

The adapter checks the presence of family members over the fritzbox. Also you can have a list of all devices in the Fritzbox. Unknown devices are reported in the blacklist.
MIT License
23 stars 7 forks source link

Force Update of Family Member states on demand #136

Closed kschaumann closed 2 years ago

kschaumann commented 2 years ago

For a notification, if opening a door is not unexpected it would be very nice if it would be possible to force the update of the absence states on demand. Use case:

As far as I understand, the interval is set in the adapter, not in the FB. So a request "out of interval" might be possible. Maybe you could prevent a misuse by a timeout after which this update could be triggered again.

afuerhoff commented 2 years ago

Hello, I have uploaded a test version on Github. Please install and test it. With following script you can trigger the prsence function. The result is true or false. The function is blocked for 10 seconds after triggering it.

sendTo('fb-checkpresence.0', 'triggerPresence', {} , function (result) { log(result, 'info'); });

kschaumann commented 2 years ago

I've installed the Version from gitHub an triggerd the function as shown above. The callback logs "true", so the presenceState should be updated. My expectation where, that the time info of the states will changed by this, but they stay as before after calling this method.

Case is in fact, that nothing changes in my test now (nobody leaves, nobody returnes to home). But when the adapter periodically updates the state, the times are changed - I think!. By calling the 'triggerPresence' function not, as it seams to me.

javascript.0 2022-07-14 09:43:14.507 info script.js.Benachrichtigungen.Schuppen: Bild per telegram verschickt.
javascript.0 2022-07-14 09:43:12.506 info script.js.Benachrichtigungen.Schuppen: Send image: /opt/iobroker/temp/cam/cam1_1.jpg
javascript.0 2022-07-14 09:43:12.505 info script.js.Benachrichtigungen.Schuppen: Schuppen geöffnet, aber Haustür false oder Anwesenheit false wurden NICHT geändert
javascript.0 2022-07-14 09:43:12.504 info script.js.Benachrichtigungen.Schuppen: Compare last Event 14.07.2022 07:33:23 with timeslot 14.07.2022 09:40:12 => false
javascript.0 2022-07-14 09:43:12.503 info script.js.Benachrichtigungen.Schuppen: Compare last Event 14.07.2022 09:24:07 with timeslot 14.07.2022 09:40:12 => false
javascript.0 2022-07-14 09:43:12.502 info script.js.Benachrichtigungen.Schuppen: Update presence State: true
javascript.0 2022-07-14 09:43:07.962 info script.js.Benachrichtigungen.Schuppen: Bild 3 gespeichert.
javascript.0 2022-07-14 09:43:04.900 info script.js.Benachrichtigungen.Schuppen: Bild 2 gespeichert.
fb-checkpresence.0 2022-07-14 09:43:02.495 debug history USER3 cntHistory: 7
fb-checkpresence.0 2022-07-14 09:43:02.477 debug history cntActualDay: 7
fb-checkpresence.0 2022-07-14 09:43:02.374 debug history USER2 cntHistory: 5
fb-checkpresence.0 2022-07-14 09:43:02.360 debug history cntActualDay: 5
fb-checkpresence.0 2022-07-14 09:43:02.338 debug history USER1 cntHistory: 5
fb-checkpresence.0 2022-07-14 09:43:02.323 debug history cntActualDay: 5
javascript.0 2022-07-14 09:43:01.915 info script.js.Benachrichtigungen.Schuppen: Bild 1 gesendet.
javascript.0 2022-07-14 09:43:01.914 info script.js.Benachrichtigungen.Schuppen: Bild 1 gespeichert.
javascript.0 2022-07-14 09:43:01.682 info script.js.Benachrichtigungen.Schuppen: registered 1 subscription and 0 schedules
javascript.0 2022-07-14 09:43:01.681 info script.js.Benachrichtigungen.Schuppen: START CALLING UPDATE PRESENCE

At "START CALLING UPDATE PRESENCE" the above code is executed, and with "script.js.Benachrichtigungen.Schuppen: Update presence State: true" it returnes, but the states are all unchanges in time:

image

the time here is the one at which the adapter was installed and get the first updates.

kschaumann commented 2 years ago

Ok, I've rechecked. The fb-checkpresence states are not updated as I expected by the periodically check. The "Zeitstempel" ist not Updates during this task, only if the "Zuletzt geändert" also changes.

Themse to my that this behavior is other than in most other adapters, but I'm far away from expert state to rate this.

So this is OK for me, an provides the function I needed! Many thanks!

kschaumann commented 2 years ago

I can now verify, that the states are not updated after calling this method.

2022-07-15 07:33:54.566  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Schuppentuer Status aenderung
2022-07-15 07:33:54.568  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: START CALLING UPDATE PRESENCE
2022-07-15 07:33:54.809  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Bild 1 gespeichert.
2022-07-15 07:33:54.809  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Bild 1 gesendet.
2022-07-15 07:33:55.527  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 3
2022-07-15 07:33:55.542  -  debug   : fb-checkpresence.0 (19769) history USERB cntHistory: 4
2022-07-15 07:33:55.568  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 0
2022-07-15 07:33:55.584  -  debug   : fb-checkpresence.0 (19769) history USERC cntHistory: 2
2022-07-15 07:33:55.655  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 3
2022-07-15 07:33:55.670  -  debug   : fb-checkpresence.0 (19769) history USERA cntHistory: 5
2022-07-15 07:33:57.533  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 3
2022-07-15 07:33:57.547  -  debug   : fb-checkpresence.0 (19769) history USERB cntHistory: 4
2022-07-15 07:33:57.575  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 0
2022-07-15 07:33:57.590  -  debug   : fb-checkpresence.0 (19769) history USERC cntHistory: 2
2022-07-15 07:33:57.612  -  debug   : fb-checkpresence.0 (19769) history cntActualDay: 3
2022-07-15 07:33:57.627  -  debug   : fb-checkpresence.0 (19769) history USERA cntHistory: 5
2022-07-15 07:33:57.629  -  debug   : fb-checkpresence.0 (19769) loop family ends after 0,596630087 s
2022-07-15 07:33:57.778  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Bild 2 gespeichert.
2022-07-15 07:33:58.525  -  info    : javascript.0 (1043) script.js.Automatismen.VorgartenCarportLicht: Ignore (Cam.Carport.MotionDetect) Event, cause it is daytime
2022-07-15 07:33:58.525  -  info    : javascript.0 (1043) script.js.Automatismen.VorgartenCarportLicht: checkForSwitchOff triggerd, but light is false
2022-07-15 07:33:58.526  -  info    : javascript.0 (1043) script.js.Automatismen.VorgartenCarportLicht: Reset Trigger hm-rega.0.10438
2022-07-15 07:34:00.802  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Bild 3 gespeichert.
2022-07-15 07:34:05.675  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Update presence State: true
2022-07-15 07:34:05.676  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Compare last presence Event 15.07.2022 07:30:54 with timeslot 15.07.2022 07:31:05 => false
2022-07-15 07:34:05.677  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Compare last haustuer Event 15.07.2022 07:24:58 with timeslot 15.07.2022 07:31:05 => false
2022-07-15 07:34:05.677  -  info    : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Schuppen geöffnet, aber Haustür false oder Anwesenheit false wurden NICHT geändert

At 07:33:54:568 the function is triggered and returned at 07:34:05:675 with "true" as result. But the states are updated far later: image as example the "fb-checkpresence.0.USERA.comming" state.

As you could see in the last log messages: 2022-07-15 07:34:05.676 - info : javascript.0 (1043) script.js.Benachrichtigungen.Schuppen: Compare last presence Event 15.07.2022 07:30:54 with timeslot 15.07.2022 07:31:05 => false At 07:34:05.675 the *.lc of the state (fb-checkpresence.0.absentCount) was "15.07.2022 07:30:54", it could not be updated from an event which returned at 07:34:05.675

So a check if the presence has changed will return false, if it is called from the callback. In current case, there is a difference of nearly 50 seconds between call of "triggerPresence" and the update of the states. My expectation was, that if teh method return with true, the states are updated.

In a further Test, I have just disabled my WLAN of my Mobile for five minutes. Then go to the door, reactivate WLAN and recheck that the mobile is back in WLAN. Then open the door and the result is the same, the state "fb-checkpresence.0.absentCount" was not updated during the call of "triggerPresence", after return true, the state keeps the same as before reactivate WLAN of my mobile:

Consumption:

javascript.0 2022-07-15 09:58:15.497    info    script.js.Benachrichtigungen.Schuppen: START CALLING UPDATE PRESENCE
javascript.0 2022-07-15 09:58:26.472    info    script.js.Benachrichtigungen.Schuppen: Update presence State: true
fb-checkpresence.0 2022-07-15 09:58:46.682  info    newActive USERA true

20 seconds delay here

afuerhoff commented 2 years ago

The question is if the state in the fritzbox was changed when you trigger the function. There is a delay to register the device in the fritzbox. It depends on the fritzbox not the adapter. Has you enabled the filter function for a family member, than you have an additional delay through the filter time setting.

For a test: Please set the family interval e.g. to 600s. Switch the filter off. Then switch off wlan from the cell phone. I think after minimum 10s (registration time) it should be registrated in the fritzbox. Then trigger the function. Then look at the state "presence". It should be changed from true to false.

Remember if you trigger the function and the state in the fritzbox is not changed then you have to wait another 10s to trigger again. The return value true means that the function is triggered. False menas the function is not triggered due to the 10s delay time.

PS: I have no problems with the function.

afuerhoff commented 2 years ago

Hello, I have integrated a log message if the function is triggered. Please install the new version from github. It is easier to see, which values are read from the fritzbox.

afuerhoff commented 2 years ago

Hello, were you able to test the new version?