I wanted to know how much the TV was on so I made this SQL query for that. Its quite heavy but does the work.
Just replace T.DeviceRowID = Idx with your device id.
If you want to chance calculation start date you must add something like this AND T.Date > '2015-09-01 00:00:00' to where caluse.
And of course it wont calculate last turn on sequence if the switch is still on. For example if your switch has been on for two days its missing from this calculation.
Code: Select all
SELECT
MIN(T.Date) as From_Date,
SUM(strftime('%s', (SELECT MIN(X.Date) FROM LightingLog X WHERE X.Date > T.Date AND X.nValue = 0 )) - strftime('%s', T.Date)) / 3600.0 as On_Hours
FROM
LightingLog T
WHERE
T.nValue = 1
AND
T.DeviceRowID = Idx
ORDER BY
T.Date;
The result is first day found in log and time the switch has been on since:
Code: Select all
rock@pjr:~$ sudo sqlite3 domoticz/domoticz.db < ./switch_on_time.sql
2015-08-25 01:33:19|22.1652777777778
But this ON-time per day, month, year would be wery nice addition.