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).
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!)
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.
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
- 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:
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