Store time difference between switches in log file

Moderator: leecollings

Post Reply
Slinkos
Posts: 81
Joined: Thursday 10 December 2015 0:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

Store time difference between switches in log file

Post by Slinkos »

Hi All,

I'd like to monitor my traveling time to work with Domoticz. I was thinking of doing that by monitoring the difference between 2 switches:
So difference between:
Time Home = Off
Time Work = On

This must be doable in Lua or something (except I don't know how) but it becomes a bit more complicated because offcourse I won't ALWAYS be heading to work when I leave my house. So I need the script only to start when Work = On, and then take the last "Off" entry from my Home switch.

First I'd just like to put the output in a simple log file, maybe later some kind of graphic.

Any ideas here?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Store time difference between switches in log file

Post by Egregius »

In pass2php that would be like this:

pass2php/work.php

Code: Select all

if($status=='On'){
    print strftime("%Y-%m-%d %H:%M:%S",time).'   -> Arrived at work, travel time was '.convertToHours(time-apcu_fetch('tHome').PHP_EOL;
}
 
That would print a line in the Domoticz logfile with a text like:
2017-03-04 16:33:22 -> Arrived at work, travel time was 1:02:13
Of course the command could easily write to another txt file, MySQL database,... A database would be best option if you like to make statistics on it.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests