Working: Gasmetersensor based on Kaku doorsensor (15 euros)

Moderator: leecollings

Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post 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.
pwhooftman
Posts: 75
Joined: Monday 11 November 2013 18:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Domoticz v 1.16xx
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 71
1X Synology Nas DS918+ DSM 7 (12Gb RAM mod)
Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post 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.
Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post by Kubra »

Checked the logfile and still teh same errormessages. So editing and saving the script with vi, didn't make any difference.
pwhooftman
Posts: 75
Joined: Monday 11 November 2013 18:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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?
Domoticz v 1.16xx
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 71
1X Synology Nas DS918+ DSM 7 (12Gb RAM mod)
Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post 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
Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post 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
User avatar
brunod
Posts: 9
Joined: Tuesday 14 April 2015 9:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Working: Gasmetersensor based on Kaku doorsensor (15 euros)

Post 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.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

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

Post 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).
I am not active on this forum anymore.
User avatar
brunod
Posts: 9
Joined: Tuesday 14 April 2015 9:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post by brunod »

Got the script working, Hurray!

rtfm brunod!
Panda
Posts: 11
Joined: Wednesday 26 August 2015 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Panda
Posts: 11
Joined: Wednesday 26 August 2015 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

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

Post 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?
pwhooftman
Posts: 75
Joined: Monday 11 November 2013 18:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Domoticz v 1.16xx
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 71
1X Synology Nas DS918+ DSM 7 (12Gb RAM mod)
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

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

Post by fransiefrans »

Nothing shows up in the domoticz log and the virtual counter is still 0.
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

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

Post 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?
Kubra
Posts: 22
Joined: Wednesday 01 April 2015 22:06
Target OS: NAS (Synology & others)
Domoticz version: latest
Location: Hollanda
Contact:

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

Post by Kubra »

Check your counter divider under Setup>Settings>Meters/Counters.
Is it 100 for gas?
puttemanp
Posts: 5
Joined: Thursday 15 October 2015 13:24
Target OS: NAS (Synology & others)
Domoticz version:
Location: Tremelo, Belgium
Contact:

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

Post 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.
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

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

Post 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
gawel31
Posts: 10
Joined: Friday 11 July 2014 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Working: Gasmetersensor based on Kaku doorsensor (15 euros)

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest