Gazpar counter via Zigbee switch button

Moderator: leecollings

Post Reply
oxygen
Posts: 9
Joined: Tuesday 02 October 2018 11:38
Target OS: -
Domoticz version:
Contact:

Gazpar counter via Zigbee switch button

Post by oxygen »

Hi all,

This is an workaround to connect easily/on the cheap the French Gazpar "smart" counter to domoticz using a Zigbee switch connected to the Gazpar output, based on the following setup.
I thought it was worth sharing as I couldn't find any example.

https://www.auto-domo.fr/home-assistant ... on-gazpar/

Overview:
The gazpar counter produces a dry contact for every 10L of gaz (1dm3) used.
This dry-contact/2pin output is connected to (any) Zigbee switch. A hit is then sent by the Zigbee switch every 10L.
This Zigbee switch is registered into domoticz (in my setup via a raspbee/deCONZ plugin)
And then parsed via a dzevents script into a virtual Gaz Counter into Domoticz.

In my setup, i'm using a IKEA/Somrig button.
https://www.ikea.com/fr/fr/p/somrig-lan ... -50560334/
https://github.com/dresden-elektronik/d ... utton.json
https://raw.githubusercontent.com/dresd ... _maps.json

Ikea/Somrig button in Domoticz has (up to) 10 different states.
Even states are for one of the two buttons.
Odd states are for the other one.
  • 10/20 is for a single short hit
  • 30/40 is for a double hit
  • 50/60 is for a long hit
