Watermeter, script tuning ?..

Post Reply
Droll
Posts: 8
Joined: Monday 29 December 2014 0:50
Target OS: Linux
Domoticz version: 3.9202
Location: Norway
Contact:

Watermeter, script tuning ?..

Post by Droll » Wednesday 28 March 2018 13:57

Version: 3.9054
Build Hash: aa52bc9
Compile Date: 2018-03-25 13:47:29
dzVents Version: 2.4.1
Python Version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]

Need some advice on how to tune this script or other settings in Domoticz so I can get the data I want :)

Short on the setup ...
Watermeter with a pulse output ( 1 P pr 10 L )
Fibaro FGBS-001 Universal Binary Sensor, for the input ..
Fresh Ubuntu server install on a ASUS J1800I-C motherboard...
Been running Domoticz on a PI since 2015 before ...

Scrip below are basically the same as posted http://www.domoticz.com/forum/viewtopic ... oor#p22721, was simple enugh for me to understand :D ....

It does work, sort of, but I can't get the numbers I want, as you can see it says 1000L, and not ?? more like 100 or 250 ...
The 1,34m3 are probably correct...
As for the log ... nothing shows up :? just 0L
The divider inside setup are sett at 1 ... I have tried other settings, but then the m3 are way off ...

Probably just a simple typo somwhere, but are not good at scrips :|

Arne Kjetil

Code: Select all

--|1.340
commandArray = {}

local thisfilename = "/home/domoticz/domoticz/scripts/lua/script_device_Vann_forbruk.lua"
local virtualcounter_idx = "494"
local switchName = "Vann_forbruk"

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.01
   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
Image
Attachments
domo1.jpg
domo1.jpg (48.44 KiB) Viewed 429 times

Droll
Posts: 8
Joined: Monday 29 December 2014 0:50
Target OS: Linux
Domoticz version: 3.9202
Location: Norway
Contact:

Re: Watermeter, script tuning ?..

Post by Droll » Wednesday 28 March 2018 20:48

Got it working :)

Just made another costum dummy sensor, an incremental counter, just a counter...
Decided to go for liter, not m3.. made all the math a bit simpler ..


logg.png
logg.png (32.03 KiB) Viewed 402 times

Code: Select all

--|120.000
commandArray = {}

local thisfilename = "/home/domoticz/domoticz/scripts/lua/script_device_Vann_forbruk.lua"
local virtualcounter_idx = "499"
local switchName = "Vann_forbruk"

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 + 10
   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


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests