Page 1 of 1
How many times and how long was a door open
Posted: Wednesday 17 May 2017 8:17
by betonishard
Hello all,
I've been trying to find this for a quite of time now, can't seem to find it.
I am looking for a method in which I can calculate how many times a day a door was opened (I have door sensors which send on/off states to my domitcz setup, works like a charm). Furthermore I would like to calculate the time over a day to see how long that particular door was open.
Did any off you did this already and if yes, care to share?
Thanks for the great support and help is much appreciated.
Best regards,
Re: How many times and how long was a door open
Posted: Wednesday 17 May 2017 9:35
by Egregius
Almost the same of what I do for my gas heater:
Code: Select all
echo '
<div>
<table class="brander">';
$datas=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=lightlog&idx=80',true,$ctx),true);
$status='';$tijdprev=$time;$totalon=0;
if(!empty($datas['result'])){
foreach($datas['result'] as $data){
//if($status!=$data['Status']){
$status=$data['Status'];
$level=$data['Level'];
$tijd=strtotime($data['Date']);
if($tijd<$eendag)break;
$period=($tijdprev-$tijd);
if($status=='On'){$totalon=$totalon+$period;$style="color:#FF4400";}else{$style="color:#1199FF";}
$tijdprev=$tijd;
echo '
<tr>
<td style="'.$style.'">'.$data['Date'].'</td>
<td style="'.$style.'"> '.$status.' </td>
<td style="'.$style.'"> '.convertToHours($period).'</td>
</tr>';
//}
}
}
echo '
</table>
</div>
<div class="fix" style="top:18px;left:320px;width:60px;">'.convertToHours($totalon).'</div>';
This shows a table with all on/off times, the time between them and a total time my gas heater was on during the last 24 hours.
Re: How many times and how long was a door open
Posted: Wednesday 17 May 2017 17:12
by betonishard
Egregius wrote:Almost the same of what I do for my gas heater:
Code: Select all
echo '
<div>
<table class="brander">';
$datas=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=lightlog&idx=80',true,$ctx),true);
$status='';$tijdprev=$time;$totalon=0;
if(!empty($datas['result'])){
foreach($datas['result'] as $data){
//if($status!=$data['Status']){
$status=$data['Status'];
$level=$data['Level'];
$tijd=strtotime($data['Date']);
if($tijd<$eendag)break;
$period=($tijdprev-$tijd);
if($status=='On'){$totalon=$totalon+$period;$style="color:#FF4400";}else{$style="color:#1199FF";}
$tijdprev=$tijd;
echo '
<tr>
<td style="'.$style.'">'.$data['Date'].'</td>
<td style="'.$style.'"> '.$status.' </td>
<td style="'.$style.'"> '.convertToHours($period).'</td>
</tr>';
//}
}
}
echo '
</table>
</div>
<div class="fix" style="top:18px;left:320px;width:60px;">'.convertToHours($totalon).'</div>';
This shows a table with all on/off times, the time between them and a total time my gas heater was on during the last 24 hours.
Thanks for your quick response. However I am not using php and was looking something in the direction of LUA or a python or a sh script. I am not a star in converting this in one of those languages, but with an example in that way I can fix it..
Regards.
Re: How many times and how long was a door open
Posted: Wednesday 17 May 2017 17:23
by Egregius
Who wants lua or anything if you have php?

Re: How many times and how long was a door open
Posted: Wednesday 17 May 2017 17:27
by emme
you can use a device script that could make 2 operations:
once the door goes Open, it will store the timestamp (_lastupdate) to a variable
once it goes Closed, it will compare (time difference) the stored timestamp with the current _lastupdate
have a sting variable called LastKnownOpenDoor and try using this script as a script_device_door.lua or a device event:
Code: Select all
local doorDevName = 'Your Door Sensor Name'
local doorStaus = otherdevices[doorDevName]
function timeDiff(dName,dType)
if dType == 'v' then
updTime = uservariables_lastupdate[dName]
elseif dType == 'd' then
updTime = otherdevices_lastupdate[dName]
end
t1 = os.time()
year = string.sub(updTime, 1, 4)
month = string.sub(updTime, 6, 7)
day = string.sub(updTime, 9, 10)
hour = string.sub(updTime, 12, 13)
minutes = string.sub(updTime, 15, 16)
seconds = string.sub(updTime, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
tDiff = os.difftime(t1,t2)
return tDiff
end
commandArray = {}
if devicechanged[doorDevName] then
if doorStatus = 'On' then -- or 'Open' based on the sensor type
uservariables['LastKnownOpenDoor'] = otherdevices_lastupdate[doorDevName]
else
timeOpen = timeDiff('LastKnownOpenDoor','v')
print('Door '..doorDevName..' was open for '..timeOpen..' seconds')
end if
return commandArray
Egregius wrote:Who wants lua or anything if you have php?

who doesn't know how to code with php

Re: How many times and how long was a door open
Posted: Wednesday 17 May 2017 19:41
by betonishard
Guys, I know. I am a weak excuse. Good thing we have you guys!
Anyhow thanks mucho!