attempt to concatenate a nil value
Publié : 24 nov. 2019, 21:27
bonjour
j ai fait un script Lua pour récupérer ma consomation de gaz sur un eco compteur Legrand
je récupère un fichier Json de type :
ma consomation de gaz est 25.421 m3
mon script :
mais j ai une erreur sur le log et mon device ( RFXMeter) non mis a jour :
je doit faire une erreur sur : commandArray[gazidx] = { ['UpdateDevice'] = gazidx ..'|0|'.. consoGaz }
Pourriez vous m aider ?
j ai fait un script Lua pour récupérer ma consomation de gaz sur un eco compteur Legrand
je récupère un fichier Json de type :
Code : Tout sélectionner
2019-11-24 21:19:00.407 "data2":141.000000,
2019-11-24 21:19:00.407 "data3":96.000000,
2019-11-24 21:19:00.407 "data4":0.000000,
2019-11-24 21:19:00.407 "data5":0.000000,
2019-11-24 21:19:00.407 "data6":0.000000,
2019-11-24 21:19:00.407 "data6m3":0.000000,
2019-11-24 21:19:00.407 "data7":25.421001,
2019-11-24 21:19:00.407 "data7m3":25.421001,
2019-11-24 21:19:00.407 "heure":21,
2019-11-24 21:19:00.407 "minute":18,
2019-11-24 21:19:00.407 "CIR1_Nrj":0.000000,
2019-11-24 21:19:00.407 "CIR1_Vol":0.000000,
2019-11-24 21:19:00.407 "CIR2_Nrj":0.000000,
2019-11-24 21:19:00.407 "CIR2_Vol":0.000000,
2019-11-24 21:19:00.407 "CIR3_Nrj":0.000000,
2019-11-24 21:19:00.407 "CIR3_Vol":0.000000,
2019-11-24 21:19:00.407 "CIR4_Nrj":0.000000,
2019-11-24 21:19:00.407 "CIR4_Vol":0.000000,
2019-11-24 21:19:00.407 "Date_Time":1574630339
2019-11-24 21:19:00.407 }
2019-11-24 21:19:00.407 Status: LUA: 25.421001,mon script :
Code : Tout sélectionner
local url = 'http://192.168.1.46/inst.json' -- url locale de votre écocompteur legrand
gazidx = otherdevices_idx ["Gaz"]
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
--recuperation des mesure sur data.json
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"data7"')
local consoGaz = removeZeros(string.sub(location,trouve+8,trouve +17))
if Debug == "YES" then
print(trouve)
print(location)
print(consoGaz)
end
commandArray[gazidx] = { ['UpdateDevice'] = gazidx ..'|0|'.. consoGaz }
return commandArrayCode : Tout sélectionner
2019-11-24 21:24:00.460 Error: EventSystem: in script_time_Gaz: [string "Debug = "YES" -- Turn debugging on ("YES") or..."]:44: attempt to concatenate a nil value (global 'gazidx')Pourriez vous m aider ?