Page 2 of 3

Re: Playstation timer

Posted: Monday 03 October 2016 16:54
by Erwinvos72
Erwinvos72 wrote:Thnx for the nice script but i have 2 questions

- when i create a system alive checker i only see the xbox 360 'on' when i do a internet test. After the test the xbox goes back to off and the xbox is still on. Do you know why?

- I created the timer but nothing was recorded. I created the script with atom editor on a windows pc and after that i did a conversion to linux to get rid of dos endings etc. Now i added the line 'commandArray['UpdateDevice'] = timer_device_ID .. '|0|' .. tostring(TotalMinutesOn)' directly under 'commandArray = {}' and will try it 2night. But could i have made a mistake by do it on windows and convert it afterwards?
I have tried it but no minutes are displayed, i started pinball locally

Re: Playstation timer

Posted: Monday 03 October 2016 23:35
by mvzut
Derik wrote:Should there be not a option to shutdown a PS with a api or something else?
The power socket solution will not work for my kids...[ there smart like there mom.. :-) ]
Don't know if the PS4 has an API which supports this, I could at least not find it in a quick Google search. You could perhaps also (temporarily) block internet access of the PS4 via the router. That would also render it useless in most cases (at least for my son, who is almost always playing online). But it probably isn't easy or even possible to perform a device block via an API call to your router or something. Although my (ASUS) router should somehow support external configuration, since I can block access to any device using an ASUS app on my iPhone.

Playstation timer

Posted: Monday 03 October 2016 23:45
by mvzut
Erwinvos72 wrote:Thnx for the nice script but i have 2 questions

- when i create a system alive checker i only see the xbox 360 'on' when i do a internet test. After the test the xbox goes back to off and the xbox is still on. Do you know why?

- I created the timer but nothing was recorded. I created the script with atom editor on a windows pc and after that i did a conversion to linux to get rid of dos endings etc. Now i added the line 'commandArray['UpdateDevice'] = timer_device_ID .. '|0|' .. tostring(TotalMinutesOn)' directly under 'commandArray = {}' and will try it 2night. But could i have made a mistake by do it on windows and convert it afterwards?
Apparently the XBOX 360 does not respond to pings all the time, no idea why. You can do an extra check by simply typing "ping <ip address xbox>" in a command line (windows or linux). Check the reaction: if it's a few lines with times (in ms) it should also work with the ping plug-in. If it gives a timeout, there's not much we can do, except when this behaviour can be configured somewhere in the network settings screen (but I doubt it).

Re: Playstation timer

Posted: Tuesday 04 October 2016 11:37
by Erwinvos72
I have gone through the process again and i think i saw some 'dumb' failures from my side. First off all, i have no Playstation, but a Xbox. With that said, i created a XBox timer and a Xbox device in hardware. But i never change those values to the script. There still stood Playstation timer and playstation 4 instead of Xbox timer and xbox.

I changed it and will check ik again 2night. I also created 2 additional timers to check if it works, one for the tv and one for my ipad.

Re: Playstation timer

Posted: Tuesday 04 October 2016 21:33
by Erwinvos72
Erwinvos72 wrote:I have gone through the process again and i think i saw some 'dumb' failures from my side. First off all, i have no Playstation, but a Xbox. With that said, i created a XBox timer and a Xbox device in hardware. But i never change those values to the script. There still stood Playstation timer and playstation 4 instead of Xbox timer and xbox.

I changed it and will check ik again 2night. I also created 2 additional timers to check if it works, one for the tv and one for my ipad.
I managed to get it working :D . My tv, iphone, ipad, androids are showing up. Now only my xbox but the tv is not domain at the moment :D

Re: Playstation timer

Posted: Tuesday 04 October 2016 22:25
by mvzut
Erwinvos72 wrote:I managed to get it working :D .
Good to hear!

I had problems with it today myself. The Playstation suddenly changed its IP address after a router firmware update, but after updating the addres in the ping plugin, I could somehow not read the status of the device in Domoticz (lua) anymore?! I then deleted the decive completely and recreated it. Now it works again. I thought I'd share my experience in case others are ever dealing with the same issue.

Re: Playstation timer

Posted: Tuesday 04 October 2016 22:31
by safi78
@mvzut: afaik the 'pinger' in domoticz is buggy and unreliable. That could explain some of the posts above (it pings devices when they are not there, or says it's gone when it's not, first hand experience). I don't know if the 'pinger' is fixed yet. Till then I use this script: viewtopic.php?f=6&t=10742

