If the value of the counter in less than 1, the .rain returns 0, the value on the device (sValue) is OKRain meter
rain: Number (please note that this does return the rain total for today)
rainRate: Number
If the value is greater then 1, event though we put value w 1 decimal, it could returns a value w a lot of decimals
The value shows in the GUI is less than the value in the device (sValue)
A script the test
Code: Select all
--[[
return
{
on =
{
devices =
{
"tippingbucketrain",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("Regenmeter") -- Your (virtual) rain device
local rainSwitch = dz.devices("tippingbucketrain") -- Your (triggered by bucket full) switch
local rainmm = 2 -- find out what 1 bucket full means in terms of mm
local rainTotal = 0
local timeSlice = math.min( (rainDevice.lastUpdate.secondsAgo / 3600), 10) -- at least 1 bucket in 10 hours
local rainAmountHour = dz.utils.round((rainmm / timeSlice),1)
if item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
]]--
local TEST = 205 -- a dummy switch for testing w/o waiting minutes / remove comment to use / comment to ignore
local dev_rain1 = 2593 -- dummy to receive rain in mm / Type Rain
local dev_rain2 = 2594 -- dummy to receive rain in mm / Type Rain
--local uv_rain = 38
local TIME_INTERVAL = 'every 15 minutes except at 00:00-00:55' -- the except to avoid the reset of the events (dzVents) and late go to 0 off the PWS
-- log options
local LOG_DEBUG = 2 -- 0 =>ERROR / 1 => FORCE / 2 => DEBUG
local LOG_LEVEL
local LOGGING
if LOG_DEBUG == 2 then
LOGGING = domoticz.LOG_DEBUG
LOG_LEVEL = domoticz.LOG_DEBUG
elseif LOG_DEBUG == 1 then
LOGGING = domoticz.LOG_FORCE
LOG_LEVEL = domoticz.LOG_FORCE
else
LOGGING = domoticz.LOG_ERROR
LOG_LEVEL = domoticz.LOG_INFO
end
return {
logging = {
level = LOGGING
},
on = {
devices = {TEST},
timer = {TIME_INTERVAL}
},
execute = function(dz, triggerObject)
_G.logMarker = dz.moduleLabel -- set logmarker to scriptname
local _u = dz.utils
-- /// Functions start \\\
local function logWrite(str,level) -- Support function for shorthand debug log statements
if level == nil then
level = LOG_LEVEL
end
dz.log(tostring(str),level)
end
local function jsonRainCounter(p_IDX, p_RAINRATE, p_RAINCOUNTER)
logWrite('IDX= ' .. p_IDX .. ' rate= ' .. p_RAINRATE .. ' rain= ' .. p_RAINCOUNTER)
local cmd = '/json.htm?type=command¶m=udevice&idx=' .. p_IDX .. '&nvalue=0&svalue=' .. p_RAINRATE .. ';' .. p_RAINCOUNTER
local url = 'http://127.0.0.1:8080' .. cmd
logWrite('url= ' .. url)
dz.openURL(url)
return
end
-- \\\ Functions end ///
local rainTot, rainRate
--if dz.variables(uv_rain).lastUpdate.isToday then
--rainTot = dz.variables(uv_rain).value
--logWrite('Same day: ' .. rainTot)
--else
--logWrite('New day', dz.LOG_FORCE)
--rainTot = 0
--end
rainTot = dz.devices(dev_rain1).rain
logWrite('rainTot initial: ' .. rainTot, dz.LOG_FORCE)
local rainVal = dz.devices(dev_rain1).sValue
logWrite('rainVal : ' .. rainVal, dz.LOG_FORCE)
local w_rainValTable = _u.stringSplit(rainVal,';')
rainTot = w_rainValTable[2]
logWrite('rainValTot : ' .. rainTot, dz.LOG_FORCE)
if dz.time.matchesRule('between 07:59 and 23:59') then
rainTot = _u.round(rainTot + 0.1, 1)
rainRate = 0.1 * 12
logWrite('rainTot increases: ' .. rainTot, dz.LOG_FORCE)
else
rainRate = 0
logWrite('rainTot unchanged: ' .. rainTot, dz.LOG_FORCE)
end
dz.devices(dev_rain1).updateRain(rainRate * 100, rainTot)
jsonRainCounter(dev_rain2, rainRate * 100, rainTot)
--dz.variables(uv_rain).set(rainTot)
logWrite ('***** FIN *****')
end
}part "rainTot initial:" + "rainVal:"
27/04/2022 09:45:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.5"
27/04/2022 09:45:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0.40000000596046 "
27/04/2022 09:40:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.4"
27/04/2022 09:40:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0.30000001192093 "
27/04/2022 09:35:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.3"
27/04/2022 09:35:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0.20000000298023 "
27/04/2022 09:34:39 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.2"
27/04/2022 09:34:39 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0.10000000149012 "
27/04/2022 09:34:02 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.1"
27/04/2022 09:34:02 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0 "
27/04/2022 09:33:14 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.1"
27/04/2022 09:33:14 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0 "
27/04/2022 09:30:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainVal : 120.0 0.1"
27/04/2022 09:30:00 Notice hestia local6 domoticz "dzVents: !Info: A_Rain: rainTot initial: 0 "
[/spoiler]
Last run
- Spoiler: show
should have been 1.9 instead of 1.8 For the rain: "Number (please note that this does return the rain total for today" I need to wait for tomorrow the see if it is today or not ; idem for sValue