Lua script for tracking time at and away from home

Post Reply
ben53252642
Posts: 392
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Lua script for tracking time at and away from home

Post by ben53252642 » Sunday 10 June 2018 9:34

This is a couple of Lua scripts I wrote for tracking time spent inside and outside my apartment each day.

timesensor.JPG
timesensor.JPG (63.77 KiB) Viewed 258 times

1) Create a couple of custom sensors and name the "Axis Label" "Hours".

2) Create two seperate Lua TIME scripts in Setup > More Options > Events

Edit below scripts as needed, in particular the method you use to determine if you are home or away from home (mine is called "Ben is Home").

Time Inside Apartment

Code: Select all

commandArray = {}
time = os.date("*t")
counter = otherdevices_svalues['Time Inside Apartment']
counter = tonumber(counter)

-- Reset hours 1 minute before mid-night (for charting reasons)
if (time.hour == 0) and (time.min == 00) then
counter = 0
commandArray['UpdateDevice'] = otherdevices_idx['Time Inside Apartment'] .. '|0|' .. tonumber(counter)
end

if (otherdevices["Ben is Home"] == 'On') then
counter = counter + 0.016666666666667
commandArray['UpdateDevice'] = otherdevices_idx['Time Inside Apartment'] .. '|0|' .. tonumber(counter)
print ('Added one minute to time inside apartment counter. Hours: ' .. counter .. '')
end

return commandArray
Time Outside Apartment

Code: Select all

commandArray = {}
time = os.date("*t")
counter = otherdevices_svalues['Time Outside Apartment']
counter = tonumber(counter)

-- Reset hours 1 minute before mid-night (for charting reasons)
if (time.hour == 0) and (time.min == 00) then
counter = 0
commandArray['UpdateDevice'] = otherdevices_idx['Time Outside Apartment'] .. '|0|' .. tonumber(counter)
end

if (otherdevices["Ben is Home"] == 'Off') then
counter = counter + 0.016666666666667
commandArray['UpdateDevice'] = otherdevices_idx['Time Outside Apartment'] .. '|0|' .. tonumber(counter)
print ('Added one minute to time outside apartment counter. Hours: ' .. counter .. '')
end

return commandArray
I've been running this for about a couple of months now and collected some interesting data. 8-)

timesensor2.JPG
timesensor2.JPG (93.1 KiB) Viewed 244 times

Please note this is not a thread for discussing presence detection methods, if you don't already have a way of detecting presence there are many methods available on the Domoticz wiki.
https://www.domoticz.com/wiki/Presence_detection

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests