I've got two problems with the dzvents data format .
I'm reading data from a website which returns the data in json format like this :
{
"8700": {
"name": "Aussentemperatur",
"value": "7.8",
"unit": "°C",
"desc": "",
"dataType": 0
}
}
I'm replacing the "8700" item with "Temp" in the script because I cannot access the field named completely numeric .
But how can I get the value of the field "value" into a variable to fill it into a virtual sensor ?
Currently there is always a nil value seen in the log.
Current script snippet as follows :
Code: Select all
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.252.226/JQ=8700',
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
local HeizungAussentemperaturString = domoticz.utils.toJSON(item.data)
HeizungAussentemperaturString = string.gsub(HeizungAussentemperaturString,"8700","Temp")
domoticz.log('-------------------------------------------------------------------------')
domoticz.log(HeizungAussentemperaturString,domoticz.LOG_INFO)
domoticz.log('-------------------------------------------------------------------------')
local HeizungAussentemperaturJSON = domoticz.utils.fromJSON(HeizungAussentemperaturString)
domoticz.log(HeizungAussentemperaturJSON,domoticz.LOG_INFO)
domoticz.log('------------------------------------')
local HeizungAussentemperatur = HeizungAussentemperaturJSON.Temp.value
domoticz.log(HeizungAussentemperatur,domoticz.LOG_INFO)
--domoticz.log('Aussentemperatur : ' .. HeizungAussentemperatur)
-- update some device in Domoticz
domoticz.devices('Heizung Aussentemperatur').updateTemperature(HeizungAussentemperatur)
end
Any help on getting the temperature value to the variable would be fine ...