Page 1 of 1
Average current for valve
Posted: Friday 03 January 2025 13:25
by PeterRozenveld
I would like to use the average value instead of the absolute because Bosch Cooktop uses PWM and occasionally the current is zero!
Does anyone have an idea? How to make that with dzVents?
And maybe it would be useful , but am not so at home with wifi (Shelly) relays, to ask if the valve is already closed.
Code: Select all
return {
on = {
timer = {'every 10 minutes'},
},
execute = function(domoticz)
local kpmt1 = domoticz.devices('Kookplaat_F1_(Rechts)') -- Fase meting L1 Kookplaat Rechts
local kpmt2 = domoticz.devices('Kookplaat_F3_(Links_Flexzone)') -- Fase meting L3 Kookplaat Links
-- Kijken of de stroom nul is
if kpmt1.actualWatt < 50 and kpmt2.actualWatt < 50 then
domoticz.openURL('http://192.168.2.172/relay/0?turn=off')
domoticz.log('klep closed', domoticz.LOG_INFO)
end
end
}
Re: Average current for valve
Posted: Friday 03 January 2025 18:25
by waltervl
For avarage calculation over x measurements see for example topic
viewtopic.php?t=38305
Re: Average current for valve
Posted: Saturday 04 January 2025 10:40
by PeterRozenveld
Code: Select all
return
{
on = {
devices = {'Test Total solar radiation'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'SEM228T',
},
data =
{
SEM228THistory = { history = true, maxMinutes = 10},
},
execute = function(domoticz, sensor)
-- add new data
domoticz.data.SEM228THistory.add(sensor.radiation)
-- average
local RadAverage = domoticz.data.SEM228THistory.avg()
domoticz.log('average radiation ' .. RadAverage, domoticz.LOG_INFO)
end
}
The solved code from your Link. That's a start.
Now I should actually add those values together from Phase 1 and Phase 2 , another hint , how to add the 2 together ?
Well thanks in advance. For me, English as a beta is quite complicated and I am getting rusty.
Re: Average current for valve
Posted: Saturday 04 January 2025 11:13
by waltervl
Just put phase1 and 2 in separate history data tables in the same script.
Trigger the script every minute instead of every 10 minutes.
Re: Average current for valve
Posted: Saturday 04 January 2025 13:06
by PeterRozenveld
First for Phase 1 this:
Code: Select all
return
{
on = {
devices = {'Kookplaat_F1_(Rechts)'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Kookrechts',
},
data =
{
kpmt1_History = { history = true, maxMinutes = 10},
},
execute = function(domoticz, sensor)
-- add new data
domoticz.data.kpmt1_History.add(sensor.actualWatt)
-- average
local CurForn1Average = domoticz.data.kpmt1_History.avg()
domoticz.log('average stroom1 ' .. CurForn1Average, domoticz.LOG_INFO)
end
}
The result is this:
Code: Select all
2025-01-04 13:00:50.976 Status: dzVents: Info: Handling events for: "Kookplaat_F1_(Rechts)", value: "0.0"
2025-01-04 13:00:50.976 Status: dzVents: Info: Kookrechts: ------ Start internal script: 11_F1_gem_stroom: Device: "Kookplaat_F1_(Rechts) (AeonStick voor Z-wave)", Index: 590
2025-01-04 13:00:50.977 Status: dzVents: Info: Kookrechts: average stroom1 0.0
2025-01-04 13:00:50.977 Status: dzVents: Info: Kookrechts: ------ Finished 11_F1_gem_stroom
Now look or as you said; put the 2 phases in one script.
It's been 40 years since I last programmed in Pascal
Greetings Peter
Re: Average current for valve
Posted: Sunday 05 January 2025 0:32
by PeterRozenveld
I feel a trigger is missing ?
Can a timer be a solutions, ?
And how do I get the logged stream values into another script now ?
Peter
Code: Select all
return
{
on = {
devices = {'Kookplaat_F1_(Rechts)', 'Kookplaat_F3_(Links_Flexzone)'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'GemKookstroom',
},
data =
{
kpmt1_History = { history = true, maxMinutes = 2},
kpmt2_History = { history = true, maxMinutes = 2},
},
execute = function(domoticz, sensor)
local kpmt1 = domoticz.devices('Kookplaat_F1_(Rechts)')
local kpmt2 = domoticz.devices('Kookplaat_F3_(Links_Flexzone)')
-- add new data kpmt1
domoticz.data.kpmt1_History.add(kpmt1.actualWatt)
-- average for Phase 1
local CurForn1Average = domoticz.data.kpmt1_History.avg()
domoticz.log('average stroom1 ' .. CurForn1Average, domoticz.LOG_INFO)
-- add new data kpmt2
domoticz.data.kpmt2_History.add(kpmt2.actualWatt)
-- average for Phase 2
local CurForn2Average = domoticz.data.kpmt2_History.avg()
domoticz.log('average stroom2 ' .. CurForn2Average, domoticz.LOG_INFO)
end
}
LOG:
Code: Select all
2025-01-05 00:17:14.867 Status: dzVents: Debug: GemKookstroom: Processing device-adapter for Kookplaat_F1_(Rechts): Electric usage device adapter
2025-01-05 00:17:14.867 Status: dzVents: Info: GemKookstroom: average stroom1 1.7
2025-01-05 00:17:14.868 Status: dzVents: Info: GemKookstroom: average stroom2 1.275
2025-01-05 00:17:14.869 Status: dzVents: Info: GemKookstroom: ------ Finished 11_F1en3_gem_stroom
Re: Average current for valve
Posted: Sunday 05 January 2025 13:08
by waltervl
I dont know why you think a trigger is being missed?
Why do you need the value in another script? You can add the switching logic for the Shelly in this script.
Re: Average current for valve
Posted: Monday 06 January 2025 13:25
by PeterRozenveld
Like this:
Its working!
Code: Select all
return {
on = {
timer = {'every 1 minutes'},
devices = {'Kookplaat_F1_(Rechts)', 'Kookplaat_F3_(Links_Flexzone)'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'OffdoorGemKookstroom',
},
data =
{
kpmt1_History = { history = true, maxMinutes = 2},
kpmt2_History = { history = true, maxMinutes = 2},
},
execute = function(domoticz)
local kpmt1 = domoticz.devices('Kookplaat_F1_(Rechts)') -- Fase meting L1 Kookplaat Rechts
local kpmt2 = domoticz.devices('Kookplaat_F3_(Links_Flexzone)') -- Fase meting L3 Kookplaat Links
-- add new data kpmt1
domoticz.data.kpmt1_History.add(kpmt1.actualWatt)
-- average for Phase 1
local CurForn1Average = domoticz.data.kpmt1_History.avg()
domoticz.log('average stroom1 ' .. CurForn1Average, domoticz.LOG_INFO)
-- add new data kpmt2
domoticz.data.kpmt2_History.add(kpmt2.actualWatt)
-- average for Phase 2
local CurForn2Average = domoticz.data.kpmt2_History.avg()
domoticz.log('average stroom2 ' .. CurForn2Average, domoticz.LOG_INFO)
-- Kijken of de stroom laag is
-- if kpmt1.actualWatt < 50 and kpmt2.actualWatt < 50 and CurForn2Average < 5 and CurForn1Average <5 then
if CurForn1Average < 5 and CurForn2Average <5 then
domoticz.openURL('http://192.168.2.172/relay/0?turn=off')
domoticz.log('klep closed', domoticz.LOG_INFO)
end
end
}
Thanks for your help!
Peter
Re: Average current for valve
Posted: Monday 06 January 2025 13:35
by lost
An arithmetic average will not work for such device that usually report (a few %) changes over time with varying samples timings. This needs some discrete integration (summing 'current sample value ' * 'time to next sample', in the end divided by summing/averaging time) to get reliable values.
Re: Average current for valve
Posted: Monday 06 January 2025 13:49
by waltervl
lost wrote: ↑Monday 06 January 2025 13:35
An arithmetic average will not work for such device that usually report (a few %) changes over time with varying samples timings. This needs some discrete integration (summing 'current sample value ' * 'time to next sample', in the end divided by summing/averaging time) to get reliable values.
TS only wants to now if the avarage is 0 A for some time. There is no need te be exact...
Re: Average current for valve
Posted: Tuesday 07 January 2025 12:34
by PeterRozenveld
Thanks all ,
I have extended the script slightly ,
so that the fan (192.168.2.171) enters a kind of shutdown phase and
extends the average value because otherwise I will start commuting the valve (192.168.2.172) .
Fan ip end's 171
Valve ip end's 172
Greets, Peter
Code: Select all
return {
on = {
timer = {'every 1 minutes'},
devices = {'Kookplaat_F1_(Rechts)', 'Kookplaat_F3_(Links_Flexzone)', 'AF1'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'OffdoorGemKookstroom',
},
data =
{
kpmt1_History = { history = true, maxMinutes = 5},
kpmt2_History = { history = true, maxMinutes = 5},
},
execute = function(domoticz)
local kpmt1 = domoticz.devices('Kookplaat_F1_(Rechts)') -- Fase meting L1 Kookplaat Rechts
local kpmt2 = domoticz.devices('Kookplaat_F3_(Links_Flexzone)') -- Fase meting L3 Kookplaat Links
local AF1s = domoticz.devices('AF1') -- Voorwaarde stroom laag
-- add new data kpmt1
domoticz.data.kpmt1_History.add(kpmt1.actualWatt)
-- average for Phase 1
local CurForn1Average = domoticz.data.kpmt1_History.avg()
domoticz.log('average stroom1 ' .. CurForn1Average, domoticz.LOG_INFO)
-- add new data kpmt2
domoticz.data.kpmt2_History.add(kpmt2.actualWatt)
-- average for Phase 2
local CurForn2Average = domoticz.data.kpmt2_History.avg()
domoticz.log('average stroom2 ' .. CurForn2Average, domoticz.LOG_INFO)
-- Kijken of de stroom laag is
-- if kpmt1.actualWatt < 50 and kpmt2.actualWatt < 50 and CurForn2Average < 5 and CurForn1Average <5 then
if CurForn1Average < 5 and CurForn2Average <5 then
domoticz.openURL('http://192.168.2.172/relay/0?turn=off')
domoticz.log('klep closed', domoticz.LOG_INFO)
end
if CurForn1Average < 35 and CurForn2Average < 35 and AF1s.state == 'Off' then
domoticz.openURL('192.168.2.171/light/0?turn=on&brightness=18')
domoticz.log('shutting down', domoticz.LOG_INFO)
end
end
}