Witajcie,
Chciałbym skonstruować skrypyt obsługujący czujnik który bazuje na interfejsie RESTful API.
Adres wywołania to:
https://sanix.bitcomplex.pl/api/measurement/read.php?serial_no=ID&auth_token=TOKEN
Dane które otrzymuję podając adres wywołania:
{
"device_no": "SANIX-1810088",
"status": "1",
"time": "19.01.2021 17:04:07",
"ssid": "BIT-Complex-EXT",
"battery": "75",
"distance": "131",
"fill_perc": "38",
"service_date": "27.01.2021"
}
Nie jestem programistą, ale wydawało mi się że coś na wzór gotowego skryptu zadziała mi no ale domoticz nie wie o co mi chodzi 🙂
local fill_perc = 374 -- idx wirtualnego czujnika
return {
on = {
timer = {
'every minute' -- just an example to trigger the request
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'adres wywołania',
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local someValue = item.json.someValue -- just an example
-- update some device in Domoticz
domoticz.devices('fill_perc').updatePercentage(percentage)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
Jeśli ktoś byłby tak miły i się podzielił wiedzą albo dał jakąś wskazówkę będę zobowiązany

