Playstation timer

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

blauwebuis
Posts: 331
Joined: Wednesday 21 December 2016 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Re: Playstation timer

Post by blauwebuis »

Funny, I've always used this as a dystopian example of how a smart home could be used..
Martijn85
Posts: 53
Joined: Wednesday 20 January 2016 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Playstation timer

Post by Martijn85 »

franzelare wrote: Wednesday 25 January 2017 7:49 yes I also noticed later and fixed it...

Code: Select all

-- this script is to detect on time of devices in domoticz
-- based on the script of mvzut that can be found here on the forum 
-- https://www.domoticz.com/forum/viewtopic.php?f=38&t=11985
-- this has to be a time based lua script in domoticz (as device script this will not work

-- for every device to monitor a counter has to be created as virtual devicecount
-- Create an incremental counter 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. "On time") and Value Units ("Minutes"). 
-- Check the Device ID (idx) that is given to the new counter device.

-- this script can be run in combination with an ping, bluetooth scan or an arp scan what is in some cases more reliable
    -- ping: https://www.domoticz.com/wiki/Presence_detection
    -- bluetooth: https://www.domoticz.com/wiki/Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)
    -- arp scan: https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

-- define general script values
devicecount = 11                     -- number of deviced to be cheked by the script for on time
PRINT_MODE = false					-- when true wil print output to log and send notifications

-- create a table to store device information
devicetable = {}

-- Device 1
device = 1
devicetable["name" .. device] = 'FransMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 237                       -- idx of the counter created for this device

-- Device 2
device=2
devicetable["name" .. device] = 'SusanMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 238                       -- idx of the counter created for this device

-- Device 3
device=3
devicetable["name" .. device] = 'FransTablet'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransTabletTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 239                       -- idx of the counter created for this device

-- Device 4
device=4
devicetable["name" .. device] = 'SusanTablet'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanTabletTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 240                       -- idx of the counter created for this device

-- Device 5
device=5
devicetable["name" .. device] = 'FransPC'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransPCTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 241                       -- idx of the counter created for this device

-- Device 6
device=6
devicetable["name" .. device] = 'SusanPC'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanPCTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 242                       -- idx of the counter created for this device

-- Device 7
device=7
devicetable["name" .. device] = 'SonyBlueRay'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SonyBlueRayTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 243                       -- idx of the counter created for this device

-- Device 8
device=8
devicetable["name" .. device] = 'ITV receiver'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ITV receiverTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 244                       -- idx of the counter created for this device


-- Device 9
device=9
devicetable["name" .. device] = 'ASM-Lan'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ASM-LanTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 245                       -- idx of the counter created for this device

-- Device 10
device=10
devicetable["name" .. device] = 'ASM-Wifi'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ASM-WifiTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 246                       -- idx of the counter created for this device

-- Device 11
device=11
devicetable["name" .. device] = 'Chromecast'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ChromecastTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 247                       -- idx of the counter created for this device



commandArray = {}
for i=1,devicecount do
    if otherdevices[devicetable["name" .. i]] == 'On' then
        TimerID = devicetable["ID" .. i]
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device name detected On :' .. devicetable["name" .. i])
            print('Device name On timer :' .. devicetable["timer" .. i])
            print('Device ID timer counter :' .. TimerID)
            print('Timer value: ' .. otherdevices_svalues[devicetable["timer" .. i]])
        end
	    TotalMinutesOnRaw = (otherdevices_svalues[devicetable["timer" .. i]])
	    Part=1
        for match in (TotalMinutesOnRaw..';'):gmatch("(.-)"..';') do
            if Part==1 then TotalMinutesOn = tonumber(match) end
            Part=Part+1
        end
    	TotalMinutesOnNew = TotalMinutesOn + 1
        execcommandOn="sudo /home/pi/domoticz/scripts/bash/SetCounter.sh "..TimerID.." "..TotalMinutesOnNew.." &"
        os.execute(execcommandOn)
            
        if PRINT_MODE == true then
		    print('Previous on time: ' .. TotalMinutesOn)
		    print('New on time: ' .. TotalMinutesOnNew)
        end
    elseif otherdevices[devicetable["name" .. i]] == 'Off' then
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected Off: ' .. devicetable["name" .. i])
            print('No update of the timer needed')
        end
    else
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device ERROR: ' .. devicetable["name" .. i])
        end
    end

end

return commandArray
and using a bash scripts to set the counters through json:

Code: Select all

    #!/bin/bash
    IDX=$1
    COUNT=$2
	curl "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=$COUNT"
I can't get this to work. The logs seems fine.. But the counter is not updating.

When i update this manualy with: curl "http://127.0.0.1:8080/json.htm?type=com ... 0&svalue=3" the counter is updating.

No errors in the log, can someone tell me whats wrong?

Code: Select all

2019-01-04 00:26:00.732 Status: LUA: Device sequence: 1
2019-01-04 00:26:00.732 Status: LUA: Device name detected On :TV Woonkamer
2019-01-04 00:26:00.732 Status: LUA: Device name On timer :TV Timer
2019-01-04 00:26:00.732 Status: LUA: Device ID timer counter :1259
2019-01-04 00:26:00.732 Status: LUA: Timer value: 3
2019-01-04 00:26:00.746 Status: LUA: Previous on time: 3
2019-01-04 00:26:00.746 Status: LUA: New on time: 4
2019-01-04 00:26:00.746 Status: LUA: Device sequence: 2
2019-01-04 00:26:00.746 Status: LUA: Device detected Off: Nintendo Wii
2019-01-04 00:26:00.746 Status: LUA: No update of the timer needed
2019-01-04 00:26:00.746 Status: LUA: Device sequence: 3
2019-01-04 00:26:00.746 Status: LUA: Device detected Off: HTPC
2019-01-04 00:26:00.746 Status: LUA: No update of the timer needed
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Playstation timer

Post by Larsoss »

franzelare wrote: Sunday 16 October 2016 11:20 thanks for the script!
nice work, i have been thinking about it but did not build it yet.. so based my code on your script and pimped it a bit with a table for multiple devices.
might be of use for other people who want to track more devices for the ontime.
you can just add devices and increase the device count to the number of devices you have added, the script here is now for 2 devices

I run this in combination with a arp scan on the devices in my network since that works better for me than a ping

Code: Select all

-- device ontimer script rev 1.0 by franzelare
-- this script is to detect on time of devices in domoticz
-- based on the script of mvzut that can be found here on the forum 
-- https://www.domoticz.com/forum/viewtopic.php?f=38&t=11985&sid=19cb4cb949d30eb8f27a797f598ad2f1
-- this has to be a time based lua script in domoticz (as device script this will not work

-- for every device to monitor a counter has to be created as virtual devicecount
-- Create an incremental counter 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. "On time") and Value Units ("Minutes"). 
-- Check the Device ID (idx) that is given to the new counter device.

-- this script can be run in combination with an ping, bluetooth scan or an arp scan what is in some cases more reliable
    -- ping: https://www.domoticz.com/wiki/Presence_detection
    -- bluetooth: https://www.domoticz.com/wiki/Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)
    -- arp scan: https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

-- define general script values
devicecount = 2                     -- number of deviced to be cheked by the script for on time
PRINT_MODE = true					-- when true wil print output to log and send notifications

-- create a table to store device information
devicetable = {}

-- Device 1
device = 1
devicetable["name" .. device] = 'FransMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 237                       -- idx of the counter created for this device

-- Device 2
device=2
devicetable["name" .. device] = 'SusanMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 238                       -- idx of the counter created for this device



commandArray = {}
for i=1,devicecount do
    if otherdevices[devicetable["name" .. i]] == 'On' then
	    TotalMinutesOn = otherdevices_svalues[devicetable["timer" .. i]]
    	TotalMinutesOnNew = TotalMinutesOn + 1
	    commandArray['UpdateDevice'] = devicetable["ID" .. i] .. '|0|' .. tostring(TotalMinutesOnNew)
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected On :' .. devicetable["name" .. i])
		    print('Previous on time: ' .. TotalMinutesOn)
		    print('New on time: ' .. TotalMinutesOnNew)
        end
    elseif otherdevices[devicetable["name" .. i]] == 'Off' then
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected Off: ' .. devicetable["name" .. i])
	    print('No update of the timer needed')
        end
    else
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device ERROR: ' .. devicetable["name" .. i])
        end
    end

