I would like to use the device_tracker to track the online time of my children and to block their assigned devices from the internet via a Fritzbox script if the online time is too long.
Currently I have no idea how that could work. I just have created a sensor, which gives me the time, beeing at home:
But this sensor will give statistics on how much time their devices are connected to the local network, not the amount of time they are actually using the devices to navigate on Internet.
that is right. This is just the time they are connected to Lan or wlan. However, also playing games expects a internet connection. For me it is the best solution to track how long they are connected, independent if they are surfing or playing online games, using whatsapp or whatever. they like to be distracted and neglect their homework
But what about the phone in standby in a table? It still connecting to the wifi from time to time (to refresh email, weather conditions, share a bunch of info with Google and other companies, etc.), and this will count as at home even when no one is really using it.
you could use the switch switch.<your_device_name>_internet_access of the Fritz!Box integration to prevent internet access for a device (you set a device lock in the parental control of the Fritz!Box)
or:
you could use the parental control of the Fritz!Box to set an access/quantity profile for devices/persons (but this doesn’t seem to work out of HA so far, but only in the Fritz!Box itself - I don’t know a way to do this so far)
switch.device is good, but how can I put it in an automation, which switch off the device after a defined time. After a new day it should be resetted to default.
There are a lot of ways to automate this and another possibilities to improve this code, but let’s start with something simpler to explain:
description: ""
mode: single
trigger:
- id: Turn off
platform: numeric_state
entity_id: sensor.smartphone_kid1
above: 7200 # I believe your new sensor is counting seconds, so this is 2 hours of device on home
- id: Turn on
platform: state
entity_id:
- switch.smartphone_kid1
to: "off"
for:
hours: 8 # 8 hours after the internet was disabled for that device
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Turn off
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.smartphone_kid1_internet_access
- conditions:
- condition: trigger
id: Turn on
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.smartphone_kid1_internet_access
This will work, but haven’t you create a sensor specifically to count the total time during the day?
Using this way you have done, if your kids realize the pattern, they will navigate for 9 minutes, disconnect for a few seconds and then they will have 10 more minutes to play, so, in reality, they can easily bypass the limitation.
The sensor you have shared earlier will manage this in a better way (althougth I still believe measuring the time the device is connected to the network is not a good way to measure the time they are using the system).
Isn’t the parental control from your router more efficient?
You are right, that is the problem I found out also some mins ago . I will try your idea next time. many thx for that.
The parental control with my Fritzbox is also working fine. The Problem is, that is quite often the case, that one kid comes and ask for internet access for doing homework. Than you have to open the fb web interface with smartphone or PC. My smartphone and a button or a slider in homeassistant is my target for doing that.
Please provide more details… What do you mean by “not working”? Was never triggered even with your kids playing for more than 10min? Was triggered when within less than 10min? Was triggered properly but the network wasn’t disabled?
Anything in your logs?
I still don’t believe the phone’s device_tracker is the right sensor to measure the phone usage, so it’s hard to believe you will get there thru this path. Again, managing your router’s parental control is probably much more efficient.
Look my example, my phone is “Home” for the past 10 hours. I haven’t touched the device during these 10 hours. I was sleeping a big part of this time and the fone is in another room. This sensor measure if my phone is at home, not if I’m using it.
So, my suggestion is to take another direction. If your router’s parental control is a solution and your only problem is about giving them more time, I think you have a much easier way to solve it. I don’t know that much about your router and it’s sensors/controls, but maybe we can invest more on that to see if it’s a viable path…
But that should be another thread.
Hi,
i believe the script is not working, because the trigger “turn off” after 7200 (I reduced for test to 60) was never reached. I have tested it with my smartphone, the device inet connection was always possible during all the time.
Go to Developer Tools, click on the “Status” tab and then type the name of your sensor in the filter.
You will see the status of the sensor (it’s value) at the column “Status”.