Page 1 of 1
dz vents runaway electrical sensor
Posted: Tuesday 26 June 2018 13:34
by tillo
HI, I am having a script that checks the status of the pool heater, and logs the electrical usage of it. Sadly I have probably fucked something up, because my virtuel electrical sensor have a run away problem. After 24h it has a value of 50*10^4 KWH after 48h 85*10^9 and so on.....
The script is run every minute and checks if the heater is on/off. The heater is on 3000W
so i take the sensor assignee it 3000W and takes old consumption value + the consumption for one minute (3000/60) = 50 watt per minute.
Pleas see the code below. If anyone know what I have done to get myselfe into this mess pleas help.
Code: Select all
if(pool_heater == On) then
power = 3000; // 3000W when heat is on
energy = 50; //3000w/60min = 50w per minute
energy = pool_heater_COUNTER.WhToday + energy;
else
power = 0; // 0w when off
energy = pool_heater_COUNTER.WhToday ; //if the heater is off, we should use the old value
end
pool_heater_COUNTER.updateElectricity(power, energy);
Re: dz vents runaway electrical sensor
Posted: Tuesday 26 June 2018 13:51
by SweetPants
Are you sure this is a dzVents script? Does not look like LUA
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 14:04
by rogzon
If you decide to use dzVents in domoticz you could use this:
Code: Select all
return {
active = true, -- set to false to disable this script
on = {
devices = {
'THE NAME OF YOUR POOL HEATER SWITCH',
}
},
execute = function(domoticz, device)
if(device.state=='On') then
domoticz.variables('slaskOnCount').set(os.time())
else
print('Energi= ' .. (((((os.time() - domoticz.variables('slaskOnCount').value)/60)/60)*3000)/1000) .. ' kWh')
domoticz.variables('slaskEnergyTot').set(domoticz.variables('slaskEnergyTot').value + (((((os.time() - domoticz.variables('slaskOnCount').value)/60)/60)*3000)/1000))
end
end
}
The uservariable "slaskEnergyTot" would be a double and contains the energy consumed in kWh.
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 14:24
by tillo
@rogzon , Since you used the word "slask" I assume that you are from probably Sweden, or Norway?
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 14:32
by rogzon
Absolut! Norrland!
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 14:52
by tillo
Härligt Stockholm (y)
Då kan vi ta det på svenska, så kan vi skriva lösningen på engelska när vi hittat felet.
Det är inte hela mitt script som jag postade. Utan bara den delen som var relevant. Men det borde vara ett korrekt dz vent script?
Så fort jag kommit hem så kan jag posta mer utav scriptet.
Men jag misstänker att felet ligger i
Code: Select all
energy = pool_heater_COUNTER.WhToday + 3000/60;
och
Code: Select all
pool_heater_COUNTER.updateElectricity(power, energy);
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 14:54
by tillo
kWh, Electricity (instant and counter)
counterToday: Number.
updateElectricity(power, energy): Function. Supports command options.
usage: Number.
WhToday: Number. Total Wh usage of the day. Note the unit is Wh and not kWh!
WhTotal: Number. Total Wh usage.
WhActual: Number. Actual reading.
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 16:06
by rogzon
Så för att förstå detta.. Du vill ha ett device under "Utility" (kom inte ihåg vad det är på svenska) som visar 3000W när den är på och 0 när den är av samt att den visar energi för dygnet och totalt?
Det visar sig att det device som heter Electrical(instant+counter) inte funkar riktigt som det skall.
Återkommer i frågan, skall kolla lite närmare vad som pågår..
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 16:42
by freijn
Al jullie Engels typen kunnen we allemaal mee lezen met de antwoorden en er ook misschien wat van leren
Re: dz vents runaway electrical sensor
Posted: Wednesday 27 June 2018 23:15
by rogzon
Okay, let's speak English then...
I found this discussion:
viewtopic.php?t=22117
It would seem as if this is your biggest problem. A workaround would would be to do the calculations yourself.
The downside on that workaround would be that you would need one device each for kwh/day and total.
I haven't been able to update anything else but energy in an Electrical(instant+counter) so that wouldn't work.
Anyone else have an idea?
Re: dz vents runaway electrical sensor
Posted: Thursday 28 June 2018 11:17
by tillo
Loool, Well German are always welcome.
Okey, lets stick with English.
I Have cleaned away some of the code to make it more understandable. See below
Code: Select all
return {
on = {
devices = {'myDevice'},
timer = {'every 1 minutes'}
},
execute = function(domoticz, device)
heater_kwh_obj = domoticz.devices('Pool - Heater (kWh)'); -- 'Pool - Heater (kWh)' is of object typ: kWh, Electricity (instant and counter)
if(json_respons["Heater"] == 'On') then
heater_kwh_obj.updateElectricity(3000,heater_kwh_obj.WhToday+3000*(1/60));
else
heater_kwh_obj.updateElectricity(0,heater_kwh_obj.WhToday);
end
end
}
Re: dz vents runaway electrical sensor
Posted: Friday 29 June 2018 23:50
by rogzon
@tillo,
If you read carefully the topic I sent in my last post you will see that there is a bug in dzVent/domoticz.
The device Electrical(instant+counter) should normally get both power in Watts and the Energy in kWh from a sensor of some kind.
You don't have a sensor that gives you any updates so you were planning to do the update yourself.
Using dzVents would be the easiest way to do this, however the bug mentioned in the topic states that it is not working.
In the device Electrical(instant+counter) you have two options (not when creating the device but when pushing Edit in the utility screen!!), one option expects both power and energy updates from sensor and the second option needs only updating of power value.
For the second option the device/domoticz then calculates the energy reading by itself (pretty handy device).
If you know that you have 3000W of power to your pool heater you need only to update one value and that is the power value to the device.
There is a workaround:
By writing the power value to the device via json api the device do calculate correct energy values.
This is how I did:
Code: Select all
return {
on = {
timer = {
'every minute'
}
},
execute = function(domoticz, device)
if (domoticz.devices('anslut3').state=='On') then
domoticz.openURL({
url = 'http://192.168.40.96:8080/json.htm?type=command¶m=udevice&idx=327&nvalue=0&svalue=3000;0',
method = 'GET'})
else
domoticz.openURL({
url = 'http://192.168.40.96:8080/json.htm?type=command¶m=udevice&idx=327&nvalue=0&svalue=0;0',
method = 'GET'})
end
end
}
I used a switch called "anslut3" as your pool-heater switch for test and when it is on dzVents issues a command to domoticz via json api (thats the openURL function) to update the device with id 327 ( thats the Electrical(instant+counter)), at the end of the URL (svalue) the power and energy values goes.
This script is tested and works!
/R
Re: dz vents runaway electrical sensor
Posted: Monday 02 July 2018 11:20
by tillo
Interesting approach. I will give it a try as soon as I get home.
I did read the link you sent me, but I could not make heads or tails out of it until I read your response and example code.