I am using the script, added some features, all works fine accept for one thing:
return (device.direction >= 60 or device.direction <= 247) and (device.gust >= 13.9) -
. That works fine with the 'or' function:
if add e.g. the device.gust,
return (device.direction >= 60 or device.direction <= 247 and device.gust >= 10.8) it does not work.
return (device.direction >= 60 or device.direction <= 247 or device.gust >= 10.8), is a accepted so "return" only accept 1 value. In this case >=60 or <=247 or >=10.8.
I did a lot of experiments in the script but i can not get it to work the way i want (winddirection
Code: Select all
-- werkt samen met script LuxTemp (gemiddelde lux meting)
-- Define all the sensors which needs to be considered for the sunscreen to close
local sensors = {
temperature = {
active = true,
device = 'Temp/hum ms',
closeRule = function(device)
return device.temperature <= 10 --15
end
},
WindSnelheid_Ri = {
active = false,
device = 'Wind BR',
closeRule = function(device)
return (device.direction >= 60 or device.direction <= 247 and device.speed >= 10.8) -- =Bft 6. in m/s. 5 bft= 8..10.7m/s. 6bft= 10.8..13.8 m/s
end
},
Windvlaag_Ri = {
active = true,
device = 'Wind BR',
closeRule = function(device)
return (device.direction >= 60 or device.direction <= 247) and (device.gust >= 13.9) -
end
},
rain = {
active = true,
device = 'Rain BR',
closeRule = function(device)
return device.rainRate > 0
end
},
rainExpected = {
active = true,
device = 'Possible Rain BR', -- This needs to be a virtual sensor of type 'percentage'
closeRule = function(device)
return device.state == 'On'
--[[ return device.percentage > 15 --]]
end
},
--[[
uv = {
active = true,
device = 'Ultraviolet',
closeRule = function(device)
return device.uv <= 3
end
},
lux = {
active = true,
device = 'Illuminance',
closeRule = function(device)
return device.lux <= 2000
end
}
--]]
lux = {
active = true,
device = 'Lux dummy gem 30min', -- device is gedefinieerd in script 'LuxTemp average'
closeRule = function(device)
-- local startmoment = device.lux -- toegevoegd
--print('=== startmoment average 30min:'..startmoment)
return device.lux <= 300 --3000 -- Lux_30min_switch staat op 3100Lux
end
}
}
-- Define the name of your sunscreen device
local sunscreenDevice = 'sunscreenblinds'
-- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
local dryRun = false
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script
-- Set to false to disable this feature
local manualOverrideSwitch = 'manualOverrideBlinds'
--local manualOverrideSwitch = true --false
-- Minutes to wait after a sunscreen close before opening it again.
local timeBetweenOpens = 0 --10
return {
active = true,
on = {
timer = {'every minute'}
},
logging = {
-- uncomment level en marker om debugging aan te zetten
--level = domoticz.LOG_DEBUG,
--marker = 'Sunscreenmarker='
},
execute = function(domoticz)
local function switchOn(sunscreen, message)
if (sunscreen.state == 'Open') then
if (not dryRun) then
sunscreen.switchOn()
domoticz.notify('Sunscreen= 1', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
local function switchOff(sunscreen, message)
if (sunscreen.state == 'Closed') then
if (not dryRun) then
sunscreen.switchOff()
domoticz.notify('Sunscreen= 2', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
-- Locals voor Alarm tekstmeldingen-------------------------------------------------------------------------------
domoticz.log ("=Graden=Gusts=Speed=======================================", domoticz.LOG_DEBUG)
--local graden = domoticz.devices('Wind BR').direction
local graden = 180
domoticz.log ('=Graden===================' ..graden, domoticz.LOG_DEBUG)
local richting = domoticz.devices('Wind BR').directionString
domoticz.log('=windrichting=========' ..richting, domoticz.LOG_DEBUG)
--local Wvlaag = domoticz.devices('Wind BR').gust
local Wvlaag = 14
domoticz.log ("=Windvlaag================" ..Wvlaag, domoticz.LOG_DEBUG)
--local Wsnelh = domoticz.devices('Wind BR').speed
local Wsnelh = 8
domoticz.log ("=Windsnelheid============" ..Wsnelh, domoticz.LOG_DEBUG)
local Ws_niet_afgerond = Wsnelh --domoticz.devices('Wind BR').speed
local Ws_afgerond = math.floor((Ws_niet_afgerond) * 10)/10 --math.floor((Ws_niet_afgerond + 0.05) * 10)/10
domoticz.log ("=Windsnelheid===afgerond=========" ..Ws_afgerond, domoticz.LOG_DEBUG)
domoticz.log ('=Graden===' ..graden .. ' , Windvlaag: '..Wvlaag .. ', Windsnelheid : ' ..Ws_afgerond, domoticz.LOG_DEBUG)
local Regen = ''
if domoticz.devices('Is it Raining').state == 'On' then
Regen = 'Het regent in Bergen'
else
Regen = 'Geen regen in Bergen'
domoticz.log ('=Regen: ' ..Regen, domoticz.LOG_DEBUG)
end
local lum1 = domoticz.devices('Lux dummy gem 30min').lux
domoticz.log(' lumen======:' ..lum1, domoticz.LOG_DEBUG)
-- uitschakelen van de manualOverrideSwitch bij sunrise nadat isNightTime is afgelopen
local T1 = (domoticz.time.secondsSinceMidnight/60)
local T2 = (domoticz.time.sunriseInMinutes)
domoticz.log ("minuten na middernacht=================" ..T1, domoticz.LOG_DEBUG)
domoticz.log ("Sunrise in minuten na middernacht=======" ..T2, domoticz.LOG_DEBUG)
if T2 == T1 then
domoticz.devices(manualOverrideSwitch).switchOff()
end
-- ------------------------------------------------------------------------------------
if (domoticz.devices(manualOverrideSwitch).state == 'On') then --manualOverrideSwitch and
domoticz.log('Automatic sunscreen script is manually disabled', domoticz.LOG_DEBUG)
return
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- Sunscreen must always be up during nighttime
if (domoticz.time.isNightTime) then
switchOff(sunscreen, 'Closing sunscreen, It is night')
local txt = ('ManualOverrideSwitch = On.<br> Screens up.<br>Nighttime')
domoticz.devices('Alarm Wind').updateAlertSensor(1,txt)
domoticz.devices(manualOverrideSwitch).switchOn()
domoticz.devices('Lux_30min_switch').switchOn()
return
end
-- -----omrekening windsnelheid m/s naar beaufort en knopen-----------------------------------------------------
local Bft = 0
local Kn = 0
--domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
if Ws_afgerond >= 24.5 and Ws_afgerond <= 28.4 then Bft = 10 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 20.8 and Ws_afgerond <= 24.4 then Bft = 9 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 17.2 and Ws_afgerond <= 20.7 then Bft = 8 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 13.9 and Ws_afgerond <= 17.1 then Bft = 7 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 10.8 and Ws_afgerond <= 13.8 then Bft = 6 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 8.0 and Ws_afgerond <= 10.7 then Bft = 5 Kn = math.floor((Ws_afgerond * 1.944) * 10/10) --5 Kn = (Ws_afgerond * 1.944)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 5.5 and Ws_afgerond <= 7.9 then Bft = 4 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 3.4 and Ws_afgerond <= 5.4 then Bft = 3 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 1.6 and Ws_afgerond <= 3.3 then Bft = 2 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
if Ws_afgerond >= 0.3 and Ws_afgerond <= 1.5 then Bft = 1 Kn = math.floor((Ws_afgerond * 1.944) * 10/10)
domoticz.log ('=Beaufort========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen========== :' ..Kn, domoticz.LOG_DEBUG)
end
-- -------omrekening windvlagen m/s naar beaufort en knopen--------------------------------
local Bftvl = 0
local Kn_vl = 0
--domoticz.log ('=Beaufort windvlaag========== :' ..Bftvl, domoticz.LOG_DEBUG)
if Wvlaag >= 24.5 and Wvlaag <= 28.4 then Bftvl = 10 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag========== :' ..Bft, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 20.8 and Wvlaag <= 24.4 then Bftvl = 9 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 17.2 and Wvlaag <= 20.7 then Bftvl = 8 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 13.9 and Wvlaag <= 17.1 then Bftvl = 7 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 10.8 and Wvlaag <= 13.8 then Bftvl = 6 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 8.0 and Wvlaag <= 10.7 then Bftvl = 5 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 5.5 and Wvlaag <= 7.9 then Bftvl = 4 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('==Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 3.4 and Wvlaag <= 5.4 then Bftvl = 3 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('==Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 1.6 and Wvlaag <= 3.3 then Bftvl = 2 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('==Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
if Wvlaag >= 0.3 and Wvlaag <= 1.5 then Bftvl = 1 Kn_vl = math.floor((Wvlaag * 1.944) * 10/10)
domoticz.log ('=Beaufort windvlaag==========' ..Bftvl, domoticz.LOG_DEBUG)
domoticz.log ('=Knopen windvlaag========== :' ..Kn_vl, domoticz.LOG_DEBUG)
end
-- ---Wind Alarm sensor--text feed-----------------------------------------------------
-- oorspronkelijke txt string. Vond ik lang en onoverzichtelijk. aangepast hieronder
if (graden >= 60 and graden <= 247) and (Ws_afgerond <= 10.7 or Wvlaag <= 13.9) then
local txt = ('<FONT COLOR=red><u>1 Windrichting waarschuwing.</u></FONT><br><br><br><br><br><FONT COLOR=grey>Wrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'</FONT><br>Wsnelheid niet >10.7m/s: ' ..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft:' ..Bft.. '<br> Wvlaag niet >13.9m/s:.....'..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl:' ..Bftvl.. '<br>' ..Regen)
domoticz.devices('Alarm Wind').updateAlertSensor(0,txt) -- 0= grey, 2= yellow
else
--local txt = ('<FONT COLOR=blue>Geen wind waarschuwing voor sunblinds.</FONT><br><br> Wrichting (>60..<247): ' ..graden.. 'gr. ' .. richting..'<br> Wsnelheid >10.7: ' ..Ws_afgerond .. 'm/s. Kn: '..Kn..'. Bft :' ..Bft.. '<br> Wvlaag >13.9: '..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl:' ..Bftvl..'<br>' ..Regen)
local txt1 = ('<FONT COLOR=blue>Geen wind waarschuwing voor sunblinds.</FONT><br><br><br><br><br>')
local txt2 = ('<FONT COLOR=green>Wrichting (>60..<247): ' ..graden.. 'gr. ' .. richting..'<br></FONT>')
local txt3 = ('Wsnelheid >10.7: ' ..Ws_afgerond .. 'm/s. Kn: '..Kn..'. Bft :' ..Bft.. '<br>')
local txt4 = ('Wvlaag >13.9: '..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl:' ..Bftvl.. '<br>')
local txt5 = (''..Regen)
domoticz.devices('Alarm Wind').updateAlertSensor(1,txt1 ..txt2 ..txt3 ..txt4 ..txt5) -- 1= green
end
if (graden >= 60 and graden <= 247) and (Ws_afgerond >= 10.7) then
--local txt = ('<FONT COLOR=red> <u>2 WAARSCHUWING windrichting en snelheid.</u> <br><br>Wrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'<br>Wsnelheid >10.7m/s: ' ..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft :' ..Bft..'.<br><FONT COLOR=black> Wvlaag < 13.9:.....'..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl :' ..Bftvl.. '</FONT><br>' ..Regen)
local txt1 = ('<FONT COLOR=red> <u>2 WAARSCHUWING windrichting en snelheid.</u>')
local txt2 = ('<br><br><br><br><br>Wrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'<br>')
local txt3 = ('Wsnelheid >10.7m/s: ' ..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft :' ..Bft..'.<br>')
local txt4 = ('<FONT COLOR=black> Wvlaag < 13.9:.....'..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl :' ..Bftvl.. '</FONT>')
local txt5 = ('<br>' ..Regen)
domoticz.devices('Alarm Wind').updateAlertSensor(4,txt1 ..txt2 ..txt3 ..txt4 ..txt5) --4-red
end
if (graden >= 60 and graden <= 247) and (Wvlaag >= 13.9) then
--local txt = ('<FONT COLOR=red> <u>3 WAARSCHUWING Windrichting en -vlaag.</u><br> Windrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'<br> </FONT> <FONT COLOR=black> Windsnelheid <10.7: ' ..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft :' ..Bft.. '.<br><FONT COLOR=red> Windvlaag > 13.9:.....'..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl :' ..Bftvl.. '</FONT><br>' ..Regen)
local txt1 = ('<FONT COLOR=red> <u>3 WAARSCHUWING Windrichting en -vlaag.</u><br><br><br><br><br> ')
local txt2 = ('Windrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'<br> </FONT>')
local txt3 = ('<FONT COLOR=black> Windsnelheid <10.7: '..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft :' ..Bft..'<br>')
local txt4 = ('<FONT COLOR=red> Windvlaag ......>13.9: '..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl :' ..Bftvl..'</FONT>')
local txt5 = ('<br>' ..Regen)
--local resultString = txt1 ..txt2 ..txt3 ..txt4 ..txt5 -- mogelijkheid om txtStrings te combineren
domoticz.devices('Alarm Wind').updateAlertSensor(4,txt1 ..txt2 ..txt3 ..txt4 ..txt5) --4-red
end
if (graden >= 60 and graden <= 247) and (Ws_afgerond >= 10.7 and Wvlaag >13.9) then
--local txt = ('<FONT COLOR=red><b> 4 WAARSCHUWING.</u><br>Wrichting tussen (>60..<247): ' ..graden.. 'gr. = ' ..richting..'<br> Wsnelheid >10.7m/s: ' ..Ws_afgerond .. 'm/s. Kn:'..Kn..' Bft:' ..Bft.. '<br> Wvlaag >13.9m/s: .....'..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..' Bftvl: ' ..Bftvl.. '<br></FONT>' ..Regen)
-- domoticz.devices('Alarm Wind').updateAlertSensor(4,txt) --4-red
local txt1 = ('<FONT COLOR=red> <u>4 WAARSCHUWING.</u><br><br><br><br><br>')
local txt2 = ('Windrichting tussen (>60..<247): ' ..graden.. 'gr. ' ..richting..'<br>')
local txt3 = ('Windsnelheid <10.7: '..Ws_afgerond .. 'm/s. Kn:'..Kn..'. Bft :' ..Bft..'<br>')
local txt4 = ('Windvlaag ......>13.9: '..Wvlaag .. 'm/s. Kn_vl:' ..Kn_vl..'. Bftvl :' ..Bftvl..'</FONT>')
local txt5 = ('<br>' ..Regen)
--local resultString = txt1 ..txt2 ..txt3 ..txt4 ..txt5 -- mogelijkheid om txtStrings te combineren
domoticz.devices('Alarm Wind').updateAlertSensor(4,txt1 ..txt2 ..txt3 ..txt4 ..txt5) --4-red
end
--[[
if (graden >= 60 and graden <= 247) and (Ws_afgerond >= 10.7 or Wvlaag >= 13.9) then
domoticz.notify('Wind Alarm',' WindR, -snelh en -vlaag limieten overschreden. Gr: ' ..graden .. ' , Windvlg: '..Wvlaag .. ', Windsn : ' ..Ws_afgerond,domoticz.PRIORITY_NORMAL,domoticz.SOUND_SPACEALARM,nil,domoticz.NSS_PUSHOVER)
end
--]]
-- activering van het script indien device 'Lux dummy gem 30min' eenmalig boven de grenswaardelux is geweest
local Luxgrenswaarde = 3100 --3100
local Lux_startmoment = domoticz.devices('Lux dummy gem 30min').lux
domoticz.log('Startmoment average 30min: Lux '..Lux_startmoment, domoticz.LOG_DEBUG)
if Lux_startmoment < Luxgrenswaarde and domoticz.devices('Lux_30min_switch').state == 'On' then -- switch wordt Off gezet nadat het 30min gemiddelde is overschreden waardoor script locals actief kunnen worden
domoticz.log('Luxgrenswaarde '..Luxgrenswaarde .. 'Lux niet overschreden. Return', domoticz.LOG_DEBUG)
return
else
domoticz.devices('Lux_30min_switch').switchOff().checkFirst()
end
-- Check all sensor tresholds and if any exeeded close sunscreen
for sensorType, sensor in pairs(sensors) do
if (sensor['active'] == true) then
local device = domoticz.devices(sensor['device'])
local closeRule = sensor['closeRule']
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
if (closeRule(device)) then
switchOff(sunscreen, sensorType .. ' treshold exceeded, Sunscreen up')
domoticz.log(sensorType .. ' treshold exceeded', domoticz.LOG_DEBUG)
-- toegevoegd om de reden van open en dicht vast te leggen
txtSBlog = (sensorType.. ' treshold exceeded')
domoticz.log('==txtSBlog====: ' .. txtSBlog, domoticz.LOG_DEBUG)
domoticz.devices('Log open_dicht sunblinds').updateText(txtSBlog)
-- --
-- Return early when we exeed any tresholds
return
end
else
domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
end
end
-- All tresholds OK, sunscreen may be lowered
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
switchOn(sunscreen, 'Sun is shining, all thresholds OK, lowering sunscreen')
end
end
}