Page 1 of 4

Working: Gasmetersensor based on Kaku doorsensor (15 euros)

Posted: Wednesday 05 February 2014 14:09
by pwhooftman
Hi, i'd like to introduce my 15 euro gasmeter pulse solution.

I bought a Kaku AMST-606 magnetic door contact for 15 euro's.
Inside the switch, there is a small reed switch, a magnetich switch (the little glass tube with green ends).

Image

I desolderd the reed switch and attached 15cm thin but stiff copper wires to it (telephone cable), running through little drill holes in the casing (do not loose the metal part of the rotating time-out switch on the back of the AMST-606 during disassembly!)

Image

Next i positioned the reed valve in the special cavity in the gasmeter. Becvause the last reel of digits contains a magnet which passes by with every revolution, every 0,01m3 of gas used produces an on-off cycle of the swith.

Image
Image

Then i proceeded as follows:
- in the device list, note the Idx of the Kaku AMST-606 switch
- add it to the used devices and give the switch a name like 'gaspuls'
- add dummy hardware
- add a virtual sensor to the hardware of the type "counter", give it any name like 'gascounter'. Once created, edit the device and set it to the type 'counter'
- create a luascript script_device_gaspuls.lua in /scripts/lua, make sure it matches the name given to the switch.
- fill the script with the following code. Adjust the Idx, filepath and switchname to your specific situation

Code: Select all

--|55744.690


commandArray = {}

local thisfilename = "/volume1/@appstore/domoticz/domoticz/scripts/lua/script_device_gaspuls.lua"
local virtualcounter_idx = "44"
local switchName = "gascounter"

if devicechanged[switchName] == 'On' then

-- Open this file and read in the first line
   file = io.open(thisfilename, "rb")
   sContents = file:read("*l")
   file:close()

-- Parse and update the countvalue
   foo, snumber = sContents:match("([^,]+)|([^,]+)")
   local countvalue = snumber + 0.010
   local newline = foo .. "|" .. string.format("%.3f", tostring(countvalue))

-- Update virtual counter device
   ts = virtualcounter_idx .. "|0|" .. string.format("%.3f", tostring(countvalue))
   commandArray['UpdateDevice'] = ts

-- Write back new counter value
   local file = io.open(thisfilename, "r+")
   file:write(newline)
   file:close()

end

return commandArray
Notes:
- put the current reading of the gasmeter at the top of the lua script in the notation shown
- this value is read & written back to the lua script on every executiuon because of the bug mentioned in this thread http://www.domoticz.com/forum/viewtopic.php?f=15&t=1309

Every time the kaku switch is activated, the script is called and the value of the counter is increased by 0.010.

The result:

Image

The 'today' value is high because i entered this starting value in the script, making it seem all gas was consumed today
I'm curious how long the built in 3V lithium battery of the AMST-606 will last, it switches like 1000-2000 a day....

Update: fixed a small bug in the Lua script which crippled the value when going from .990 m3 to the next .000 counter

Tip: set the device type to 'gas' and the gasmeter setting to 1 to display daily usage correctly
Image

Re: Working: Gasmeterpuls for 15 euros, based on Kaku doorse

Posted: Wednesday 05 February 2014 16:50
by safi78
Very cool!

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Thursday 06 February 2014 20:17
by Derik
Really great !!!!

I have a other meter, only i like yor mod very much...

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 07 February 2014 12:16
by BigDog
damn sometimes things can be so easy :D

the only thing i was thinking about if you have more kaku sensors are switches if the door-sensor reports its thing other sensors and switches cant communicate with domoticz becose the door sensor is already sending and the doorsensor is sending very often i see....

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 07 February 2014 12:54
by pwhooftman
BigDog wrote:damn sometimes things can be so easy :D

the only thing i was thinking about if you have more kaku sensors are switches if the door-sensor reports its thing other sensors and switches cant communicate with domoticz becose the door sensor is already sending and the doorsensor is sending very often i see....
Thats right, Kaku sensor transmit 5-sec bursts of messages. But i don't use any other Kaku transmitters to be received by the RfxCom, and as long as the last gasmeter dial does not spin faster than 5 seconds i should be ok

I'm currently reading up on connecting a light-diode to a Gpio port of a TP-Link 1043ND router (those are cheap). Someone has created a little program on that router to count pulses delivered to the Gpio port, so maybe thats my next project :)

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 07 February 2014 18:10
by Derik
I'm currently reading up on connecting a light-diode to a Gpio port of a TP-Link 1043ND router (those are cheap). Someone has created a little program on that router to count pulses delivered to the Gpio port, so maybe thats my next project :)


How is this working??
And what are there for more options???

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 07 February 2014 20:41
by pwhooftman
Derik wrote:I'm currently reading up on connecting a light-diode to a Gpio port of a TP-Link 1043ND router (those are cheap). Someone has created a little program on that router to count pulses delivered to the Gpio port, so maybe thats my next project :)


How is this working??
And what are there for more options???
GPIO are General Purpose Input Output ports on the chip of the router, which can be used to control external devices like sensors & switches. The well known PiFace for Raspberry Pi is based on usages of these ports. See http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd for example.

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 08 August 2014 22:03
by dorustd
Hi

I am very interested.
At the moment I have Domoticz installed.
Domoticz v 1.1680
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 69
I have severeal klikaanklikuit (door) sensors installed

But.... I am I am very interested to create gassensor as yoy described.

So far successful but :
How do I change/add create a luascript script_device_gaspuls.lua in /scripts/lua ?
On the RaspBerry PI ?

