Page 3 of 4
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Thursday 02 April 2015 21:42
by Kubra
Okay, here's the script.
Code: Select all
--|6456.881
commandArray = {}
local thisfilename = "/volume1/@appstore/domoticz/scripts/lua/script_device_gaspuls.lua"
local virtualcounter_idx = "24"
local switchName = "gaspuls"
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("%d", tostring(countvalue * 100))
commandArray['UpdateDevice'] = ts
-- Write back new counter value
local file = io.open(thisfilename, "r+")
file:write(newline)
file:close()
end
return commandArray
I copied/pasted and adjusted to my personal situation. I have checked and double checked the script with the original. Very curious where it goes wrong.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Friday 03 April 2015 23:16
by pwhooftman
Have you opened the script with vi in a telnet/ssh session? Maybe the file was saved in windows format , which adds ^M caracters to the end of the lines which messes things up.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 04 April 2015 7:34
by Kubra
I opened end edited the script all the time with WinSCP. Should that make a difference?
I have now opened the script with vi and saved it.
I will monitor the log and see if the errors disappear.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 04 April 2015 12:31
by Kubra
Checked the logfile and still teh same errormessages. So editing and saving the script with vi, didn't make any difference.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 04 April 2015 13:38
by pwhooftman
Hi, still sounds like formatting of the script is the issue if even very simple lines like line 6 and 7 where variables are defined end in log errors.
If editing in vi, are you sure there are no ^M markers at the end of the lines?
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 04 April 2015 15:27
by Kubra
Retypt the script in vi.
Looks like the former errormessages are gone but now I get these errormessages:
Sat Apr 4 15:23:36 2015 Executing script: /volume1/@appstore/domoticz/scripts/lua/script_device_gaspuls.lua
Sat Apr 4 15:23:36 2015 Error: Error executing script command (/volume1/@appstore/domoticz/scripts/lua/script_device_gaspuls.lua). returned: 32256
Sat Apr 4 15:23:36 2015 Error: /usr/local/domoticz/scripts/lua/script_device_gaspuls.lua:28: attempt to index local 'file' (a nil value)
Sat Apr 4 15:23:36 2015 Script event triggered: /usr/local/domoticz/scripts/lua/script_device_gaspuls.lua
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 04 April 2015 15:52
by Kubra
Found out that teh previous error (returned: 32256) was a permission issue. Fixed that.
But now (I am back) with this error:
Sat Apr 4 15:46:37 2015 Script event triggered: /usr/local/domoticz/scripts/lua/script_device_gaspuls.lua
Sat Apr 4 15:46:37 2015 (RFXCOM) Lighting 2 (gaspuls)
Sat Apr 4 15:46:37 2015 Executing script: /volume1/@appstore/domoticz/scripts/lua/script_device_gaspuls.lua
Sat Apr 4 15:46:37 2015 Error: Error executing script command (/volume1/@appstore/domoticz/scripts/lua/script_device_gaspuls.lua). returned: 512
Working: Gasmetersensor based on Kaku doorsensor (15 euros)
Posted: Saturday 25 April 2015 23:08
by brunod
Does anyone know if LUA scripts are working on the Raspberry PI hardware?
I am trying to install the gasmetering counter according to the description at the beginning in this thread, but come no further than a gaspuls switch switching as normal but not trigger to start the according lua script.
The log file does not show a thing (errors or script calls) regarding the lua script, which it has to trigger. It only shows the gaspuls switch switching on and off.
local virtualcounter_idx = "69" is referring to the gaspuls switch and local switchName = "gasmeter" is referring to the dummy counter as in the description.
Lua script ( script_device_gaspuls.lua ) was saved with the utf-8 coding. Filezilla did the work to copy the script file to the lua folder (/home/pi/domoticz/scripts/lua/).
Code: Select all
--|15287.669
commandArray = {}
local thisfilename = "/home/pi/domoticz/scripts/lua/script_device_gaspuls.lua"
local virtualcounter_idx = "69"
local switchName = "gasmeter"
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
What do I forget or wrong?
Thanks in advance.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Sunday 26 April 2015 15:40
by ThinkPad
Is the switch (that is controlled by the sensor) named exactly 'gasmeter' ? If not, the script will never run (it will only run if device 'gasmeter' has changed).
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Sunday 26 April 2015 16:58
by brunod
Got the script working, Hurray!
rtfm brunod!
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 05 September 2015 17:21
by Panda
Hello,
Bought the kaku sensor today to use is as gasmeter following the steps in this guide, however I have some problems.
In the steps the op says the device should be visible in the device list, maybe some things in domoticz have changed since this guide was posted because I don't see the device in the list.
When learning a new switch it is reconized and I can add it, however there is some strange time delay, when connecting to a magnet it will trigger, when pulled a way and connected again to a magnet it won't. Then after some time it will give me a notification that the sensor is closed. The switch on the back is on the zero position.
Tried the type of switch to contact and on/off switch, does someone has an idea why it doesn't reconize the opening and closing?
Edit: Shows up in devices, but it still doesn't close directly if i hold a magnet to the reel
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Tuesday 08 September 2015 23:12
by Panda
So it seems that I had a problem with the kaku switch, got a few easy home sensors and gave it an other try.
So this time it works, however it gives me an pulse when XXXXXX,XX2 and XXXXXX,XX6 passes, so I guess that I need to modify the script to only count 1 pulse. Could someone help me to get this working I just started with Domoticz and don't know anything yet regarding LUA (I have some basic c# experience and know the if, else, do, this concept).
Edit: Nevermind Got it working.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Friday 02 October 2015 13:21
by fransiefrans
Im trying to get the gasmeter to count but I'm getting the following error:
pi@raspberrypi ~ $ sudo /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua
: not foundmoticz/scripts/lua/script_device_gaspuls.lua: 1: /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: 15287.669
/home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: 1: /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: --: not found
: not foundmoticz/scripts/lua/script_device_gaspuls.lua: 2: /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua:
/home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: 3: /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: commandArray: not found
: not foundmoticz/scripts/lua/script_device_gaspuls.lua: 4: /home/pi/domoticz/scripts/lua/script_device_gaspuls.lua:
/home/pi/domoticz/scripts/lua/script_device_gaspuls.lua: 5: local: not in a function
my script_device_gaspuls.lua:
local virtualcounter_idx = "72" = IDX virtual gasmeter
local switchName = "gaspuls" = KaKu amst 606
Code: Select all
--|15287.669
commandArray = {}
local thisfilename = "/home/pi/domoticz/scripts/lua/script_device_gaspuls.lua"
local virtualcounter_idx = "72"
local switchName = "gaspuls"
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
Has anyone a solution for me?
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Friday 02 October 2015 21:12
by pwhooftman
You can't run this script from the command prompt. It's run by Domoticz every time the switch 'gaspuls' receives an on/off from the kaku switch. You should see entries in the domoticz that the lua script is called.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 03 October 2015 21:22
by fransiefrans
Nothing shows up in the domoticz log and the virtual counter is still 0.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Monday 12 October 2015 12:43
by fransiefrans
I got it working now.
I changed the amst-606 from doorcontact to on/off switch.
My usage is shown in whole m3 (6.000m3) Is this normal?
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Saturday 07 November 2015 13:50
by Kubra
Check your counter divider under Setup>Settings>Meters/Counters.
Is it 100 for gas?
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Wednesday 11 November 2015 16:39
by puttemanp
Picking up on this thread.
I was wondering if the original mod of the KAKU door switch would also work with the Fibaro door and window sensor (
http://www.fibaro.com/en/the-fibaro-sys ... dow-sensor) It has a binary input connector where I was planning on installing the Flukso reed switch for water meter (
https://www.flukso.net/content/water-probe).
This because Domoticz does not yet support water and gas readings from pvoutput.
Any insight?
P.
Re: Working: Gasmetersensor based on Kaku doorsensor (15 eur
Posted: Friday 13 November 2015 23:07
by stlaha2007
Hi pwhooftman,
Nice setup for the gasmeter... With something simple as a door-sensor.
I was wondering, you placed your starting value in the first part of the script? At the end when changed/recalulated its written back into the file?
Why not read/write to a uservariable? Using it myself in bashscript only for Initial gasmeter reading and calculate counter from current minus initial.
I have looked into the script at
http://domoticz.com/wiki/Upload_energy_data_to_PVoutput which does simular with reading values of several devices in Domotics.
Grtz
Stephan
Sent from my D6503 using Tapatalk
Re: Working: Gasmetersensor based on Kaku doorsensor (15 euros)
Posted: Thursday 31 March 2016 11:51
by gawel31
hi! (Sorry for my English...i am french....)
i tried to do this. It counts and i can get global consumption, but consumption for one day is always zero. you can see that on this picture:
http://hpics.li/365e55c
What could i do?
I use this script:
Code: Select all
--|91.340000
commandArray = {}
local thisfilename = "/home/pi/domoticz/scripts/lua/script_device_gaz.lua"
local virtualcounter_idx = "81"
local switchName = "Contacteur Gaz"
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
Thanks a lot for your help!