Using total rain for today in an action:
For this we are going to use dzVents, it is in the same editor as Blockly, but then choose dzVents
We are going to (Always!!) start simple, then build the final script, so lets start with printing the values:
Code: Select all
return {
on = {
devices = {
'DumRain'
}
},
execute = function(domoticz, device)
--[[
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
domoticz.log('rain_rate: ' .. device.rainRate, domoticz.LOG_INFO)
domoticz.log('total_rain: ' .. device.rain, domoticz.LOG_INFO)
]]--
end
}
When we now execute the json query:
Code: Select all
http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=1103&nvalue=0&svalue=510;1081
it will output in the log:
2018-06-05 07:48:07.545 Status: dzVents: Info: Handling events for: "DumRain", value: "511;1081"
2018-06-05 07:48:07.545 Status: dzVents: Info: ------ Start internal script: TestTotalRain: Device: "DumRain (Dummy)", Index: 1103
2018-06-05 07:48:07.546 Status: dzVents: Info: Device DumRain was changed
2018-06-05 07:48:07.547 Status: dzVents: Info: rain_rate: 5.1100001335144
2018-06-05 07:48:07.547 Status: dzVents: Info: total_rain: 81
2018-06-05 07:48:07.547 Status: dzVents: Info: ------ Finished TestTotalRain
Perfect! all the values we need... now lets switch on a light when there is to much rainfall today (>80mm)
For this i added a dummy switch called 'MyDummySwitch'
Here is the new script:
Code: Select all
return {
on = {
devices = {
'DumRain'
}
},
execute = function(domoticz, device)
local my_light = domoticz.devices('MyDummySwitch')
if (device.rain>80) then
domoticz.log('more then 80mm of rain today!!', domoticz.LOG_INFO)
my_light.switchOn()
else
my_light.switchOff()
end
end
}
Now of course, on every rain change the light will be switched on/off, and probably you would not want this, so there are several options to prevent this, so lets do a simple one:
Code: Select all
return {
on = {
devices = {
'DumRain'
}
},
execute = function(domoticz, device)
local my_light = domoticz.devices('MyDummySwitch')
local bTurnOn = false
if (device.rain>80) then
domoticz.log('more then 80mm of rain today!!', domoticz.LOG_INFO)
bTurnOn = true;
end
if (my_light.bState ~= bTurnOn) then
if (bTurnOn == true) then
domoticz.log('switching light ON', domoticz.LOG_INFO)
my_light.switchOn()
else
domoticz.log('switching light OFF', domoticz.LOG_INFO)
my_light.switchOff()
end
end
end
}
In the installation folder of domoticz there is a folder 'dzVents' with documentation, and also a scripts/dzVents/examples