Je tente de suivre ce tuto :
https://easydomoticz.com/lua-et-json/
Pour récupérer dans un script lua une valeur de JSON de mon capteur de station météo.
voici le script :
Code : Tout sélectionner
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
local config=assert(io.popen('/usr/bin/curl http://192.168.1.101:8080/json.htm?type=devices&rid=234'))
local blocjson = config:read('*all')
config:close()
--print (blocjson)
local jsonValeur = json:decode(blocjson)
nom = jsonValeur.result[1].Name
data = jsonValeur.result[1].Temp
print('**************** Alerte ************')
print(nom)
print(data)
commandArray = {}
print('****************')
return commandArrayCode : Tout sélectionner
{
"ActTime" : 1486666106,
"ServerTime" : "2017-02-09 13:48:26",
"Sunrise" : "07:01",
"Sunset" : "16:54",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"Barometer" : 1012,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "-22.8 C, 80 %, 1012 hPa",
"Description" : "",
"DewPoint" : "-25.31",
"Favorite" : 0,
"Forecast" : 2,
"ForecastStr" : "Partly Cloudy",
"HardwareID" : 31,
"HardwareName" : "Prevision meteo",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveTimeout" : false,
"Humidity" : 80,
"HumidityStatus" : "Wet",
"ID" : "1413A",
"LastUpdate" : "2017-02-09 13:15:03",
"Name" : "Prevision 6H",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "THB1 - BTHR918, BTHGN129",
"Temp" : -22.809999999999999,
"Timers" : "false",
"Type" : "Temp + Humidity + Baro",
"TypeImg" : "temperature",
"Unit" : 1,
"Used" : 1,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "234"
}
],
"status" : "OK",
"title" : "Devices"
}Code : Tout sélectionner
LUA: **************** Alerte ************
2017-02-09 14:50:00.864 LUA: Mode Cinéma
2017-02-09 14:50:00.864 LUA: ****************Une idée ?