-- Script to upload gas metering readings to mindergas.nl. To use this script
-- you first need to define the following user variables:
--
-- MINDERGAS_DEVICE_NAME (gas metering device name like 'Gas')
-- MINDERGAS_AUTH_TOKEN (cf https://www.mindergas.nl/member/api)
return {
logging = {
level = domoticz.LOG_INFO,
marker = "MinderGas"
},
on = {
timer = {
'at 0:05' -- 5 minutes after midnight we take a sample of the gas metering device
},
httpResponses = {
'mindergas'
}
},
execute = function(domoticz, item)
if item.isTimer then
local mindergas_auth_token = domoticz.variables('MINDERGAS_AUTH_TOKEN')
if mindergas_auth_token == nil then
return
end
local mindergas_device = domoticz.variables('MINDERGAS_DEVICE_NAME')
if mindergas_device == nil then
return
end
local gas_metering_device = domoticz.devices(mindergas_device.value)
if gas_metering_device == nil or gas_metering_device.counter == nil then
domoticz.log("Unknown or wrong metering device '" .. mindergas_device.value .. "'", domoticz.LOG_ERROR)
return
end
local yesterday = os.date("%Y-%m-%d", os.time() - 24 * 60 * 60)
domoticz.log('MinderGas meter reading for ' .. yesterday .. ' is ' .. gas_metering_device.counter, domoticz.LOG_INFO)
domoticz.openURL({
url = 'https://www.mindergas.nl/api/gas_meter_readings',
method = 'POST',
headers = {
['AUTH-TOKEN'] = mindergas_auth_token.value,
['Content-Type'] = 'application/json'
},
postData = {
reading = gas_metering_device.counter,
date = yesterday
},
callback = 'mindergas'
}).withinHour(4) -- to prevent peak load on MinderGas infra, upload the sample a few hours later
elseif item.isHTTPResponse then
if item.ok then
domoticz.log('Uploaded meter reading to MinderGas', domoticz.LOG_INFO)
else
domoticz.log('Failed to upload meter reading to MinderGas (code ' .. item.statusCode .. ')', domoticz.LOG_ERROR)
end
end
end
}
Sorry, it take a while before i see your post.
I stil have the problem, but now i wil try your script. I hope that it is the solution.
I wil let it know.
-- Script to upload gas metering readings to mindergas.nl. To use this script
-- you first need to define the following user variables:
--
-- MINDERGAS_DEVICE_NAME (gas metering device name like 'Gas')
-- MINDERGAS_AUTH_TOKEN (cf https://www.mindergas.nl/member/api)
return {
logging = {
level = domoticz.LOG_INFO,
marker = "MinderGas"
},
on = {
timer = {
'at 10:10' -- 5 minutes after midnight we take a sample of the gas metering device
},
httpResponses = {
'mindergas'
}
},
execute = function(domoticz, item)
if item.isTimer then
local mindergas_auth_token = domoticz.variables('gsMxrjmtFF3UxXz4DYre')
if mindergas_auth_token == nil then
return
end
local mindergas_device = domoticz.variables('Gas')
if mindergas_device == nil then
return
end
local gas_metering_device = domoticz.devices(mindergas_device.value)
if gas_metering_device == nil or gas_metering_device.counter == nil then
domoticz.log("Unknown or wrong metering device '" .. mindergas_device.value .. "'", domoticz.LOG_ERROR)
return
end
local yesterday = os.date("%Y-%m-%d", os.time() - 24 * 60 * 60)
domoticz.log('MinderGas meter reading for ' .. yesterday .. ' is ' .. gas_metering_device.counter, domoticz.LOG_INFO)
domoticz.openURL({
url = 'https://www.mindergas.nl/api/gas_meter_readings',
method = 'POST',
headers = {
['AUTH-TOKEN'] = mindergas_auth_token.value,
['Content-Type'] = 'application/json'
},
postData = {
reading = gas_metering_device.counter,
date = yesterday
},
callback = 'mindergas'
}).withinHour(4) -- to prevent peak load on MinderGas infra, upload the sample a few hours later
elseif item.isHTTPResponse then
if item.ok then
domoticz.log('Uploaded meter reading to MinderGas', domoticz.LOG_INFO)
else
domoticz.log('Failed to upload meter reading to MinderGas (code ' .. item.statusCode .. ')', domoticz.LOG_ERROR)
end
end
end
}
waaren
MinderGas made it also possible to upload the power usage from a heat pump.
A gas meter has a counter and that counter is used in the script. But a kWh device has only counterToday so I have to use WhTotal /1000 to get the right value in mindergas. In the original script from Roblom I managed it and it works. But in your script you use .value at some places and I don't know if your script works when I only change .counter in .WhTotal?
If so can you explain how I can be sure that this line: local gas_metering_device = domoticz.devices(mindergas_device.value) gives the WhTotal value?
MeAlbert wrote: ↑Tuesday 05 January 2021 21:35
waaren
MinderGas made it also possible to upload the power usage from a heat pump.
A gas meter has a counter and that counter is used in the script. But a kWh device has only counterToday
Not sure if I understand you correctly but the available attributes for a kWh device in dzVents are:
actualWatt: Number. Actual usage in Watt.
counterToday: Number.
usage: Number.
WhToday: Number. Total Wh usage of the day. Note the unit is Wh and not kWh!
WhTotal: Number. Total Wh usage.
so I have to use WhTotal /1000 to get the right value in mindergas. In the original script from Roblom I managed it and it works. But in your script you use .value at some places and I don't know if your script works when I only change .counter in .WhTotal?
If so can you explain how I can be sure that this line: local gas_metering_device = domoticz.devices(mindergas_device.value) gives the WhTotal value?
I would have to see the script because I don't remember that I shared one on the forum but the line
-- Script to upload gas metering readings to mindergas.nl. To use this script
-- you first need to define the following user variables:
--
-- MINDERGAS_DEVICE_NAME (gas metering device name like 'Gas')
-- MINDERGAS_AUTH_TOKEN (cf https://www.mindergas.nl/member/api)
return {
logging = {
level = domoticz.LOG_INFO,
marker = "MinderGas"
},
on = {
timer = {
'at 0:05' -- 5 minutes after midnight we take a sample of the gas metering device
},
httpResponses = {
'mindergas'
}
},
execute = function(domoticz, item)
if item.isTimer then
local mindergas_auth_token = domoticz.variables('MINDERGAS_AUTH_TOKEN')
if mindergas_auth_token == nil then
return
end
local mindergas_device = domoticz.variables('MINDERGAS_DEVICE_NAME')
if mindergas_device == nil then
return
end
local gas_metering_device = domoticz.devices(mindergas_device.value)
if gas_metering_device == nil or gas_metering_device.counter == nil then
domoticz.log("Unknown or wrong metering device '" .. mindergas_device.value .. "'", domoticz.LOG_ERROR)
return
end
local yesterday = os.date("%Y-%m-%d", os.time() - 24 * 60 * 60)
domoticz.log('MinderGas meter reading for ' .. yesterday .. ' is ' .. gas_metering_device.counter, domoticz.LOG_INFO)
domoticz.openURL({
url = 'https://www.mindergas.nl/api/gas_meter_readings',
method = 'POST',
headers = {
['AUTH-TOKEN'] = mindergas_auth_token.value,
['Content-Type'] = 'application/json'
},
postData = {
reading = gas_metering_device.counter,
date = yesterday
},
callback = 'mindergas'
}).withinHour(4) -- to prevent peak load on MinderGas infra, upload the sample a few hours later
elseif item.isHTTPResponse then
if item.ok then
domoticz.log('Uploaded meter reading to MinderGas', domoticz.LOG_INFO)
else
domoticz.log('Failed to upload meter reading to MinderGas (code ' .. item.statusCode .. ')', domoticz.LOG_ERROR)
end
end
end
}
I thought is was yours but it is from markruys. Sorry for the confusion.
Other answers in PM.
#!/bin/bash
#Token to authenticate with mindergas.nl
TOKEN=<your token>
#fetch meterstand (use jq to parse JSON object correctly)
# rid is the Idx number for the Gas reading in Setup->Devices in Domoticz
METERSTAND=`curl -s "http://127.0.0.1:8080/json.htm?type=devices&rid=<Idx number>" | jq '.result[0].Counter'| tr $
#Get OS date, and format it corectly.
NOW=$(date +"%Y-%m-%d")
#Build JSON by hand 😉
JSON='{ "date":"'$NOW'", "reading":"'$METERSTAND'" }'
#post using curl to API
curl -v -H "Content-Type:application/json" -H "AUTH-TOKEN:$TOKEN" -d "$JSON" https://www.mindergas.nl/a$
--[[
/home/pi/javascript:void(0)domoticz/scripts/dzVents/scripts/upload_gas_usage_to_minderGas.lua
Author : Roblom
Adapted to heatpunp : MeAlbert
Description : This script collects the kWh 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 = 'xxxxxxxxxxxxxxxxxxx'' -- Fill in here your Mindergas authentication token
---------------------------------------------------------------------------------------------------------------
return {
active = true,
on = {
timer = {'at 00:05'},
httpResponses = {'UploadToMindergas'}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'Mindergas'
},
execute = function(domoticz, item)
if item.isTimer then
local kWhUsageCounter = domoticz.devices(3).WhTotal/1000
local TodaysDate = tostring(domoticz.time.rawDate)
domoticz.log('The kWh usage is ' .. kWhUsageCounter, 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'] = kWhUsageCounter
},
})
elseif (item.isHTTPResponse) then
if item.ok then -- self.statusCode >= 200 and self.statusCode <= 299
domoticz.log('kWh 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
}
It worked ok but I like the other one with the delay and user variables
Also adapted the other script. Understand the code and how to work with user variables.
Tested it and works fine only have to wait one hour before it appears in MinderGas.
-- Script to upload kWh metering readings to mindergas.nl. To use this script
-- you first need to define the following user variables in - setup - more options - User variables :
-- origianaly developed by : Roblom
-- optimized by : markruys
-- adapted to heatpump by : MeAlbert
-- MINDERGAS_DEVICE_NAME (Power metering device name like 'WP verbruik')
-- MINDERGAS_AUTH_TOKEN (cf https://www.mindergas.nl/member/api)
------ no changes needed below this point ----=
return {
logging = {
level = domoticz.LOG_INFO,
marker = "MinderGas"
},
on = {
timer = {
-- 'at 0:10' -- 5 minutes after midnight we take a sample of the gas metering device
'every minute'
},
httpResponses = {
'mindergas'
}
},
execute = function(domoticz, item)
if item.isTimer then
local mindergas_auth_token = domoticz.variables('MINDERGAS_AUTH_TOKEN')
if mindergas_auth_token == nil then
return
end
local mindergas_device = domoticz.variables('MINDERGAS_DEVICE_NAME')
if mindergas_device == nil then
return
end
local kWh_metering_device = domoticz.devices(mindergas_device.value)
if kWh_metering_device == nil or kWh_metering_device.WhTotal == nil then
domoticz.log("Unknown or wrong metering device '" .. mindergas_device.value .. "'", domoticz.LOG_ERROR)
return
end
local yesterday = os.date("%Y-%m-%d", os.time() - 24 * 60 * 60)
domoticz.log('MinderGas meter reading for ' .. yesterday .. ' is ' .. kWh_metering_device.WhTotal/1000, domoticz.LOG_INFO)
domoticz.openURL({
url = 'https://www.mindergas.nl/api/gas_meter_readings',
method = 'POST',
headers = {
['AUTH-TOKEN'] = mindergas_auth_token.value,
['Content-Type'] = 'application/json'
},
postData = {
reading = kWh_metering_device.WhTotal/1000,
date = yesterday
},
callback = 'mindergas'
}).withinHour(1) -- to prevent peak load on MinderGas infra, upload the sample the # of hours later filed in at .withinHour(#)
elseif item.isHTTPResponse then
if item.ok then
domoticz.log('Uploaded meter reading to MinderGas', domoticz.LOG_INFO)
else
domoticz.log('Failed to upload meter reading to MinderGas (code ' .. item.statusCode .. ')', domoticz.LOG_ERROR)
end
end
end
}
MeAlbert wrote: ↑Wednesday 06 January 2021 12:49
Also adapted the other script. Understand the code and how to work with user variables.
Tested it and works fine only have to wait one hour before it appears in MinderGas.
Great !
Do you also still have the same script for Gas? If so could the two be combined?
Great that the script is updated for kWh & heatpumps!
I don't understand the new script though... I see something happening every minute now? Why is that the case when all i want is to upload kWh total from the heautpump device?
vandermark1977 wrote: ↑Wednesday 13 January 2021 22:35
Great that the script is updated for kWh & heatpumps!
I don't understand the new script though... I see something happening every minute now? Why is that the case when all i want is to upload kWh total from the heautpump device?
I still haven't been able to upload the values to Mindergas.nl from my Synology.
I only have the gas values and the name of the device is .... tadaaa .... Gas.
The API nr. I have, but what script should I use: dzVents - timer? Wat should be the code exactly, because I'm not sure where to put the different details.
--[[
/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 = 'my_mindergas_API' -- Fill in here your Mindergas authentication token
---------------------------------------------------------------------------------------------------------------
return {
active = true,
on = {
timer = {'at 12:26'},
httpResponses = {'UploadToMindergas'}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Mindergas"
},
execute = function(domoticz, item)
if item.isTimer then
local GasUsageCounter = domoticz.devices('Gas').counter
--local GasUsageCounter = domoticz.devices('Gas').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 entry 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
}
but whatever I try, I keep getting the error message:
Error: EventSystem: in Mindergas: [string "--[[..."]:22: attempt to index a nil value (global 'domoticz')
Error on line 22? That is the logging-part and that seems to be OK. Is it the "Gas"-reading? Been at this for days now and I can't figure it out.