Playstation timer
Posted: Monday 16 May 2016 15:09
Hi all,
Just to let you know I created a custom counter that keeps track of how long the Playstation console in my house has been turned on. It uses two (virtual) Domoticz devices and a piece of LUA script.
First, I created a new device with the System Alive Checker. This uses pinging to check if the Playstation is turned on or off. It will probably also report "On" if the Playstation is in standby mode downloading something in the background, but that doesn't happen too often I think. Add the switch to the used switches under Setup>Devices and give it a name like "Playstation 4". From now on, Domoticz keeps track of when your game console is on and off.
Then, I created an incremental counter called "Playstation timer" using the Dummy hardware component (first add this component if you haven't already done so before, using Setup>Hardware). Then go to the Utility section, change the type of your new counter from Energy to Counter, and fill in the Value Quantity (e.g. "Gaming time") and Value Units ("Minutes"). Check the Device ID (idx) that is given to the new counter device. In my case, this was 344.
Finally, create a script in the domoticz/scripts/lua directory with a name like "script_time_playstation_update.lua" with the following contents:
That's it! Now you can do several things:
- Check remotely if your kids are on the game console when they should be doing their homework
- Program a notification if the console has been on for more than e.g. 2 hours that day
- Get weekly, monthly and yearly overviews of the usage per day
- Switch off the console if an agreed limit has been reached (although this is probably easy to bypass by your kids if you are using a simple power socket switch)
Note that this should work on any internet-connected device, so not only a Playstation but also XBox, Wii, laptop or even the TV. Come to think of it, you could even monitor how long a lamp or fan or any device that you control from Domoticz has been on!
Maybe this can be of use for others too.
UPDATE:
I edited the script a little bit, so that it updates the timer every minute, even when the value has not changed. This avoids sensor timeout indications in Domoticz.
If you don't get the script to work right away, here are a few tips:
- Restart Domoticz, I've sometimes seen that Domoticz cannot immediately "see" newly created devices from LUA and a restart solves this
- It could help to put
directly after the "commandArray = {}" line in your script. This will properly initialize the value of the timer to 0. Remove (or comment out) the line again after a few minutes.
- If you create the script using the built-in script editor, make sure you select the "time" option in the top right hand corner. If you leave it on the default "Device", the script will be executed whenever any device state changes, which can be at arbitrary moments and leads to incorrect timing (i.e. one count could be more or less than one minute)
Just to let you know I created a custom counter that keeps track of how long the Playstation console in my house has been turned on. It uses two (virtual) Domoticz devices and a piece of LUA script.
First, I created a new device with the System Alive Checker. This uses pinging to check if the Playstation is turned on or off. It will probably also report "On" if the Playstation is in standby mode downloading something in the background, but that doesn't happen too often I think. Add the switch to the used switches under Setup>Devices and give it a name like "Playstation 4". From now on, Domoticz keeps track of when your game console is on and off.
Then, I created an incremental counter called "Playstation timer" using the Dummy hardware component (first add this component if you haven't already done so before, using Setup>Hardware). Then go to the Utility section, change the type of your new counter from Energy to Counter, and fill in the Value Quantity (e.g. "Gaming time") and Value Units ("Minutes"). Check the Device ID (idx) that is given to the new counter device. In my case, this was 344.
Finally, create a script in the domoticz/scripts/lua directory with a name like "script_time_playstation_update.lua" with the following contents:
Code: Select all
local timer_device_ID = 344
commandArray = {}
local TotalMinutesOn = otherdevices_svalues['Playstation timer']
if otherdevices['Playstation 4'] == 'On' then
TotalMinutesOn = TotalMinutesOn + 1
end
commandArray['UpdateDevice'] = timer_device_ID .. '|0|' .. tostring(TotalMinutesOn)
return commandArray
- Check remotely if your kids are on the game console when they should be doing their homework
- Program a notification if the console has been on for more than e.g. 2 hours that day
- Get weekly, monthly and yearly overviews of the usage per day
- Switch off the console if an agreed limit has been reached (although this is probably easy to bypass by your kids if you are using a simple power socket switch)
Note that this should work on any internet-connected device, so not only a Playstation but also XBox, Wii, laptop or even the TV. Come to think of it, you could even monitor how long a lamp or fan or any device that you control from Domoticz has been on!
Maybe this can be of use for others too.
UPDATE:
I edited the script a little bit, so that it updates the timer every minute, even when the value has not changed. This avoids sensor timeout indications in Domoticz.
If you don't get the script to work right away, here are a few tips:
- Restart Domoticz, I've sometimes seen that Domoticz cannot immediately "see" newly created devices from LUA and a restart solves this
- It could help to put
Code: Select all
commandArray['UpdateDevice'] = timer_device_ID .. '|0|0'
- If you create the script using the built-in script editor, make sure you select the "time" option in the top right hand corner. If you leave it on the default "Device", the script will be executed whenever any device state changes, which can be at arbitrary moments and leads to incorrect timing (i.e. one count could be more or less than one minute)