@Erwinvos72: afaik an Xbox doesn't respond to ping & cannot be told to. I wasted a lot of time on that ;) But if you managed to get it working, I'm really curious how!

cheers.

Re: Playstation timer

Posted: Thursday 06 October 2016 7:16
by Erwinvos72
@safi78, thnx for your reply. I indeed noticed that the xbox isn't responding to ping. So that part i let go. I thought to change the lua script to assign the tv to the xbox script instead of the xbox but then i get wrong information, because the tv is pinging but that doesn't mean that the xbox is on.

Re: Playstation timer

Posted: Sunday 09 October 2016 13:53
by safi78
@Erwin: I had somewhat of a brainfart :P You can also use 'arping' on Linux, pings devices on a low level (has to be done as root).

I update the meantioned script (replaced the 'ping'-command with 'sudo arping' they take the same arguments, so works instantly). Either sudo without password or run the script as root of course ....

This pings my otherwise unpingable devices as well (a windows laptop, apple tv4, xbox to be tested, but pretty sure that's gonna work as well .. )

Maybe you can use it :)

Re: Playstation timer

Posted: Sunday 09 October 2016 19:01
by Martijn85
Works great! Thanks for sharing :D

Re: Playstation timer

Posted: Monday 10 October 2016 14:35
by safi78
Martijn85 wrote:Works great! Thanks for sharing :D
no problem ;) I needed to fix this as well ...

Re: Playstation timer

Posted: Sunday 16 October 2016 11:20
by franzelare
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

Re: Playstation timer

Posted: Tuesday 24 January 2017 12:21
by sdsi
franzelare wrote: 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
Hi,

Just testing it - it only counts the last device; so, when I set "devicecount = 2' it counts second device, not first. when I set "devicecount = 1" - it counts first device.

Try it and please let me know the fix

Thanks.

Re: Playstation timer

Posted: Wednesday 25 January 2017 7:49
by franzelare
sdsi wrote:
franzelare wrote: 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
Hi,

Just testing it - it only counts the last device; so, when I set "devicecount = 2' it counts second device, not first. when I set "devicecount = 1" - it counts first device.

Try it and please let me know the fix

Thanks.
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"

Playstation timer

Posted: Wednesday 25 January 2017 8:32
by mvzut
franzelare wrote: 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"
Just curious, but why have you changed from LUA UpdateDevice commands to json calls? And if you decided to use json, why do you use a bash script for them? You can also do that directly from LUA using e.g.

Code: Select all

http = require "socket.http"
http.request('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx='..IDX..'&nvalue=0&svalue='..COUNT)
Is this because you have to update so many timers that you got script timeout warnings in the log? I had this with one of my own scripts (completely unrelated to this topic). I ended up running the script completely outside Domoticz using crontab.

Re: Playstation timer

Posted: Wednesday 25 January 2017 11:26
by franzelare
the LUA UpdateDevice commands only works for one device as you noticed... so had to change it.
I cound have called the json comment from the LUA script... but didn't think about that and the bash script was about ready from an other project.
I don't have time outs on the script, did have them before on other scripts but only due to other scripts that were called out to were wrong (like python or bash scripts)

Re: Playstation timer

Posted: Thursday 18 January 2018 9:44
by corederoma82
I'm sorry but I don't understand.
I have domoticz installed on Windows, can I create a LUA script with name like "script_time_playstation_update.lua" and pit it in the LUA directory?
Then? To execut the script???


Thanks

Re: Playstation timer

Posted: Saturday 20 January 2018 17:12
by corederoma82
Counter is not functioning for me.....

Re: Playstation timer

Posted: Sunday 21 January 2018 10:03
by CaesarPL
corederoma82 wrote: Thursday 18 January 2018 9:44 I'm sorry but I don't understand.
I have domoticz installed on Windows, can I create a LUA script with name like "script_time_playstation_update.lua" and pit it in the LUA directory?
Then? To execut the script???
Scripts starting with _time_ are part of internal Domoticz routine and are run automatically

Re: Playstation timer

Posted: Wednesday 24 January 2018 12:36
by corederoma82
CaesarPL wrote: Sunday 21 January 2018 10:03
Scripts starting with _time_ are part of internal Domoticz routine and are run automatically
Thanks, problem solved. :)