Persistent data + average = errors

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Persistent data + average = errors

Post by wizzard72 »

I'm strugeling with persistant data. I'm created the following script (based on the script in the wiki):

Code: Select all

return {	
    active = true,
    logging = {
		level = domoticz.LOG_INFO,
		marker = 'TEST '
	},
	on = {
		devices  = {
			'Wasmachine (W)'
		},
	},
	data = {
        temperatures = { history = true, maxMinutes = 6 }
    },

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, device)

        domoticz.data.temperatures.add(device.state)
        local average = domoticz.data.temperatures.avg()

	end
}
The log shows the following errors:
2017-09-28 19:57:35.864 dzVents: Info: TEST : ------ Start internal script: dzVentsTest: Device: "Wasmachine (W) (AeonLabs)", Index: 534
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : Item data is not a number type. Type is nil
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : Item data is not a number type. Type is nil
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : Item data is not a number type. Type is nil
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : Item data is not a number type. Type is nil
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : Item data is not a number type. Type is nil
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : An error occured when calling event handler dzVentsTest
2017-09-28 19:57:35.866 Error: dzVents: Error: TEST : ...i/domoticz/scripts/dzVents/runtime/HistoricalStorage.lua:288: attempt to perform arithmetic on local 'sum' (a nil value)
Can someone help me?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Persistent data + average = errors

Post by dannybloe »

Well. I think it is because apparantly what you add to the variable is not a number. I doubt your device has a state. I assume you want to add temperatures in your variable so I guess you want to add device.temperate or something similar. On the other hand I wonder if a washinmachine device has a temperature at all. Anyway, in order for the avg function ro work it needs numbers.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Persistent data + average = errors

Post by wizzard72 »

Don't let the tempertures variable name mislead you :-) It stores the actual energy usage of my washing machine.

The datafile looks like this:

Code: Select all

-- Persistent Data
local multiRefObjects = {

} -- multiRefObjects
local obj1 = {
        ["temperatures"] = {
                [1] = {
                        ["data"] = "0.0";
                        ["time"] = "2017-09-28 17:56:01";
                };
                [2] = {
                        ["data"] = "0.0";
                        ["time"] = "2017-09-28 17:55:49";
                };
                [3] = {
                        ["data"] = "0.0";
                        ["time"] = "2017-09-28 17:53:01";
                };
                [4] = {
                        ["data"] = "0.0";
                        ["time"] = "2017-09-28 17:52:48";
                };
        };
}
return obj1
It stores the energy (Watts) in the data portion of the datafile. How can I calculate the average (this example datafile it's not very sensible :-) ).
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Persistent data + average = errors

Post by dannybloe »

You have to check the docs for energy devices as they have specific attributes for usage like WhActual. These are numbers. The state attribute is a string value.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Persistent data + average = errors

Post by wizzard72 »

Thanks dannybloe for sorting this out. It is working now.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest