Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
Post Reply
boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Thursday 17 May 2018 12:29

It is very important and usefull function. It was in oldest version and I don't know why now is not.

User avatar
waaren
Posts: 608
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by waaren » Thursday 17 May 2018 17:50

Could you check the result of this dzVents script ?
Is this the Global Table you want ? If not can you please elaborate a bit more on what exactly you are looking for ?
Spoiler: show

Code: Select all

--[[ Global table
 ]]--
 
return {
    on =        {   timer = { 'every minute' }  },
      
    logging =   {   level   = domoticz.LOG_DEBUG, 
                    marker = "Global table"},  

    execute = function(dz, trigger)
    
        local seen = {}
        function dumpTable(t,i)
            seen[t] = true
            local s= {}
            local n=0
            for k in pairs(t) do
                n=n+1 s[n]=k
            end
           table.sort(s)
            for k,v in ipairs(s) do
                dz.log(i .. ">" .. v,dz.LOG_DEBUG)
                v=t[v]
                if tostring(type(v))=="table" and not seen[v] then
                    dumpTable(v,i .. ".")
                end
            end
        end

        dumpTable(_G,"")
    
    end
}
Last edited by waaren on Thursday 17 May 2018 23:55, edited 1 time in total.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Thursday 17 May 2018 19:54

I'm sorry but I don't use dzVent script.
My problem is:
1. My harware invoke scripts (http) like: <domoticz_IP>/json.htm?type=command&param=udevices&script=d10.lua&s=1, with 5s interval.
2. Domoticz use d10.lua file (from LUA_parsers directory) to execute script (to read variable s as 1 and save to domoticz by domoticz_updateDevice procedure)
but before domoticz_updateDevice, script checked actual state of sensors and make domoticz_updateDevice only when the state was different.
Now, global tables like otherdevice_svalue are empty. The examples from wiki (LUA Parsers examples) not working too.

DzVent can catch the domoticz_updateDevice procedure and check the actual status before make changes in domoticz databases ?

User avatar
waaren
Posts: 608
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by waaren » Thursday 17 May 2018 21:16

boe666 wrote:
Thursday 17 May 2018 19:54
I'm sorry but I don't use dzVent script.
....
DzVent can catch the domoticz_updateDevice procedure and check the actual status before make changes in domoticz databases ?
@boe666
my approach would be to change the json to send the your sensor data to User variable in Domoticz (User variables do not store history in database)

Code: Select all

http://192.xxx.xxx.xxx:yyyy/json.htm?type=command&param=updateuservariable&vname=tempParse&vtype=2&vvalue=12.65
and trigger dzVents script on User variable changed to check current value and update only when different.
Spoiler: show

Code: Select all


--[[ 
parseTemp.lua
 ]]--
 
return {
    on      =   {   variables   = { "tempParse } },

    logging =   {   level       = domoticz.LOG_DEBUG,                   -- LOG_DEBUG, LOG_INFO or LOG_ERROR
                    marker      = "parseTemp" },

    execute = function(dz, trigger)
        local myTempDevice = dz.devices("your temperature devicename")          
        if dz.utils.round(myTempDevice.temperature,2)  ~= dz.utils.round(trigger.value,2) then
            myTempDevice.updateTemperature(trigger.value)
            dz.log("Device " .. myTempDevice.name .. " updated. New temperature is " .. trigger.value .. "°C. Old temperature was " .. myTempDevice.temperature .. "°C." ,dz.LOG_DEBUG)
        else
            dz.log("Device " .. myTempDevice.name .. " does not need an update. Temperature is " .. dz.utils.round(trigger.value,2) .. "°C" ,dz.LOG_DEBUG)
        end    
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Friday 18 May 2018 17:29

how i can define uservariables ?
Where can I find some examples of this dzVent triggers ?

User avatar
waaren
Posts: 608
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by waaren » Friday 18 May 2018 19:55

boe666 wrote:
Friday 18 May 2018 17:29
how i can define uservariables ?
Where can I find some examples of this dzVent triggers ?
If you press the show button after the word spoiler in my previous post you will see a dzVents script that will execute every time the user variable is updated.
You can read everything needed on dzVents in the wiki

For uservariables please have a look here
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Wednesday 23 May 2018 22:05

I write some code in my script:
commandArray = {}
print ("Write to test1");
local alarm_ruch = uri['a'];
print ("Variable val:");print(alarm_ruch);
commandArray['Variable:test1'] = tostring(alarm_ruch);
print ("End Writing");

but value of my variable (defined in domoticz in uservariable section) has no change.
i think lua_parsers script has no access to commandArray table.....
How can I send this value to the uservariable with json method ?

I use json.htm?type=command&param=udevices&script=d10.lua&s=1&a=5&f=5... because i can send many variables in one pass, and my harware (http gateway) has limit of char in url (255 chars).

boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Friday 25 May 2018 11:29

Any body know WHY access to global tables and global variables is disables in LUA_Parsers script ????

boe666
Posts: 24
Joined: Thursday 19 January 2017 17:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.

Post by boe666 » Friday 25 May 2018 12:30

OK, it was my mistake.... I'm sorry for my indolence...
my scripts has no access to global tables becouse i don't turn on this function....

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests