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

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

Moderator: leecollings

Post Reply
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

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

Post 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 :)
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

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

Post 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?
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post by dannybloe »

Excel ;)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

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

Post 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.
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

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