Hi.
I have a little problem witch sctipts located in lua_parses directory: I have no access to global tables like otherdevices, otherdevices_lastupdate and otherdevices_svalues. When i try do check some values in this tables, i have an error in log: (...) variable is nil.
I use this script to update values. My hardware call the spcial URL JSON.
Can you help me ?
global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
Moderator: leecollings
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
The latest beta has these added, they are not on the stable I'm afraid...
-
- Posts: 46
- Joined: Thursday 19 January 2017 16:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
ok, so it's a normal situation in newest stable version or not ? In the new version (unstable for now) it's working ?
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
Yes, more info e.g. here: viewtopic.php?p=115099
It's true that in some betas there might be issues, therefore I do not usually update immediately. But I've noticed there has been issues in the stable ones as well - at the time of release at least (fixed very soon of course). So, for the 2½ years I've been using Domoticz I cannot remember any specific issues arising from the fact that I've been on beta and not on stable. But yes, there's of course the risk (therefore daily full backups)...
It's true that in some betas there might be issues, therefore I do not usually update immediately. But I've noticed there has been issues in the stable ones as well - at the time of release at least (fixed very soon of course). So, for the 2½ years I've been using Domoticz I cannot remember any specific issues arising from the fact that I've been on beta and not on stable. But yes, there's of course the risk (therefore daily full backups)...
-
- Posts: 3
- Joined: Friday 06 January 2017 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
i can't tell why it is not working for you, it does for me.
test if this is a solution for you.
sorry i misunderstood you did miss the lua_parses directory reference. but the solution might still be usable
test if this is a solution for you.
Code: Select all
tAllDevicesById = {}
tAllDevicesByName = {}
function getMoreDeviceInformation()
-- by calling this function you can get much more information about a device, eg the number of dim levels
--[[
Attributes available:
AddjMulti; AddjMulti2; AddjValue; AddjValue2; BatteryLevel; CustomImage; Data; Description; Favorite;
HardwareID; HardwareName; HardwareType; HardwareTypeVal; HaveDimmer; HaveGroupCmd; HaveTimeout; ID;
Image; IsSubDevice; LastUpdate; Level; LevelInt; MaxDimLevel; Name; Notifications; PlanID; PlanIDs;
Protected; ShowNotifications; SignalLevel; Status; StrParam1; StrParam2; SubType; SwitchType;
SwitchTypeVal; Timers; Type; TypeImg; Unit; Used; UsedByCamera; XOffset; YOffset; idx
--]]
local sUrl = 'localhost'
local sPort = '8082'
local json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- get all the device info needed, since it is not available in lua
local config=assert(io.popen('curl http://'..sUrl..':'..sPort..'/json.htm?type=devices'))
local jsonDevice = config:read('*all')
config:close()
local tDevices = json:decode(jsonDevice)
-- put it in tables for easy access
for k,v in pairs(tDevice['result']) do
--print( "index : " .. k .. " = " .. v['idx'])
tAllDevicesById[v['idx']] = v
tAllDevicesByName[v['Name']] = v
end
end
-
- Posts: 46
- Joined: Thursday 19 January 2017 16:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
I tried... result: 2017-01-24 14:15:05.479 Error: CLuaHandler: /home/pi/domoticz/scripts/lua_parsers/d10.lua:27: attempt to index global 'tDevice' (a nil value).
I upgrade domoticz to latest version (unstable) and now it's ok. Example like this:
"function LogVariables(x,depth,name)
for k,v in pairs(x) do
if (depth>0) or ((string.find(k,'device')~=nil) or (string.find(k,'variable')~=nil) or.
(string.sub(k,1,4)=='time') or (string.sub(k,1,8)=='security')) then
if type(v)=="string" then print(name.."['"..k.."'] = '"..v.."'") end
if type(v)=="number" then print(name.."['"..k.."'] = "..v) end
if type(v)=="boolean" then print(name.."['"..k.."'] = "..tostring(v)) end
if type(v)=="table" then LogVariables(v,depth+1,k); end
end
end
end
-- call with this command
LogVariables(_G,0,'');
"
working very well.
I upgrade domoticz to latest version (unstable) and now it's ok. Example like this:
"function LogVariables(x,depth,name)
for k,v in pairs(x) do
if (depth>0) or ((string.find(k,'device')~=nil) or (string.find(k,'variable')~=nil) or.
(string.sub(k,1,4)=='time') or (string.sub(k,1,8)=='security')) then
if type(v)=="string" then print(name.."['"..k.."'] = '"..v.."'") end
if type(v)=="number" then print(name.."['"..k.."'] = "..v) end
if type(v)=="boolean" then print(name.."['"..k.."'] = "..tostring(v)) end
if type(v)=="table" then LogVariables(v,depth+1,k); end
end
end
end
-- call with this command
LogVariables(_G,0,'');
"
working very well.

