You watch too much TV

I have the feeling that my teenager son spends too much time in front of the TV. We have a house rule that he is allowed to watch TV only after all homework is done, room is tidied up and for no more than couple hours a day. Of course, this rule is hard to control unless time spent in front of the TV is accurately measured, so I came up with an easy way to log TV usage to emoncms and later analyze that. The approach to do this is similar to the method I used to tracking my presence at home i.e. see if the smart TV is registered at home’s WiFi and log that information along with time stamp. The major difference from my previous approach is that I track the device by its MAC address rather than static IP lease. I figured that I want to track few more devices, so setting up a static IP lease for pinging them is going to take me more time than working out another method using MAC address. I use arp-scan to achieve this, to install it run:

 sudo apt-get update
 sudo apt-get install arp-scan

It basically can scan the network for certain MAC address and respond with the corresponding IP address, if it is registered. We use exactly feature this to establish if the TV is on or off by specifying part or all of the MAC address of the device to track:

[Edit July 1st 2014] Increased retries count as the default was giving me unreliable readouts and suppressed vendor decoding to speed things up:

sudo arp-scan  --retry 5 --quiet --localnet --interface=wlan0 | grep -s -i 10:08:C1

So here is all this implemented in Node-RED:

TV_flow_1The TV check function is an exec node-red module that runs the arp-scan command:


A simple function checks if the arp-scan returns anything (meaning the device is on) or a null string, meaning device is off:


The result of this check is published to emoncms node 30. I do some post-processing in emoncms to track the time-on:



So with this data collection running for a while, I will be able to know average TV usage per day.

The script can be easily extended with a rule to turn off the TV if daily usage limit is exceeded, but I do not want to be that tough on the kid. The purpose of this project is to learn more about the TV usage and have arguments to support further usage restrictions or relaxing these, also good for self quantification purposes.

The exact same approach can be applied to tracking usage of anything on your home network that connects to the Internet i.e. game consoles, laptops and so forth.




Page views: 17037

7 thoughts on “You watch too much TV

  1. Heh, fun project you have
    My intention was rather to collect data on TV and gaming console usage, with the intention to later analyze it

  2. Thanks for sharing! I just added my Chromecast’s on-time to emoncms.

    If you multiply “LG TV status” by 1000 and then use the process “Power to kWh/d” you will get the usage in hours instead of seconds 🙂

    • Hi Again, I was getting unreliable readouts so increased the number of retries and suppressed vendor lookup. Looks good for now, you may need to adjust the arp-scan to run as follows:

      sudo arp-scan --retry 5 --quiet --localnet --interface=wlan0 | grep -s -i [MAC HERE]

  3. Hi Martin,

    Huge fan of your blog !

    I was trying to get this working to monitor my presence at home with my Iphone.

    Got everything working from the command line : ”sudo arp-scan –retry 5 –quiet –localnet –interface=eth1 | grep -s -i “mac address iphone” ” returns the correct IP address, when i input this in an exec node and ad a debug right behind it, i receive nothing. A variation of the command : ”sudo arp-scan –retry 5 –quiet –localnet –interface=eth1” outputs the same information (first line) as on the command line.

    Have you encountered such a problem ? Have you got any advice ?


    • Strange indeed. Someone mentioned that IPhones switch off the WiFi after going to sleep, could that be happening here too? The exec node has three outputs, try wiring all three to the debug node to check for clues. I assume you don’t enclose the MAC with brackets and the above is just for tidiness?

Comments are closed.