end

return commandArray
Can you please give me a detail description for making the counter?
First step is Hardware - Add a new device (System Alive Checker)
When add that click on settings and add one name / ip
And what is the next step
Because i see now only a switch that says On/Off and no counter.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Playstation timer

Post by bewo »

Hi Larsoss,

i use an different script of mine, maybe this is helpful for you (or others). You can count anything with this....

This ist the script:

Code: Select all

-- Domoticz-LUA-Script for counting the workingtime of any device you wish

--[[
##########################
WATCH OUT!!!! - The script type LUA Time MUST be selected !!
Another type of script maybe forces a domoticz crash because the script is triggered countless times,
instead of just once per minute and one minute would be counted for each call, although there are only
a few seconds or fractions of a second.
##########################

The minute-by-minute call can lead to counting inaccuracies. At the moment it is different
not (easy) possible. Example: A device is switched on at 12:00:50. So the counter counts one minute,
even though it was only on for 10 seconds. Conversely, if a device is switched off at 00:00:50, the
50 seconds no longer counted. -> In short: only full minutes are counted.
]]



commandArray = {}

-- Set up your devices here:
All_Devices = {
 -- { Counter = 'Name of the counter', Device = 'Device which should be counted' },
    { Counter = 'Example-Counter-1', Device = 'Example-Counter-1' },
    { Name = 'Example-Device-2', Device = 'Example-Counter-2' },
 -- just so on.... as many devices you want
}


-- ####################################################################################
-- Don't need to change something after here... :-)

-- Load an function for timedifference
function timedifference(timestamp)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
  return difference
end


-- Let'start:
for Devices,Device in pairs(All_Devices) do

    counter_reading = otherdevices_svalues[Device.Counter]

    if otherdevices[Device.Device] == 'On' then
            
        On_time = counter_reading + 1
        commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[Device.Counter]..'|1|'..tonumber(On_time)}
        print('Timecounter -> The device '..Device.Device..' is ON and was counted.')
        
    end

    -- And update if no change was made (so that after 60 minutes off the title banner does not turn red.):
    if timedifference(otherdevices_lastupdate[Device.Counter]) > 3500 then
        commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[Device.Counter]..'|1|'..tonumber(counter_reading)}
        print('Timecounter -> '..Device.Counter..' was kept active.')
    end

end



return commandArray

--[[ Little help:
The device which should be counted could be any device you want.
The Counter is an dummy device with this settings:
- Type in setup: Counter
- Type in device configuration: Counter
- Division: 0
- Meter offset: 0
]]

This is an counter, for example the PlayStation:
Bildschirmfoto 2020-04-14 um 17.17.18.png
Bildschirmfoto 2020-04-14 um 17.17.18.png (19.75 KiB) Viewed 1314 times
This are the options form the counter:
Bildschirmfoto 2020-04-14 um 17.17.30.png
Bildschirmfoto 2020-04-14 um 17.17.30.png (48.16 KiB) Viewed 1314 times
And to get such an counter just an an device in the hardware tab, and then in your dummy hardware "Create device/sensor":
Bildschirmfoto 2020-04-14 um 17.18.55.png
Bildschirmfoto 2020-04-14 um 17.18.55.png (62.05 KiB) Viewed 1314 times
And if you don't have an "dummy hardware" yet, just generate one at the bottom of the hardware page:
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Playstation timer

Post by bewo »

Bildschirmfoto 2020-04-14 um 17.22.27.png
Bildschirmfoto 2020-04-14 um 17.22.27.png (36.96 KiB) Viewed 1314 times
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Playstation timer

Post by Larsoss »

bewo wrote: Tuesday 14 April 2020 17:24 Bildschirmfoto 2020-04-14 um 17.22.27.png
Thank you for the fast answer.
I think i'm done with the script i used. Only thing is that my switches (2 phones to try with it) the whole time going to on/off.
So it's not working fine at this moment. Maybe you can help me with teamviewer? to look at my settgins?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
mvzut
Posts: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Playstation timer

Post by mvzut »

