Page 1 of 1

Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 14:20
by Freemann
I moving some lua scripting to dzVents and while reading the docs I found "smoothItem(itemIdx, [smoothRange])" but have no idea how to use it.

Here's my dzVents script;

Code: Select all

-- Check the wiki at
-- http://www.domoticz.com/wiki/%27dzVents%27:_next_generation_LUA_scripting
return {
	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script
	-- trigger
	-- can be a combination:
	on = {devices = {'DummyTest'},timer = {}},
    data = {
            achtertuinRaamLux = { history = true, maxItems = 10 }
    },
	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, device)
	    domoticz.data.achtertuinRaamLux.add(domoticz.devices('AchtertuinRaamLux').lux)
	    -- how further with 'smoothItem(itemIdx, [smoothRange])' ?
	end
}
Many thanks in advance and maybe someone could add some example code to the tutorial/docs :)

Re: Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 15:46
by dannybloe
Well you build up a history of lux readings. At some point you want to do queries on those readings. So you could get the latest/youngest value or perhaps the 5th reading from now in the past . Then you will get the exact value that you've put into the history.

Code: Select all

local lux5=domoticz.data.achtertuinRaamLux.get(5) 
But you can also get the smoothed value at that 5th location in time which is an average over a few readings before and a few readings after the 5th item. You do this to average out fluctuations in your readings.

Code: Select all

local lux5smoothed = domoticz.data.achtertuinRaamLux.smoothItem(5, 2)
In this case you average the reading at indx 3,4,5,6 and 7 (2 around 5th item).

Note that idx=1 is the youngest reading.

Re: Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 19:42
by Freemann
ok thanx!

Seeying the following table and chart i'm wondering how to get such data table/chart.
https://www.domoticz.com/wiki/index.php ... _smoothing

Is there some sort of example how to do this?

Re: Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 19:58
by dannybloe
Excel ;)

Re: Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 20:29
by Freemann
dannybloe wrote:Excel ;)
thanks for you constructive answer!

The smoothItem() and the docs suggest that it, under the hood, generates an lua table (which can be printed with domoticz.log() ;) ) with data points.
If so, how to get these datapoinst.
If not, how could I build such a table with this function.

Re: Howto use "smoothItem(itemIdx, [smoothRange])"?

Posted: Sunday 06 August 2017 20:49
by dannybloe
That easy!

Code: Select all

domoticz.data.myHistory.forEach(function(item,index)
    local s=domoticz.data.myHistory.smoothItem(index, 3)
    domoticz.log(item.data .. ', ' .. s)
 end)
Something like that.