How many hours on

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
User avatar
mongoose
Posts: 42
Joined: Friday 22 November 2013 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How many hours on

Post 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.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: How many hours on

Post 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]
User avatar
mongoose
Posts: 42
Joined: Friday 22 November 2013 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How many hours on

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: How many hours on

Post by Egregius »

Outside, it's part of php floorplan.
User avatar
mcestoni
Posts: 11
Joined: Tuesday 08 August 2017 3:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How many hours on

Post 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
SweetPants

Re: How many hours on

Post 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:
User avatar
mongoose
Posts: 42
Joined: Friday 22 November 2013 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How many hours on

Post by mongoose »

He says use Grafana.com :) good ol google translate, I would have liked to have it in Domoticz directly. :)
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: How many hours on

Post 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.
User avatar
mongoose
Posts: 42
Joined: Friday 22 November 2013 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How many hours on

Post by mongoose »

Thanks for that! I'll give it a go! 🙂
Wob76
Posts: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: How many hours on

Post by Wob76 »

viewtopic.php?t=18848

Sent from my SM-G935F using Tapatalk

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest