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

How many hours on

Post by mongoose » Friday 11 August 2017 10:17

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: 2416
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: How many hours on

Post by Egregius » Friday 11 August 2017 10:30

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: 89
Joined: Friday 22 November 2013 11:43
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How many hours on

Post by mongoose » Saturday 12 August 2017 2:01

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: 2416
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: How many hours on

Post by Egregius » Saturday 12 August 2017 6:27

Outside, it's part of php floorplan.

User avatar
mcestoni
Posts: 6
Joined: Tuesday 08 August 2017 3:19
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How many hours on

Post by mcestoni » 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

SweetPants
Posts: 1534
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8630
Location: The Netherlands
Contact:

Re: How many hours on

Post by SweetPants » Sunday 13 August 2017 15:39

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: 89
Joined: Friday 22 November 2013 11:43
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How many hours on

Post by mongoose » Monday 14 August 2017 2:08

He says use Grafana.com :) good ol google translate, I would have liked to have it in Domoticz directly. :)

D'rMorris
Posts: 296
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: How many hours on

Post by D'rMorris » Monday 14 August 2017 13:13

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: 89
Joined: Friday 22 November 2013 11:43
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How many hours on

Post by mongoose » Monday 14 August 2017 13:27

Thanks for that! I'll give it a go! 🙂

Wob76
Posts: 55
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: How many hours on

Post by Wob76 » Monday 11 September 2017 14:35

viewtopic.php?t=18848

Sent from my SM-G935F using Tapatalk


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests