Geting data form table

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

Moderator: leecollings

Post Reply
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Geting data form table

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Geting data form table

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Geting data form table

Post by rkarolek »

tyvm, it works
but cant understand diference :( problem was lack of [0] table's value or declare local varible on start script?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Geting data form table

Post 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

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Geting data form table

Post by rkarolek »

realy?
lol, omg....
tyvm once more for your time
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest