relay operating time measurement

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tiger125
New user
Posts: 6
Joined: 03 Feb 2021, 10:08

relay operating time measurement

#1 Post by tiger125 » 26 Dec 2023, 21:00

Hi,

I want to make a measurement!
The gas boiler turns on a relay (230VAC), whose independent pole output short-circuits the input of a nodemcu (D5).
The time should be measured in the tightened state, when the relay pulls and drops!
What is the rule for this, because I couldn't find one!

Since the gas boiler has a fixed consumption, the consumption can be recovered from the time!

I look forward to your ideas

Csaba

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

Re: relay operating time measurement

#2 Post by Ath » 26 Dec 2023, 21:49

I've recently added some example code, based on an answer to a very similar question, to the documentation in a pull request on Github, over here. This hasn't been merged yet, but it is quite readable, IMHO.

The example was based on this thread
/Ton (PayPal.me)

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

Re: relay operating time measurement

#3 Post by Ath » 27 Dec 2023, 21:28

Not sure if you succeeded in writing the rules to handle this, but I saw a chance to add another example to the documentation, so I built this:

- Add the Generic - Dummy Device, as described in the code
- Adjust the On TransmitPower Do event so the data gets sent where you need it, or comment out the code if it doesn't have to be transmitted
- After pasting this code in a Rules file either reboot the ESP, or run command event,System#boot to initialize the Monitor command and the power value in Watt (you may have to adjust that to your situation)
(check if you don't already have a On System#Boot Do event in there, if so, add the code from this one to your existing On System#Boot code, and leave the code from this example out)

Code: Select all

// Uses a Generic - Dummy Device, name: Power, output data type: Dual, first value: Seconds (0 decimals), second value: PowerUsed (4 decimals)

On GPIO#14 Do // GPIO-14 = D5 on Wemos boards
  If %eventvalue1%=0 // On state
    Let,1,%syssec_d% // Store current nr of seconds of today in var#1
  Else // Off state
    Event,CalcPower // Don't queue
    AsyncEvent,TransmitPower // Send out to receiver
  Endif
  Let,5,!%eventvalue1% // 0 = On, to invert on/off state change to: Let,5,%eventvalue1%
  LogEntry,"Power [int#5#O#C], measured: [Power#Seconds] sec. [Power#PowerUsed#d.4] kWh"
Endon

On CalcPower Do
  TaskValueSet,Power,Seconds,[Power#Seconds]+%syssec_d%-[int#1] // Add run time to Power#Seconds
  Let,4,[Power#Seconds]*[var#3] // Wattseconds
  If [var#4]>0
    TaskValueSet,Power,PowerUsed,[var#4]/3600000 // Wattseconds to kWh
  Endif
  TaskRun,Power
Endon

On TransmitPower Do
  // Send value of [Power#Seconds] and [Power#PowerUsed] to wherever you need it, adjust as needed
  PostToHTTP,192.168.1.20,8080,/receiver.php,'','%lcltime% !!! Total RunningTime = [Power#Seconds] Seconds, PowerUsed = [Power#PowerUsed] kWh'
Endon

On Clock#Time=All,00:00 Do // At midnight
  // Include power used until midnight
  If [Plugin#GPIO#PinState#14]=0 // Still on?
    Event,CalcPower // Don't queue
  Endif
  Let,1,0 // Reset start time
  Event,TransmitPower // Send out remainder of the day immediately
  TaskValueSet,Power,Seconds,0 // Reset total counter
  TaskValueSet,Power,PowerUsed,0 // Reset total power
Endon

On System#Boot Do
  Monitor,gpio,14 // Generate an event when the GPIO state changes
  Let,3,250 // Wattage of the load, adjust as needed
Endon
/Ton (PayPal.me)

tiger125
New user
Posts: 6
Joined: 03 Feb 2021, 10:08

Re: relay operating time measurement

#4 Post by tiger125 » 28 Dec 2023, 10:13

Hi,

Thanks for the help!
The program is very good as a starting point.

Csaba

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

Re: relay operating time measurement

#5 Post by Ath » 28 Dec 2023, 11:17

Thanks, you're welcome

Instead of the 'kWh' unit I used, you can of course use 'kCal/hr' or your measure of choice for the heater-used energy, you probably need to adjust the calculation factor for that ;)
/Ton (PayPal.me)

Post Reply

Who is online

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