Awesome! Great job 
For now, I haven’t thought about this aspect yet 
Thinking about it now, what we want is:
- When a device is seen in a home, mark the user as « seen » in the home.
- A user can have multiple devices.
- A device belongs to only one user (otherwise it doesn’t make sense).
So the modeling we had until now in Gladys 3 is rather logical. (an attribute in the device table).
However, I think we should give a better name to this attribute, and above all present it in a completely different way in the UI, in Gladys 3 it was really not clear. For me, it should be a small UI dedicated to this presence detection.
The attribute in the device could be presence_detection_user_id (it’s not crazy, if someone has a better idea..)
We could for example make a « Presence Detection » service, which clearly explains:
"Some devices have the possibility of being detected when they are at your home: via a Bluetooth scan, a Wi-Fi network scan, or via their geolocation. Gladys can use this information to deduce whether you are at home, or on the contrary absent.
If you want Gladys to use the detection of certain devices to mark you as present at home, you need to indicate to Gladys the devices it can use to detect you.
For example: if you have a Bluetooth keychain attached to your keys, you can link this keychain to your user, and when it is seen via Bluetooth at your home, you will be marked as « present ». After a certain delay, if the device is no longer seen by Gladys, you will be marked as « absent ».
Select the devices that Gladys can use to detect you:
[List with checkboxes of devices with a presence deviceFeature that has reported information + indication of the last information reported + sort the list by the most recent information reported].
Example:
Fitbit Charge 2 (seen 2 min ago)
Nut Mini (seen 12 min ago)
Gladys can automatically mark you as absent if these devices are not detected after a certain time.
Enable automatic absence detection
(disabled by default)
Delay before absence: 15 minutes (select box with 4-5 options, like 5, 10, 15, 30, 45)
Development level
To summarize:
- An attribute in the « t_device » table, like
presence_detection_user_id, nullable and foreign key on t_user.id.
- A new category of device_feature that indicates that it is a « presence » device_feature of a device. Example: { category: « detection », type: « push », min: 1, max: 1 }
- An API route of GET device filtered by category.
- An API route of PATCH device.
- Two variables in DB, like « ABSENCE_DETECTION_ENABLED », and « ABSENCE_DETECTION_TIMEOUT ».
- A task in the scheduler (not yet developed) of Gladys 4 to go check the potential absence of a user. If we do everything in RAM (as is often the case in Gladys 4), a passage every minute should not be a problem.
What do you think? 