Measure Operating Time

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
trendkill
Normal user
Posts: 31
Joined: 22 Feb 2022, 09:04

Measure Operating Time

#1 Post by trendkill » 08 Dec 2023, 10:26

Hello guys,
I have a heating system and a simple thermostat setup with espeasy. It logs to my linux server when the heater turns on and off, but I would like to have a daily report about the total amount of time while the heater was ON. So I think I would start counting seconds when the HeaterON event happens, pause it when HeaterOFF event happens, and finally send the summarized value to my linux server and reset the counter at midnight. How would you do it in a simple way? Thank you!! Here is my code:

Code: Select all

on DS1#Temperature do
 if [DS1#Temperature] < 40
  GPIO,5,0
  Event,HeaterON
 endif
 if [DS1#Temperature] > 55
  GPIO,5,1
  Event,HeaterOFF
 endif
endon

On HeaterON Do
  If [Dummy#LoggingON] = 1
    PostToHTTP,192.168.1.20,8080,/receiver.php,'','%lcltime% !!! Temp = [DS1#Temperature] -> Heater ON'
    TaskValueSet,12,1,0
    TaskValueSet,12,2,1
    TaskRun,12
   Endif
Endon

On HeaterOFF Do
  If [Dummy#LoggingOFF] = 1
    PostToHTTP,192.168.1.20,8080,/receiver.php,'','%lcltime% !!! Temp = [DS1#Temperature] -> Heater OFF'
    TaskValueSet,12,1,1
    TaskValueSet,12,2,0
    TaskRun,12
   Endif
Endon
Last edited by TD-er on 08 Dec 2023, 12:09, edited 1 time in total.
Reason: Added [code][/code] tags

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure Operating Time

#2 Post by TD-er » 08 Dec 2023, 12:16

When handling the events for heater on and off, you can perform some calculations and store it in a variable

When starting the heater:

let,1,%syssec_d% // Store current nr of seconds of today in var#1


When stopping the heater:
let,2,[int#2]+%syssec_d%-[int#1] // Add run time to var#2

And at midnight:
// Send value of [int#2] to wherever you need it
SendToHttp,......

let,1,0 // Reset start time
let,2,0 // Reset total counter

trendkill
Normal user
Posts: 31
Joined: 22 Feb 2022, 09:04

Re: Measure Operating Time

#3 Post by trendkill » 08 Dec 2023, 21:55

TD-er wrote: 08 Dec 2023, 12:16 When handling the events for heater on and off, you can perform some calculations and store it in a variable

When starting the heater:

let,1,%syssec_d% // Store current nr of seconds of today in var#1


When stopping the heater:
let,2,[int#2]+%syssec_d%-[int#1] // Add run time to var#2

And at midnight:
// Send value of [int#2] to wherever you need it
SendToHttp,......

let,1,0 // Reset start time
let,2,0 // Reset total counter
Thank you!! I'll try it tomorrow.

trendkill
Normal user
Posts: 31
Joined: 22 Feb 2022, 09:04

Re: Measure Operating Time

#4 Post by trendkill » 09 Dec 2023, 14:48

Works perfectly! Thank you very much!

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure Operating Time

#5 Post by TD-er » 09 Dec 2023, 16:11

You're welcome :)

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Measure Operating Time

#6 Post by Ath » 09 Dec 2023, 19:12

I've added this code, with some small modifications, as an example to the Rules documentation in PR #4899.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 30 guests