Page 1 of 1

How many hours on

Posted: Friday 11 August 2017 10:17
by mongoose
Have had a search but couldnt find anything.
Id like to see how long a switch has been on for. Is this currently possible or something new. If there is a script please point me in the right direction
Would be handy to see how many hours my tv has been on for a day, week etc so I can restrict my kids :lol: how long a door has been open or how long a light has been on. Currently in graphs it displays when on and when off. But it could be extended. Or in a dummy switch.

Re: How many hours on

Posted: Friday 11 August 2017 10:30
by Egregius
I use the lightlog json command to calculate that in PHP, for example my freezer:

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='.apcu_fetch('idiepvries'),true,$ctx),true);
	$status='';$tijdprev=$time;$totalon=0;
	if(!empty($datas['result'])){
		foreach($datas['result'] as $data){
		//6:20:06
			$level=$data['Level'];
			$tijd=strtotime($data['Date']);
			if($tijd<$eendag)break;
			$period=($tijdprev-$tijd);
			if($data['Status']=='On'){$totalon=$totalon+$period;$style="color:#FF4400";}else{$style="color:#1199FF";}
			$tijdprev=$tijd;
			//if($status!=$data['Status']){

				echo '
				<tr>
					<td style="'.$style.'">'.$data['Date'].'</td>
					<td style="'.$style.'">&nbsp;'.$data['Status'].'&nbsp;</td>
					<td style="'.$style.'">&nbsp;'.convertToHours($period).'</td>
				</tr>';
				$status=$data['Status'];
			//}
		}
	}
	echo '
			</table>
		</div>
		<div class="fix" style="top:18px;left:260px;width:60px;">'.convertToHours($totalon).'</div>';[code]

Re: How many hours on

Posted: Saturday 12 August 2017 2:01
by mongoose
Cool thank you for that.
Can you explain how you are using it? like dummy switch? if so what kind, or outside of domoticz etc?

Cheers

Larry

Re: How many hours on

Posted: Saturday 12 August 2017 6:27
by Egregius
Outside, it's part of php floorplan.

Re: How many hours on

Posted: Sunday 13 August 2017 15:32
by mcestoni
Hola, lo que deseas hacer se puede perfectamente enviando los datos a influx y consultandolos con Grafana.
Desde Grafana puedes calcular todo lo que quieras, incluso enviar alertas despues de un determinado tiempo de uso

Saludos

Re: How many hours on

Posted: Sunday 13 August 2017 15:39
by SweetPants
mcestoni wrote: Sunday 13 August 2017 15:32 Hola, lo que deseas hacer se puede perfectamente enviando los datos a influx y consultandolos con Grafana.
Desde Grafana puedes calcular todo lo que quieras, incluso enviar alertas despues de un determinado tiempo de uso

Saludos
English please!!! :mrgreen: :mrgreen: :mrgreen:

Re: How many hours on

Posted: Monday 14 August 2017 2:08
by mongoose
He says use Grafana.com :) good ol google translate, I would have liked to have it in Domoticz directly. :)

Re: How many hours on

Posted: Monday 14 August 2017 13:13
by D'rMorris
You can do it in LUA as well.

First create a function that calculates the time difference:

Code: Select all

function timedifference (s)
  year = string.sub(s, 1, 4)
  month = string.sub(s, 6, 7)
  day = string.sub(s, 9, 10)
  hour = string.sub(s, 12, 13)
  minutes = string.sub(s, 15, 16)
  seconds = string.sub(s, 18, 19)
  t1 = os.time()
  t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
  difference = os.difftime (t1, t2)
  return difference
end
Then you could calculate how long something is on by using this code:

Code: Select all

if (devicechanged['TVof yourkids'] == 'On')
then
difference_in_days = math.floor(difference / 86400)
difference_in_hours = math.floor((difference - difference_in_days * 86400) / 3600)
difference_in_minutes = math.floor(((difference - difference_in_days * 86400) - (difference_in_hours * 3600)) / 60)
print('<b style="color:Red">>> Devices ' .. difference_in_days .. ' days, ' .. difference_in_hours .. ' hours and ' .. difference_in_minutes .. ' minutes ago</b>')
Then you could update a virtual text sensor or something with the values in days / hours / minutes.

Re: How many hours on

Posted: Monday 14 August 2017 13:27
by mongoose
Thanks for that! I'll give it a go! 🙂

Re: How many hours on

Posted: Monday 11 September 2017 14:35
by Wob76
viewtopic.php?t=18848

Sent from my SM-G935F using Tapatalk