dz vents runaway electrical sensor

Easy to use, 100% Lua-based event scripting framework.
Post Reply
tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

dz vents runaway electrical sensor

Post by tillo » Tuesday 26 June 2018 13:34

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);

Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

SweetPants
Posts: 2349
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10196
Location: The Netherlands
Contact:

Re: dz vents runaway electrical sensor

Post by SweetPants » Tuesday 26 June 2018 13:51

Are you sure this is a dzVents script? Does not look like LUA
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dz vents runaway electrical sensor

Post by rogzon » Wednesday 27 June 2018 14:04

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.

tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

Re: dz vents runaway electrical sensor

Post by tillo » Wednesday 27 June 2018 14:24

@rogzon , Since you used the word "slask" I assume that you are from probably Sweden, or Norway?
Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dz vents runaway electrical sensor

Post by rogzon » Wednesday 27 June 2018 14:32

Absolut! Norrland!

tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

Re: dz vents runaway electrical sensor

Post by tillo » Wednesday 27 June 2018 14:52

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);
Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

Re: dz vents runaway electrical sensor

Post by tillo » Wednesday 27 June 2018 14:54

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.
Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dz vents runaway electrical sensor

Post by rogzon » Wednesday 27 June 2018 16:06

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..

freijn
Posts: 392
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: dz vents runaway electrical sensor

Post by freijn » Wednesday 27 June 2018 16:42

Al jullie Engels typen kunnen we allemaal mee lezen met de antwoorden en er ook misschien wat van leren :-(

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dz vents runaway electrical sensor

Post by rogzon » Wednesday 27 June 2018 23:15

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?

tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

Re: dz vents runaway electrical sensor

Post by tillo » Thursday 28 June 2018 11:17

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
}
Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dz vents runaway electrical sensor

Post by rogzon » Friday 29 June 2018 23:50

@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&param=udevice&idx=327&nvalue=0&svalue=3000;0',
                        method = 'GET'})
            else
                		        domoticz.openURL({
                        url = 'http://192.168.40.96:8080/json.htm?type=command&param=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

tillo
Posts: 40
Joined: Monday 01 May 2017 20:15
Target OS: Raspberry Pi
Domoticz version: 3.9030
Contact:

Re: dz vents runaway electrical sensor

Post by tillo » Monday 02 July 2018 11:20

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.
Raspberry Pi 2 B - Raspbian Jessie + Domoticz + RFXtrxcom 433, House(dimmers, sockets, harmonyhub, Temp / Humidity Sensors, PIR, ESP8266)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest