We have moved at community.getvera.com

Author Topic: [Solved] Help with roller shutter script  (Read 1142 times)

Offline hhamresand@gmail.com

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
[Solved] Help with roller shutter script
« on: June 07, 2015, 03:41:48 pm »
Hi,

I have connected a Fibaro Roller Shutter to my terrace awning and would like to controll it depending on weather.
For that I have created two scripts.

If it's bad weather, I would like it to roll in. For that I have created below script:
Code: [Select]
local c = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","ConditionGroup",18)
local w = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindSpeed",18)
local g = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindGust",18)
local l = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelTarget",23)

if (((c == "rain") or (c == "snow") or (c == "cloudy") or (w > "14") or (g > "19")) and (l < "95"))
then
  return true
else
  return false
end

And if it?s sunny, I trigger a scene but would like to know that it's not too windy or that the awning is already rolled out. For that I would like to use below script.
Code: [Select]
local w = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindSpeed",18)
local g = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindGust",18)
local l = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelTarget",23)

if ((w < "15") and (g < "15") and (l > "90"))
then
  return true
else
  return false
end


But it will not work for me. I seems like the Lua-engine crashes...  ???
Is there anyone who could give me some guidance?
Thanks in advance!

//
Henrik
« Last Edit: June 16, 2015, 02:19:11 pm by hhamresand@gmail.com »

Offline hhamresand@gmail.com

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Workaround/Solved: Help with roller shutter script
« Reply #1 on: June 13, 2015, 03:53:27 pm »
After a few hours of reading in this forum I have made two scenes running the scripts below..

1. Scene is triggered to run every 30minutes and the script checks weather/wind to see if the awning should be rolled out.
Code: [Select]
local function checkTime()
local pStart = "08:00"    -- Start of time period
local pEnd = "20:00"      -- End of time period
local allow = true        -- Runs if time schedule is true, else blocks it
local hS, mS = string.match(pStart,"(%d+)%:(%d+)")
local mStart = (hS * 60) + mS
local hE, mE = string.match(pEnd,"(%d+)%:(%d+)")
local mEnd = (hE * 60) + mE
local tNow = os.date("*t")
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end
end

local function checkDay()
local dID = 31            -- Device ID of your DayTime plugin
local allow = true -- true runs scene during day
local status = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status",dID)
return ((status == "1") == allow)
end

local function checkWheater()
local rID = 23 -- Device ID of your Roller Shutter device
local dID = 24 -- Device ID of your Weather app
local wHigh = 20 -- Highest wind level, value/3.6 to get m/s Vindklass 2 made for 10.5
local gHigh = 20 -- Highest gust level
local allow = true -- true runs scene when in range, false blocks it
local level = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelTarget",rID)
local gust = tonumber((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindGust",dID)))
local wind = tonumber((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindSpeed",dID)))
if  (level == "100") -- Checks if the marquis is already rolled out
and ((wind <= wHigh) and (gust <= gHigh)) -- High wind or gusts blocks scene from running
then
local cond = tostring((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","ConditionGroup",dID)))
return (((cond == "sunny") or (cond == "partlysunny") or (cond == "partlycloudy") or (cond == "mostlysunny") or (cond == "clear")) == allow)
else
return false
end
end

return (checkTime() and checkDay() and checkWheater()) -- runs scene when in time interval, daytime and the weather is right

2. Scene is triggered to run every 5minutes and the script checks weather/wind to see if the awning should be rolled in.
Code: [Select]
local function checkWind()
local dID = 24 -- Device ID of your Weather app
local wHigh = 25 -- Highest wind level, value/3.6 to get m/s Vindklass 2 made for 10.5
local gHigh = 30 -- Highest gust level
local allow = true -- true runs scene when in range, false blocks it
local gust = tonumber((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindGust",dID)))
local wind = tonumber((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","WindSpeed",dID)))
return (((wind >= wHigh) or (gust >= gHigh)) == allow)
end

local function checkWheater()
local dID = 24 -- Device ID of your Weather app
local allow = true -- true runs scene when in range, false blocks it
local cond = tostring((luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","ConditionGroup",dID)))
return (((cond == "rain") or (cond == "snow") or (cond == "tstorms") or (cond == "unknown") or (cond == "cloudy") or (cond == "flurries") or (cond == "fog") or (cond == "mostlycloudy") or (cond == "sleet")) == allow)
end

local function checkTime()
local dID = 31            -- Device ID of your DayTime plugin
local allow = true -- true runs scene during night
local status = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status",dID)
return ((status == "0") == allow)
end

local rID = 23 -- Device ID of your Roller Shutter device
local level = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelTarget",rID)
if  (level == "100") -- Checks if the marquis is already rolled in
then
return false
else
return (checkWind() or checkWheater() or checkTime()) -- runs scene if high wind/gusts, the weather is bad or if it's night.
end
« Last Edit: June 28, 2015, 12:19:52 pm by hhamresand@gmail.com »