Page 1 of 1
Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Thursday 17 May 2018 12:29
by boe666
It is very important and usefull function. It was in oldest version and I don't know why now is not.
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Thursday 17 May 2018 17:50
by waaren
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
}
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Thursday 17 May 2018 19:54
by boe666
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¶m=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 ?
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Thursday 17 May 2018 21:16
by waaren
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¶m=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
}
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Friday 18 May 2018 17:29
by boe666
how i can define uservariables ?
Where can I find some examples of this dzVent triggers ?
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Friday 18 May 2018 19:55
by waaren
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
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Wednesday 23 May 2018 22:05
by boe666
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¶m=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).
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Friday 25 May 2018 11:29
by boe666
Any body know WHY access to global tables and global variables is disables in LUA_Parsers script ????
Re: Access to Global Tables (ie. otherdevice_svalue) in LUA_Parsers scripts.
Posted: Friday 25 May 2018 12:30
by boe666
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....