-
- Posts: 46
- Joined: Thursday 19 January 2017 16:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
I have another problem.
My some harware send variables to domoticz by special URL with parameters - every 2 second.
So, when i want to monitoring movement detector i have on every 2 sec the same status.
First of all I want to check actual status before i write new status. I can do this now - i can read otherdevices_svalue and can make a decision to use domoticz_updateDevice procedure.
But domoticz after some time show me a red alert - no read on my movement detector.
How can I change a date in otherdevices_lastupdate ?
I tried:
but it's not working.
My some harware send variables to domoticz by special URL with parameters - every 2 second.
So, when i want to monitoring movement detector i have on every 2 sec the same status.
First of all I want to check actual status before i write new status. I can do this now - i can read otherdevices_svalue and can make a decision to use domoticz_updateDevice procedure.
Code: Select all
tem = tonumber(alarm_ruch)
if (tem == 0 and otherdevices_svalues['Naruszenie strefy'] ~= 'Brak ruchu') then domoticz_updateDevice(9,1,'Brak ruchu') else end
if (tem == 1 and otherdevices_svalues['Naruszenie strefy'] ~= 'Wykryto Ruch!') then domoticz_updateDevice(9,4,'Wykryto Ruch!') else end
How can I change a date in otherdevices_lastupdate ?
I tried:
Code: Select all
local now_time = os.date("%Y-%m-%d %H:%M:%S");
otherdevices_lastupdate['Naruszenie strefy'] = now_time;
Re: global variables like otherdevices, otherdevices_lastupdate and otherdevices_svalues
@Bellison
I saw this LUA script with Json commands.
But how do I get a value (OFFSET) which I entered at a device (ADJUST/AANPASSEN and OFFSET)?
for example I entered an offset at device Watermeter (idx 403), offset is 1184308
How can I read out this value and put it in a value like 'watermeteroffset'? So I can use this value with: otherdevices/svalues['Watermeter'] to get the total amount.
Hope you understand my problem
best regards,
Hein
I saw this LUA script with Json commands.
But how do I get a value (OFFSET) which I entered at a device (ADJUST/AANPASSEN and OFFSET)?
for example I entered an offset at device Watermeter (idx 403), offset is 1184308
How can I read out this value and put it in a value like 'watermeteroffset'? So I can use this value with: otherdevices/svalues['Watermeter'] to get the total amount.
Hope you understand my problem
best regards,
Hein
RFXcom433e ver1009,Raspberry Pi,Domoticz v3.5877
KaKu:16c remote,dimmer,wall-sockets,sunscreenswitch
Promax:wall sockets Elro:wall sockets Somfy:RFY screens
TFA:weather station Chinese temperature sensors, smoke detectors, power switches
KaKu:16c remote,dimmer,wall-sockets,sunscreenswitch
Promax:wall sockets Elro:wall sockets Somfy:RFY screens
TFA:weather station Chinese temperature sensors, smoke detectors, power switches
Who is online
Users browsing this forum: No registered users and 1 guest