Upload gas usage to mindergas.nl  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

markruys
Posts: 2
Joined: Friday 04 December 2020 20:52
Target OS: Linux
Domoticz version:
Contact:

Re: Upload gas usage to mindergas.nl

Post by markruys »

This script is more robust, uses user variables and doesn't upload to mindergas.nl at midnight to prevent overload:

Code: Select all

-- 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 like DzEvents!!
markruys
Posts: 2
Joined: Friday 04 December 2020 20:52
Target OS: Linux
Domoticz version:
Contact:

Re: Upload gas usage to mindergas.nl

Post by markruys »

Fixed a typo in the URL above, sorry about that.
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Upload gas usage to mindergas.nl

Post by dutchronnie »

Thanks markruys,

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.
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Upload gas usage to mindergas.nl

Post by dutchronnie »

Hello markruys,

I used the script you have posted, but i get the following error in Domoticz

2020-12-14 10:10:00.921 Error: dzVents: Error: (3.0.16) MinderGas: There is no uservariable with that name or id: gsMxrjmtFF3UxXz4DYre

Did i put the API on the wrong place?

Code: Select all

-- 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
}
MeAlbert
Posts: 65
Joined: Friday 06 December 2019 14:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: Upload gas usage to mindergas.nl

Post by MeAlbert »

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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by waaren »

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

Code: Select all

local gas_metering_device = domoticz.devices(mindergas_device.value)
certainly does not return any other value then a device object

btw. I have not seen a follow-up on the xml script I sent you via PM?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MeAlbert
Posts: 65
Joined: Friday 06 December 2019 14:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: Upload gas usage to mindergas.nl

Post by MeAlbert »

waaren
This is the script

Code: Select all

-- 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.
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Upload gas usage to mindergas.nl

Post by HvdW »

The alternative way on RPI is a script like:

Code: Select all

#!/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$
and in Cron 'crontab -e'

Code: Select all

# mindergas uploaden
3 0 1 * * /home/pi/scripts/mindergas-upload.sh
3 0 15 * * /home/pi/scripts/mindergas-upload.sh
Credits for the code to this site.
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by waaren »

MeAlbert wrote: Tuesday 05 January 2021 23:57 Other answers in PM.
I have not received a PM. Please check your sent folder. If it reached 150 you will have to clean it.

Can you also share the working @roblom script in which you added the heatpump usage?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MeAlbert
Posts: 65
Joined: Friday 06 December 2019 14:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: Upload gas usage to mindergas.nl

Post by MeAlbert »

waaren
new try on PM send just done.
The @problem script as you call it is the following.

Code: Select all

--[[
 /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
MeAlbert
Posts: 65
Joined: Friday 06 December 2019 14:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: Upload gas usage to mindergas.nl

Post by MeAlbert »

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.

Code: Select all

-- 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by waaren »

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?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MeAlbert
Posts: 65
Joined: Friday 06 December 2019 14:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

Re: Upload gas usage to mindergas.nl

Post by MeAlbert »

The url has to be changed to 'https://www.mindergas.nl/api/meter_readings'
In a few months the old one 'https://www.mindergas.nl/api/gas_meter_readings' will not work anymore.
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Upload gas usage to mindergas.nl

Post by HvdW »

Used the script, replaced MINDERGAS_AUTH_TOKEN and MINDERGAS_DEVICE_NAME then:

Code: Select all

MinderGas: There is no uservariable with that name or id: 1234mytoken5678 
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by waaren »

HvdW wrote: Saturday 09 January 2021 0:09 Used the script, replaced MINDERGAS_AUTH_TOKEN and MINDERGAS_DEVICE_NAME then:

Code: Select all

MinderGas: There is no uservariable with that name or id: 1234mytoken5678 
You should not enter your token and devicename but the domoticz user variablenames containing them.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Upload gas usage to mindergas.nl

Post by HvdW »

Never too old to learn. ;-)
Bugs bug me.
vandermark1977
Posts: 11
Joined: Sunday 11 December 2016 20:10
Target OS: -
Domoticz version:
Contact:

Re: Upload gas usage to mindergas.nl

Post by vandermark1977 »

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?

Can someone explain the logic of the new script?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by waaren »

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?

Can someone explain the logic of the new script?
That was just for test.

Change the lines from

Code: Select all

    on = {
        timer = {
           -- 'at 0:10' -- 5 minutes after midnight we take a sample of the gas metering device
           'every minute'
        },
to

Code: Select all

    on = {
        timer = {
           'at 0:03' -- 3 minutes after midnight we take a sample of the gas metering device
           -- 'every minute'
        },
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
mvveelen
Posts: 678
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by mvveelen »

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.
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
mvveelen
Posts: 678
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Upload gas usage to mindergas.nl

Post by mvveelen »

I use:

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 = '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.
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest