Domoticz has a buildin report function for the amount of Rain that has fallen per day, week, month etc.
I want to use that data in a script to control the amount of water I drip into my garden.
Question 1. Someone who build that function already??
Question 2. Are those, reported, calculated amounts available for scripting?
Thanks for helping already..
Using calculated amount of rain parameters from Domoticz
Moderator: leecollings
-
- Posts: 17
- Joined: Wednesday 26 February 2020 17:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Using calculated amount of rain parameters from Domoticz
Not directly but you can use the API callsAfterburner wrote: ↑Thursday 27 May 2021 22:17 Are those, reported, calculated amounts available for scripting?
/json.htm?type=graph&sensor=rain&idx=23&range=day
/json.htm?type=graph&sensor=rain&idx=23&range=week
/json.htm?type=graph&sensor=rain&idx=23&range=month
/json.htm?type=graph&sensor=rain&idx=23&range=year
and process the results in your script.
You can use below dzVents script that I once created as an example / starting point.
Code: Select all
local scriptVar = 'water the plants'
return
{
on =
{
timer =
{
'at 09:09', -- change to the time you want to check the amount of rain in the set number of days
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script works as expected
marker = scriptVar,
},
execute = function(dz, item)
local minAmount = 2 -- in mm rain
local daysToEvaluate = 5 -- in days
local rainDevice = dz.devices('myRain') -- name enclosed in quotes or number without quotes
local waterPump = dz.devices('Beregening')
if item.isDevice or item.isTimer then
dz.openURL(
{
url = dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=rain&idx=' .. rainDevice.idx .. '&range=month',
callback = scriptVar,
})
return
end
local function getmm(rt)
local startDate = (dz.time.addMinutes(-1 * daysToEvaluate * 24 * 60)).rawDate
local mm = 0
dz.log('startDate: ' .. startDate, dz.LOG_DEBUG)
for index, record in ipairs(rt) do
if record.d > startDate then
mm = mm + record.mm
end
end
return mm
end
if item.ok and item.isJSON then
local mmRain = getmm(item.json.result, days )
if mmRain < minAmount then
waterPump.cancelQueuedCommands()
waterPump.switchOn()
waterPump.switchOff().afterSec(3600)
dz.log('Not enough rain in the last ' .. daysToEvaluate .. ' days (' .. mmRain .. ' mm). Switching waterpump on for 1 hour', dz.LOG_DEBUG)
else
dz.log('Enough rain in the last ' .. daysToEvaluate .. ' days (' .. mmRain .. 'mm). No need to turn on waterpump.', dz.LOG_DEBUG)
end
else
dz.log('No valid response from domoticz ',dz.LOG_ERROR)
dz.log(item,dz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 17
- Joined: Wednesday 26 February 2020 17:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Using calculated amount of rain parameters from Domoticz
Good startingpoint. Thanks.
Who is online
Users browsing this forum: No registered users and 1 guest