Page 1 of 1

Geting data form table

Posted: Saturday 03 November 2018 13:09
by rkarolek
Hi id like to declare local table variable, and get data depends other variable,
Is it possible to do it?
i try something like that but w/o success :(

Code: Select all

local LED_Sunny    = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

return {
   on = {
  	timer = {'every minutes'}    --uruchomienie skryptu co minute
   },
   
   logging = {
       level = domoticz.LOG_INFO,
       marker = "A100_test"
   },
   
   execute = function(domoticz)
       domoticz.log('function ')

	Time = domoticz.time.rawTime
	HH = domoticz.time.hour
	MM = domoticz.time.minutes
	
	domoticz.log('hour   ')
	domoticz.log(HH)
	domoticz.log('min   ')
	domoticz.log(MM)
	
    domoticz.log('LED   ')
    domoticz.log(LED_Sunny(HH))
	
end
}

in log i got this msg

Code: Select all

2018-11-03 13:03:00.378 Status: dzVents: Error (2.4.6): A100_test: ...domoticz/scripts/dzVents/generated_scripts/A100_test.lua:32: attempt to call upvalue 'LED_Sunny' (a table value)
any idea?

Re: Geting data form table

Posted: Saturday 03 November 2018 14:05
by waaren
rkarolek wrote: Saturday 03 November 2018 13:09 Hi id like to declare local table variable, and get data depends other variable,
Is it possible to do it?
i try something like that but w/o success :(

any idea?
Yes, it is possible and you were very close.
Look at the example below for right syntaxis. Be aware that a Lua array (which are in fact a table indexed with sequential integers) start with 1 when indexed implicitly.
what you do with LED_Sunny = {0,0,0,0} is telling Lua

LED_Sunny[1] = 0,
LED_Sunny[2] = 0,
LED_Sunny[3] = 0,
LED_Sunny[4] = 0

Code: Select all

return {
   on = {
  	timer = {'every minutes'}    --uruchomienie skryptu co minute
   },
   
   logging = {
       level = domoticz.LOG_INFO,
       marker = "A100_test"
   },
   
   execute = function(domoticz)
        local LED_Sunny    = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0,0,0,0,0,0,0}
        LED_Sunny[0] = 0        -- 0 is a "special"case" as Lua arrays start with 1
        
        domoticz.log('function ')

        Time = domoticz.time.rawTime
        HH = domoticz.time.hour
        MM = domoticz.time.minutes
        
        domoticz.log('hour   ')
        domoticz.log(HH)
        domoticz.log('min   ')
        domoticz.log(MM)
        
        domoticz.log('LED   ' .. LED_Sunny[HH])
    end
}

Re: Geting data form table

Posted: Saturday 03 November 2018 14:37
by rkarolek
tyvm, it works
but cant understand diference :( problem was lack of [0] table's value or declare local varible on start script?

Re: Geting data form table

Posted: Saturday 03 November 2018 18:48
by waaren
No. Real reason was your use of (HH), where it should have been [HH]
rkarolek wrote:tyvm, it works
but cant understand diference :( problem was lack of [0] table's value or declare local varible on start script?
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk


Re: Geting data form table

Posted: Saturday 03 November 2018 21:19
by rkarolek
realy?
lol, omg....
tyvm once more for your time