Can you help me


Regards,
Theo
The Netherlands

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Tuesday 12 August 2014 13:43
by pwhooftman
Hi Theo,

I put the text of the luascript via notepad into a .lua file.
I copied the file to a public folder on my Synology, i guess you can use WinSCP to put in onto the Raspberry via FTP
Then move it to the right folder under domoticz (i think ./domoticz/scripts/lua)

BTW: the battery of the 'gassensor' lasts less than 2 months..., no wonder becaus eit's designed as a door contact :-)

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Tuesday 12 August 2014 14:06
by niclasf
My wireless pulse counter is Very low-power. It is also very versatile.

http://foogadgets.tictail.com/product/w ... se-counter

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Wednesday 13 August 2014 23:42
by dorustd
Thanks !

In meantime its working now with my AMST-606 contact.
I have installed the lua scirpt in the proper directory on my Rasberry PI. I have seen it is working

Only I have to do is to desolder the reed switch and attached 15cm thin but stiff copper wires to it (telephone cable).
I hope it will work after installation the device on my gasmeter.

Other question:
How do I reset Status 55775 to 0 ?

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 15 August 2014 21:47
by dorustd
Is does not work.

Maybe my gameter the last reel of digits does not contain a magnet :(

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Wednesday 17 September 2014 0:41
by markk
Hi

I'm desperate to get this working but am having a bit of trouble. I'm rumming Domoticz on windows and it appears I have the file path wrong and don't know how to fix it. I attach the script I'm using and the error message from the log and would be really grateful for any help please!

image.jpg
image.jpg (24.49 KiB) Viewed 25073 times

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Saturday 27 September 2014 11:02
by Palatinus
hello,
thanks for this great tutorial! I am not from the computer industry and it has worked for me right away.
I'm from Germany, so it was not possible for me not to get the sensor. I have instead taken a door sensor of intertechno. Inside it looks like and can be converted as well.
It now transmits high without problems from the basement to the living room.
Unfortunately, it does not transmit battery status. Are there any experiences how long the battery works?
Maybe I'm going there to solder a power supply to it.
Thanks again for the Great manual, I did not think that you can get as cheap a sensor for the gas meter.

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Saturday 27 September 2014 21:12
by pwhooftman
Hi, my battery lasted about 6 weeks, so i advice to connect a power supply to it.

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Friday 03 October 2014 23:37
by ThinkPad
Very clever idea! In technical aspect mabye not the best advisable idea (because of the battery draining quite fast, and the 433Mhz band being blocked every few seconds), but definately easily to create!

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Monday 10 November 2014 17:24
by Conn-artist
Hi, i'd like to introduce my 15 euro gasmeter pulse solution.
Thanks for the excellent instructions. I tried a similar construction with my gas meter, except I am using a reed switch from Flukso in stead of a KAKU, and the Raspberry Pi GPIO interrupts (and s ingle pull-up resistor). Saves batteries.

I encountered an issue which I would like to share, in case anyone else experiences it.

The script that is explained above records the gas meter reading in three decimals (e.g. 55744.690) but the actual data field in the Domoticz database is an integer. It won't accept a string with a decimal component. Maybe the data format changed between the time that OP wrote his post and the version that I use (2.2042).

So I modified one line in the script as follows, to store an integer value:
ts = virtualcounter_idx .. "|0|" .. string.format("%d", tostring(countvalue * 100))
And then in Domoticz, Setup / Application Settings, I return to the original value by entering 100 in the RFXMeter/Counter Dividers / Gas field.

HTH.

*Edit: formatting

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Monday 10 November 2014 21:01
by roblom
Conn-artist wrote: I tried a similar construction with my gas meter, except I am using a reed switch from Flukso in stead of a KAKU, and the Raspberry Pi GPIO interrupts (and s ingle pull-up resistor). Saves batteries.
Can you provide some more information about how you connect the reed switch to the PRi?

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Tuesday 11 November 2014 6:38
by Conn-artist
decrxgarage wrote:Can you provide some more information about how you connect the reed switch to the PRi?
I don't have my schematics software installed at the moment so I can't draw it, but it's trivial, really. The reed switch has two connections, see http://elinux.org/File:GPIOs.png for the RaspberryPi GPIO pinout.
  • one connection of the reed switch goes to GND
  • the other one goes to GPIO 23
  • a 10k pullup resistor is added and connected between GPIO 23 and 3V3.
Before starting Domoticz, run the following from the command line (requires GPIO librray from http://wiringpi.com):

gpio export 23 in
gpio edge 23 falling


And then the GPIO 23 will become available in Domoticz and it will switch whenever the reed switch closes.

Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur

Posted: Thursday 11 December 2014 10:27
by ThinkPad
The GPIO solution is very nice Conn-artist. I was already looking for something like that.

I am planning to read the pulse LED of my kWh-meter, and also the gasmeter with a reed-contact/IR-sensor which responds to the little mirror in the zero of the counting reel.

I have two modules: The great advantage of both modules is that they already have an analog to digital part (LM398 / LM393 or something). They both have a analog output which spits out raw values. But they also have a digital output. By adjusting the screw potentiometer, you can configure when the digital output has to be HIGH or LOW. There is also a small LED on the module that will turn on or off simultaneously to the digital output. I already managed to let the LED on the module blink at the same rate as the LED of my kWh-meter 8-) So that part is working.

I will try the scripts mentioned here soon, i think this is a great way to reading your meters in a cheap way!