Phones (especially iPhones) are notoriously bad at reacting to pings (which is what the System Alive Checker uses). They go in a power saving mode and don't react to pings after a while. The phone may react again if some internal process wakes it up temporarily, but this is very unreliable. If you want to do reliable presence checking of phones, I suggest to look at the iDetect Wifi presence detection Python plugin. This plugin uses the mac adress of your device and checks your router (via an ssh connection) if it is currently present in the network.
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Playstation timer

Post by Larsoss »

mvzut wrote: Tuesday 14 April 2020 21:48 Phones (especially iPhones) are notoriously bad at reacting to pings (which is what the System Alive Checker uses). They go in a power saving mode and don't react to pings after a while. The phone may react again if some internal process wakes it up temporarily, but this is very unreliable. If you want to do reliable presence checking of phones, I suggest to look at the iDetect Wifi presence detection Python plugin. This plugin uses the mac adress of your device and checks your router (via an ssh connection) if it is currently present in the network.
Yes i have found and installed it. This works perfect.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
franzelare
Posts: 139
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Playstation timer

Post by franzelare »

Larsoss wrote: Tuesday 14 April 2020 15:46
franzelare wrote: Sunday 16 October 2016 11:20 thanks for the script!
nice work, i have been thinking about it but did not build it yet.. so based my code on your script and pimped it a bit with a table for multiple devices.
might be of use for other people who want to track more devices for the ontime.
you can just add devices and increase the device count to the number of devices you have added, the script here is now for 2 devices

I run this in combination with a arp scan on the devices in my network since that works better for me than a ping

Code: Select all

-- device ontimer script rev 1.0 by franzelare
-- this script is to detect on time of devices in domoticz
-- based on the script of mvzut that can be found here on the forum 
-- https://www.domoticz.com/forum/viewtopic.php?f=38&t=11985&sid=19cb4cb949d30eb8f27a797f598ad2f1
-- this has to be a time based lua script in domoticz (as device script this will not work

-- for every device to monitor a counter has to be created as virtual devicecount
-- Create an incremental counter 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. "On time") and Value Units ("Minutes"). 
-- Check the Device ID (idx) that is given to the new counter device.

-- this script can be run in combination with an ping, bluetooth scan or an arp scan what is in some cases more reliable
    -- ping: https://www.domoticz.com/wiki/Presence_detection
    -- bluetooth: https://www.domoticz.com/wiki/Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)
    -- arp scan: https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

-- define general script values
devicecount = 2                     -- number of deviced to be cheked by the script for on time
PRINT_MODE = true					-- when true wil print output to log and send notifications

-- create a table to store device information
devicetable = {}

-- Device 1
device = 1
devicetable["name" .. device] = 'FransMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 237                       -- idx of the counter created for this device

-- Device 2
device=2
devicetable["name" .. device] = 'SusanMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 238                       -- idx of the counter created for this device



commandArray = {}
for i=1,devicecount do
    if otherdevices[devicetable["name" .. i]] == 'On' then
	    TotalMinutesOn = otherdevices_svalues[devicetable["timer" .. i]]
    	TotalMinutesOnNew = TotalMinutesOn + 1
	    commandArray['UpdateDevice'] = devicetable["ID" .. i] .. '|0|' .. tostring(TotalMinutesOnNew)
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected On :' .. devicetable["name" .. i])
		    print('Previous on time: ' .. TotalMinutesOn)
		    print('New on time: ' .. TotalMinutesOnNew)
        end
    elseif otherdevices[devicetable["name" .. i]] == 'Off' then
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected Off: ' .. devicetable["name" .. i])
	    print('No update of the timer needed')
        end
    else
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device ERROR: ' .. devicetable["name" .. i])
        end
    end

end

return commandArray
Can you please give me a detail description for making the counter?
First step is Hardware - Add a new device (System Alive Checker)
When add that click on settings and add one name / ip
And what is the next step
Because i see now only a switch that says On/Off and no counter.
sorry, i do not use the script anymore.
use to have a network map with all ping and uptimes but changed so many devices in my network without maintenace on my scripts that i deleted it
marcowork
Posts: 7
Joined: Wednesday 28 November 2018 12:55
Target OS: Linux
Domoticz version:
Contact:

Re: Playstation timer

Post by marcowork »

I just wanted to say to the original poster of this thread:
you are mean.....let them kids just play
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest