It collects the gas usage from the smartmeter and uploads it to the mindergas.nl database.
Code: Select all
--[[
/home/pi/domoticz/scripts/dzVents/scripts/upload_gas_usage_to_minderGas.lua
Author : Roblom
Description : This script collects the gas values from Domoticz (for example from the smart meter) and uploads the values to a MinderGas account.
For more information about MinderGas, see the API instructions on their website on https://mindergas.nl/member/api
]]--
---------------------------------------------------------------------------------------------------------------
local AUTH_TOKEN = 'xxxxxxxxxxxxxx' -- Fill in here your Mindergas authentication token
---------------------------------------------------------------------------------------------------------------
return {
active = true,
on = {
--timer = {'at 00:05'},
timer = {'every minute'},
httpResponses = {'UploadToMindergas'}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'Mindergas'
},
execute = function(domoticz, item)
if item.isTimer then
local GasUsageCounter = domoticz.devices('Gas (P1)').counter
local TodaysDate = tostring(domoticz.time.rawDate)
domoticz.log('The gas usage is ' .. GasUsageCounter, domoticz.LOG_INFO)
domoticz.log('The date is ' .. TodaysDate, domoticz.LOG_INFO )
domoticz.openURL({
url = 'https://www.mindergas.nl/api/gas_meter_readings',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['AUTH-TOKEN'] = AUTH_TOKEN
},
callback = 'UploadToMindergas',
postData = {
['date'] = TodaysDate,
['reading'] = GasUsageCounter
},
})
elseif (item.isHTTPResponse) then
if (item.statusCode == 201) then
domoticz.log('Gas usage data is sucessfully upoaded to Mindergas.nl.', domoticz.LOG_INFO)
else
if (item.statusCode == 401) then
domoticz.log('There was an authorisation problem with the Mindergas.nl database.', domoticz.LOG_ERROR)
end
if (item.statusCode == 422) then
domoticz.log('There was an unprocessable enrty while trying to upload the gas usage data to Mindergas.nl', domoticz.LOG_ERROR)
end
domoticz.notify('Domoticz error', 'An error occured while trying to upload the gas usage data to Mindergas.nl', PRIORITY_NORMAL)
end
end
end
}