(I couldn't find actions generating the values for 70/80/90/+)

In order to ensure all works, i've configured both in the dzevent script.

Simplified overview
Gazpar <--cable--> Ikea/Somrig Zigbee Switch {{<== Zigbee Radio Waves ==>} Raspbee/deCONZ <-- Ethernet --> Domoticz/zigbee plugin

Here is the dzevents script:

Code: Select all

-- ************************************************************ 
-- ** Manage Gazpar virtual Counter from Zigbee drycontact   **
-- ** Triggered every time the Zigbee devices receives a hit **
-- **
-- ** Gazpar counter: 1 hit per 10dm3/10L
-- **
-- ** Zigbee device: Two buttons
-- ** Zigbee device: Single hit : 10/20
-- ** Zigbee device: Dual hit (2 hits in less than 1 sec): 30/40
-- ** Zigbee device: Long hit (1-long hit in more than 1 sec): 50/60
        
return {
	on = {
		devices = {
			-- Zigbee device called by the Gazpar Smart counter
			'Raspbee-Gazpar',
			-- Test Fake device for simulation / test purpose
			'raspbee-gazpar-test',
			}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'Gazpar',
	},
	
	execute = function(domoticz, device)
	    --domoticz.log('trigger == > '..device.trigger)
	        
	    local current_gazpar = domoticz.devices("Gazpar-Zigbee").counter
	    local zigbee_hit = domoticz.devices("Raspbee-Gazpar").level
	    -- local zigbee_hit = domoticz.devices("raspbee-gazpar-test").level
		domoticz.log('Gazpar // Device ' .. device.name .. ' was hit with ' .. tonumber(zigbee_hit), domoticz.LOG_INFO)

	    if zigbee_hit == 10 or zigbee_hit == 20 then
    		-- Single hit = +10L
    		domoticz.log('Single hit', domoticz.LOG_INFO)
    		domoticz.devices("Gazpar-Zigbee").updateGas(current_gazpar * 1000 + 10)
    		domoticz.log('Gazpar // Upgrade m3 from ' .. tonumber(current_gazpar) .. ' to ' .. tonumber(domoticz.devices("Gazpar-Zigbee").counter), domoticz.LOG_INFO)
    	elseif zigbee_hit == 30 or zigbee_hit == 40 then
            -- Dual hit = two close hits = +20L
    		domoticz.log('Dual hit', domoticz.LOG_INFO)
    		domoticz.devices("Gazpar-Zigbee").updateGas(current_gazpar * 1000 + 20)
    		domoticz.log('Gazpar // Upgrade m3 from ' .. tonumber(current_gazpar) .. ' to ' .. tonumber(domoticz.devices("Gazpar-Zigbee").counter), domoticz.LOG_INFO)
    	elseif zigbee_hit == 50 or zigbee_hit == 60 then
            -- Long hit = probably an error, but +10L anyway
    		domoticz.log('Long hit', domoticz.LOG_INFO)
    		domoticz.devices("Gazpar-Zigbee").updateGas(current_gazpar * 1000 + 10)
    		domoticz.log('Gazpar // Upgrade m3 from ' .. tonumber(current_gazpar) .. ' to ' .. tonumber(domoticz.devices("Gazpar-Zigbee").counter), domoticz.LOG_INFO)
    	else
    		domoticz.log('Another type of hit // we do nothing', domoticz.LOG_INFO)
    	    -- Use this to "reset" the Counter values (usefull during resync/1st setup)
    	    -- domoticz.devices("Gazpar-Zigbee").updateGas(123456789)
    	end
    	
	end

}
dartflag
Posts: 7
Joined: Sunday 21 May 2017 12:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Gazpar counter via Zigbee switch button

Post by dartflag »

Hi Oxygene,
I saw your post and I'm trying to adapt your script.
Unfortunately I don't have the same with :(
My switch is always on
In domoticz, inclusion of the switch in Domoticz, I have 3 sensors
Capture d’écran 2025-07-20 à 09.35.59.png
Capture d’écran 2025-07-20 à 09.35.59.png (134.43 KiB) Viewed 609 times
do you possible to use this kind of switch with your script? I am not script expert :(


thanks for help

Fred
User avatar
waltervl
Posts: 5950
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Gazpar counter via Zigbee switch button

Post by waltervl »

You have to see a switch moment (Off to On or On to Off) to have this working.
I presume this type of action switches normally are Off so it seems strange that yours is always On. Did you connect the switch wires correctly?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
dartflag
Posts: 7
Joined: Sunday 21 May 2017 12:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Gazpar counter via Zigbee switch button

Post by dartflag »

hi
thanks for answer. found the solution :)

I adaptes the script like this and it works :)

Code: Select all

return {
    on = {
        devices = { 'TuyaZigbe_single' } -- Ton switch Zigbee Tuya
    },

    logging = {
        level = domoticz.LOG_INFO,
        marker = 'Gazpar',
    },



    execute = function(domoticz, device)
	
	  local compteurGaz = domoticz.devices("Gazpar-Zigbee")
	 
	  -- Valeur réelle affichée sur le compteur Gazpar (en m³)
	  		local valeur_initiale_m3 = 123.456
	  		local valeur_initiale_litres = valeur_initiale_m3 * 1000
	
	  -- Si compteur encore vierge (0), on l'initialise à la valeur réelle
			if compteurGaz.counter == 0 then
				domoticz.log('Initialisation du compteur virtuel Gazpar à ' .. valeur_initiale_m3 .. ' m³', domoticz.LOG_INFO)
				compteurGaz.updateGas(valeur_initiale_litres)
			end
	
       	 	if device.active then -- Switch a envoyé un statut "On"
          
            	local currentCounter = compteurGaz.counter -- en m3
            	local litres = currentCounter * 1000
            	local newLitres = litres + 10 -- Ajout de 10L
            	local newM3 = newLitres / 1000

            	domoticz.log('Appui sur switch détecté => +10L', domoticz.LOG_INFO)
            	domoticz.log('Ancien compteur : ' .. litres .. ' L (' .. currentCounter .. ' m³)', domoticz.LOG_INFO)
            	domoticz.log('Nouveau compteur : ' .. newLitres .. ' L (' .. newM3 .. ' m³)', domoticz.LOG_INFO)

            	-- Mise à jour compteur gaz
            		compteurGaz.updateGas(newLitres)
        	end
    end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest