pantherale0 / ha-familysafety

Microsoft Family Safety Home Assistant integration
MIT License
5 stars 1 forks source link

Screen time values do not match Family Safety app #34

Closed manonstreet closed 4 months ago

manonstreet commented 4 months ago

System Health details

System Information

version core-2024.2.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.1
os_name Linux
os_version 6.1.74-haos
arch x86_64
timezone America/New_York
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4711 Installed Version | 1.34.0 Stage | running Available Repositories | 1393 Downloaded Repositories | 29
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | August 15, 2024 at 8:00 PM relayer_connected | true relayer_region | us-east-1 remote_enabled | true remote_connected | true alexa_enabled | true google_enabled | false remote_server | us-east-1-1.ui.nabu.casa certificate_status | ready instance_id | ca203c98f2a9400796633ff5a0d45a6e can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 11.5 -- | -- update_channel | stable supervisor_version | supervisor-2024.01.1 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 116.7 GB disk_used | 19.2 GB healthy | true supported | true board | generic-x86-64 supervisor_api | ok version_api | ok installed_addons | Node-RED (17.0.6), Zigbee2mqtt (1.18.1-1), File editor (5.8.0), AirSonos (4.2.0), Glances (0.21.0), Home Assistant Google Drive Backup (0.112.1), Mosquitto broker (6.4.0), Duck DNS (1.15.0), Studio Code Server (5.15.0), Tautulli (4.0.1), Z-Wave JS UI (3.3.2), Tailscale (1.58.2.0), Advanced SSH & Web Terminal (17.1.0), ESPHome (2023.12.9), AdGuard Home (5.0.3), Ring-MQTT with Video Streaming (5.6.3)
Dashboards dashboards | 2 -- | -- resources | 17 views | 23 mode | storage
Recorder oldest_recorder_run | February 4, 2024 at 10:05 PM -- | -- current_recorder_run | February 11, 2024 at 12:35 PM estimated_db_size | 139.72 MiB database_engine | sqlite database_version | 3.44.2

Checklist

Describe the issue

The Used Screen Time sensor value differs from that as reported via the Family Safety website and iOS app.

Note: I have 2 kids with separate microsoft accounts. In both cases their used screen time sensor is inaccurate.

Screenshot 2024-02-11 at 1 02 33 PM

Screenshot 2024-02-11 at 1 13 47 PM jpeg

Reproduction steps

  1. Install, configure and authenticate integration
  2. Compare sensor value reported by integration vs value reported directly by Family Saftey

Debug logs

Not supplying debug logs unless requested by integration author. I don't believe this is specific to my setup.

Diagnostics dump

No response

pantherale0 commented 4 months ago

Hi,

This is pretty odd and not something I've experienced myself:

Screenshot_20240211_182221_Home Assistant

Can you show all the attributes please?

Thanks

manonstreet commented 4 months ago

To note, I just installed this integration for the first time, after this time was used. I don't think it will matter, but will also check again tomorrow after everything resets. Here are all attributes:

discord: 207 Google Chrome: 207 overwolf: 0 openjdk platform binary: 0 Minecraft* (version hidden from driver): 57 Krita (x64): 40 1Password: 4 Minecraft Launcher: 3 AimLab_tb.exe: 0 Blu-ray Player: 0 credential manager ui host: 0 cs2.exe: 0 Dev Home: 0 Disney+: 0 easy anti-cheat bootstrapper (eos): 0 elden ring™: 0 EPG: 0 epicgameslauncher: 0 Fabric Installer: 0 Fortnite: 0 gamingservicesui.exe: 0 hass.agent: 0 installer for mcreator 2023.4.52316: 0 King's Quest: 0 LEGO® DIMENSIONS™: 0 LEGO® MARVEL Super Heroes: 0 'LEGO® STAR WARS™: The Force Awakens': 0 LEGO® Worlds: 0 Mail and Calendar: 0 malwarebytes tray application: 0 MCreator 2023.4: 0 Microsoft 365 (Office): 0 Microsoft Clipchamp: 0 Microsoft Edge: 0 Microsoft Photos: 0 Microsoft Sticky Notes: 0 Microsoft Store: 0 Microsoft Teams: 0 Microsoft To Do: 0 Microsoft Whiteboard: 0 Microsoft Xbox Payment Options: 0 minecraft launcher: 0 Minecraft Story Mode: 0 'Minecraft: Forge Loading...': 0 'Minecraft: Story Mode - Season Two': 0 Mixed Reality Portal: 0 Movies & TV: 0 MSN Weather: 0 News: 0 Ori and the Will of the Wisps: 0 Outlook for Windows: 0 Paint: 0 Phone Link: 0 Plex for Xbox: 0 Power Automate: 0 Raft.exe: 0 Rayman Legends: 0 roblox: 0 Roblox Player: 0 Rocket League®: 0 RustClient.exe: 0 servicehub.threadedwaitdialog.exe: 0 Skylanders™ Imaginators: 0 So Many Me: 0 Solitaire & Casual Games: 0 Spotify Music: 0 Steam: 0 steam client webhelper: 0 Terraria: 0 The Orange Box: 0 TotallyAccurateBattlegrounds.exe: 0 Unity: 0 Unity Hub: 0 Visual Studio 2022: 0 Windows Calculator: 0 Windows Clock: 0 Windows Feature Experience Pack: 0 Windows Maps: 0 Windows Media Player: 0 Windows Notepad: 0 Windows Security: 0 Windows Sound Recorder: 0 Windows Terminal: 0 Xbox: 0 Xbox Captures: 0 Xbox Events: 0 Xbox Original Avatars: 0 Zoom: 0 Device usage NOAH-RIG: 207 Xbox console: 0

pantherale0 commented 4 months ago

I'm not sure what's happened here, but Microsoft is reporting device usage for NOAH-RIG as 207 minutes when we are polling the API.

Device usage
NOAH-RIG: 207
Xbox console: 0

Which means the value home assistant is showing is expected. In fact it almost looks like the mobile app is showing old / bad data.

Only way to know for certain though, how long has your child used their device? (Without checking Home Assistant or the Family Safety app)

manonstreet commented 4 months ago

My son is on his computer right now, and his usage is increasing across both this integration, and the Family and Safety apps.

The integration is now showing: NOAH-RIG: 247

I also tried logging into the website (instead of the iOS app but for the record, they match) here. And I see: 1 h 53 min screen time today Updated 21 minutes ago

pantherale0 commented 4 months ago

It will be difficult to diagnose this I think, it seems specific to your setup, not something I've experienced at all in the 6~ months I've been using it, and I've received no other reports.

I don't do any additional manipulation to the used time sensor in the integration or the python module, what you see above in the entity attributes is exactly what Microsoft is returning.

The only thing I can think of is that it's detecting the wrong screen time report (they are accessed via a separate API endpoint), and the module is unable to read the right data, but this shouldn't be possible as the API returns screen time against the device ID which I use to pull the data together. If that was the case though, the behaviour you are seeing (with both the mobile app and HA screen time values increasing) wouldn't be possible.

Would recommend checking again tomorrow and measuring "the old fashioned way" to see.

manonstreet commented 4 months ago

I think this may have to do with the forced migration to the new Family Safety version. Let me get everything updated and report back.

manonstreet commented 4 months ago

I am not sure if MS is having issues or if there is something on my side. I got my Family Safety account migrated to the new version (MS established a deadline of 2/29), and upgraded my iOS apps. I removed this integration and attempted to reinstall. I now get a "Failed to set up" on the integration and in the logs I see: Aggregator error occured. This is an upstream issue with Microsoft and is usually temporary. Try reloading the integration in 15 minutes.

and the related:

  File "/config/custom_components/family_safety/__init__.py", line 27, in async_setup_entry
    familysafety = await FamilySafety.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyfamilysafety/__init__.py", line 24, in create
    self.accounts = await Account.from_dict(self.api, accounts.get("json"))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyfamilysafety/account.py", line 186, in from_dict
    await self.update()
  File "/usr/local/lib/python3.12/site-packages/pyfamilysafety/account.py", line 37, in update
    await self.get_screentime_usage()
  File "/usr/local/lib/python3.12/site-packages/pyfamilysafety/account.py", line 99, in get_screentime_usage
    device_usage = await self._api.send_request(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyfamilysafety/api.py", line 96, in send_request
    raise AggregatorException()
pyfamilysafety.exceptions.AggregatorException: An upstream aggregator error occured.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 444, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/family_safety/__init__.py", line 39, in async_setup_entry
    raise CannotConnect from err
custom_components.family_safety.CannotConnect

I've retried numerous times since last night up through this afternoon - same error. The website and mobile apps appear to be working fine. I am wondering the APIs change?

pantherale0 commented 4 months ago

To be honest I stopped using the family safety mobile app a while ago and don't even have it installed anymore so didn't realise they've released a new version.

I'll take a look and see what's happened.

pantherale0 commented 4 months ago

Ahh, a number of new endpoints have appeared which look to function better than the previous ones, seems that once you upgrade to the "new experience", the old endpoints aren't valid anymore.

I'll upgrade the Python module to fix :+1:

pantherale0 commented 4 months ago

Ok, new update is available, can you try with 1.1.1 please?

Also, I believe I found the reason for the screen time issue, but as I can't replicate could you test?

Thanks

manonstreet commented 4 months ago

I installed v1.1.1, created a new integration and get prompted for OAuth response. I copied the URL from the integration's github page, and pasted the OAuth Response URL in the box. It receive an error invalid_auth

pantherale0 commented 4 months ago

You need to navigate to that URL as per the instructions and sign in with your Microsoft account when prompted. You then get redirected to a blank page, the URL of that page is what you need to copy.

pantherale0 commented 4 months ago

Also, worth noting just in case anyone else is reading this, the access token for previous versions should still be valid so you won't need to go through a reconfiguration when updating.

manonstreet commented 4 months ago

Understood. I did this action previously without issue. I was noting that after I removed the integration, and tried to redeploy, I could not due to the change in API endpoints. Now that the integration has been updated, I following the exact same process, and my OAuth URL is being rejected.

Note: I am putting pasting in the redirected URL response as indicated. It does look the documentation was recently updated and auth URL changed.

manonstreet commented 4 months ago

I looked at the update history for the readme.md and found an older version of the login URL here. That worked and now I can get the integration setup and it can reach the new APIs without error.

Unfortunately the used screen time sensors are still showing values that don't match the Family Safety website/app.

manonstreet commented 4 months ago

I have the hass.agent installed on my kids computers and can see independent data being reported (like when the system was turned on through present). I can confirm that the screen time values in Family Safety website/iOS app are correct, and the sensor presented by this integration are not. @pantherale0, can this please be re-opened?

manonstreet commented 4 months ago

Confirmed resolved by version 1.2.0