Automate Sunscreen and Blinds with lua

User avatar
remb0
Posts: 762
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Automate Sunscreen and Blinds with lua

Postby remb0 » Sunday 23 August 2015 10:59

Here is our complex script (MrFranky and I).

some key functions:
- everything can be adjust by uservariables
- script tells you when uservariables are missing
- complete logging with usefull options
- usefull notifacations (not only switched time but also reasons why the screen is up)
- nice printing to domoticz log

-safety options like: manual usage for a max period. so when you left and manual is on, system override after a x period.
- buienradar + Weatherunderground + optional own sensors



Download
https://drive.google.com/folderview?id=0ByoCQiC2jUrLfllnRl9SRktBSUp0a0lBME1SWV9yTDNQTkx1bmhmVk9HZXp6UDEzLURoZEU&usp=sharing
here you can find: 1-Functions script, 2-Sunscreen script and Documentation of script and variables.

Wiki ...
I post it when some other users are also satisfied and can confirm there are no bugs and documentation is valid!


Please reply with bugs / improvements / ideas or questions..


Help Wanted!
Documentation is always a problem you if you want to help documenting you can edit the documentation:
https://docs.google.com/spreadsheets/d/ ... sp=sharing







Code: Select all

-- Time Sunscreen
-- Check the (weather)conditions for controlling the Suncreen.
--
-- Release notes:
--  *104 12-07-2015 Using user variables instead of the normal variables
--  *105 15-07-2015 Open/Closed commando variabel, Start bash shell after change
--  *106 23-07-2015 Buienradar, Layout logfile, logfile name with ~d / ~m
--------------------------------------------------------------------------------
-- Variable
--
Script        = 'Time Sunscreen'                  --
Version       = 106                              --
VersionLog     = 106                              --
Version_Type  = 'Beta 01'                        --
Man_or_Auto   = 'Auto'                           -- Default

package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
My = require('MyFunc')
--------------------------------------------------------------------------------
-- Functions
--
function SendANotification()
   commandArray['SendNotification']='Sunscreen ' .. NewState .. '#Sunscreen ' .. DeviceName .. ' was in state ' .. CurState .. ' new state is ' .. NewState .. ', reason for change is ' .. My.EnumClear(Reason) .. ' / '.. os.date("%Y-%m-%d;%H:%M:%S").. '#0#pushover'
end

function LogActions()
   LogFile=string.gsub(LogFile,"~d",os.date("%Y-%m-%d"))
   LogFile=string.gsub(LogFile,"~m",os.date("%Y-%m"))
   
   if not My.File_exists(LogFile) then
    f=io.open(LogFile,"a")
    f:write("Datum ; Tijd ; DeviceName ; Man_or_Auto ; Current State ; New state ;  Reason up ; Version #".. VersionLog .."# ; Version Type ; " ..
            "Result_Daytime ; Result_Hour ; Result_Wind ; Result_Gust ; Result_Wu_Rain ; Result_Br_Rain ; Result_UvClose ; Result_Temperature_Close ; Result_UvOp ; Result_TemperatureOp ; Result ; "..
          "Nu_Hour <".. TH_Hour .." ; Wu_Wind <=".. TH_Wind .. "; Wu_Gust <=".. TH_Gust .. "; Wu_Rain <=".. TH_Wu_Rain .. "; Br_Rain <=".. TH_Br_Rain .. " ; Wu_Uv <=".. TH_Uv_Close .. "/" .. TH_Uv_Open .. "; Wu_Temperature <=".. TH_Tp_Close .. "/".. TH_Tp_Open .. "; "..
          "Uv Sim ; SwManStart ; SwManEnd ; Switch manual ; SwManDif ; Notifications ; LogAction ; SwitchTime ; SwitchDiff ; " ..
          LogCap01 .. ";" .. LogCap02 .. ";" .. LogCap03)
     f:write("\r\n")
    else
    f=io.open(LogFile,"r")
    c=f:read("*line")
    if string.match(c, "#" ..VersionLog .. "#") then
    else
      print(".  Version of logfile ".. LogFile .." is not correct.")
    end
    f:close()
    f=io.open(LogFile,"a")
   end
    f:write(os.date("%Y-%m-%d;%H:%M:%S") .. ";" .. DeviceName .. ";" .. Man_or_Auto .. ";" .. CurState .. ";" .. NewState .. ";" .. My.EnumClear(Reason) ..  ";" .. Version .. ";" .. Version_Type .. ";" ..
             Res_Dayl .. ";" .. Res_Hour .. ";" .. Res_Wind .. ";" .. Res_Gust .. ";" .. Res_WuRain .. ";" .. Res_BrRain .. ";" .. Res_UvCl .. ";" .. Res_TpCl .. ";" .. Res_UvOp .. ";" .. Res_TpOp .. ";".. Result .. ";" ..
           Nu_Hour .. ";" .. Wu_Wind .. ";" .. Wu_Gust .. ";" .. Wu_Rain .. ";" .. Br_Rain .. ";".. Wu_Uv .. ";" .. Wu_Temp .. ";" ..
           Uv_Sim .. ";"  .. SwManStart .. ";" .. SwManEnd .. ";" .. Man_to_Auto .. ";" .. SwManDif .. ";" .. Notifications .. ";" .. LogAction .. ";" .. SwitchTime .. ";" .. SwitchDiff .. ";" ..
           LogAdd01 .. ";" .. LogAdd02 .. ";" .. LogAdd03)
    f:write("\r\n")
    f:close()
end
--------------------------------------------------------------------------------

commandArray = {}
print ("______________________________________________________________________")
print (">> ".. Script .. ".......v" .. Version .. "....." .. Version_Type)

-- User variables
--
UserVarErr     = 0
RunFast        = My.GetUserVar("SUN_RunFast")            -- 5
RunSlow        = My.GetUserVar("SUN_RunSlow")            -- 5
RunLast        = My.GetUserVar("SUN_RunLast")           -- 2015-07-29 18:30:00

if (timeofday['Daytime']) then RunEveryxMin=RunFast else RunEveryxMin=RunSlow end
TDiff = My.Round(My.TimeDiff(os.time(),RunLast)/60,0)
if TDiff < RunEveryxMin then
   print (".  Wait : ".. TDiff .. " / " .. RunEveryxMin)
   goto done
end
nu=tostring(os.date ("%Y-%m-%d %H:%M:%S"))
commandArray['Variable:SUN_RunLast'] = nu
print (".  ")
DeviceLuaMstr  = My.GetUserVar("LUA_MasterSW")          -- LUA_MasterSW
lat            = My.GetUserVar("Gen_Latitude") + 0       --
lon            = My.GetUserVar("Gen_Longitude") + 0      --
LogFile        = My.GetUserVar("SUN_LogFile")         -- /home/pi/log/Sunscreen.csv
DeviceName     = My.GetUserVar("SUN_DeviceName")      -- Sunscreen
DeviceManual   = My.GetUserVar("SUN_DeviceManual")      -- Sunscreen - Manual
DeviceAtHome   = My.GetUserVar("SUN_DeviceAtHome")      -- Not in use
DeviceTemp      = My.GetUserVar("SUN_DeviceTemp")      -- 45.00;NE;0;0;23.1;23.1   In most cases this is the wind device. Temperature is on position 5
DeviceRain     = My.GetUserVar("SUN_DeviceRain")      -- 0;0.0               Weather undergMy.Round Rain device
DeviceUvme     = My.GetUserVar("SUN_DeviceUvme")      -- 0.0;0.0               Weather undergMy.Round Uv device
DeviceBuien    = My.GetUserVar("SUN_DeviceBuien")      -- 2                  Buienradar (under construction)
DeviceAddVal01 = My.GetUserVar("SUN_AddValue01")      -- Temp_Livingroom
DeviceAddVal02 = My.GetUserVar("SUN_AddValue02")      -- Temp_Bedroom
DeviceAddVal03 = My.GetUserVar("SUN_AddValue03")      -- x
InstVersion    = My.GetUserVar("SUN_InstVersion")      -- 104
ActionClose    = My.GetUserVar("SUN_ActionClose")      -- On
ActionOpen     = My.GetUserVar("SUN_ActionOpen")      -- Off
ShAfterAction  = My.GetUserVar("SUN_ShAfterAction")      -- sudo /home/pi/domoticz/scripts/bash/log-dropbox.sh
TH_Wind        = My.GetUserVar("SUN_TH_Wind") + 0      -- Treshold wind
TH_Gust        = My.GetUserVar("SUN_TH_Gust") + 0      -- Treshold windstoten
TH_Wu_Rain        = My.GetUserVar("SUN_TH_Wu_Rain") + 0   -- Treshold regen/neerslag
TH_Br_Rain     = My.GetUserVar("SUN_TH_Br_Rain") + 0   -- Treshold regen/neerslag
TH_Uv_Close    = My.GetUserVar("SUN_TH_Uv_Close") + 0    -- 2.5    -- treshold voor Uv close
TH_Uv_Open     = My.GetUserVar("SUN_TH_Uv_Open") + 0   -- 1.5    -- treshold voor Uv open   
TH_Tp_Close    = My.GetUserVar("SUN_TH_Tp_Close") + 0   -- 20     -- treshold voor Temperature close
TH_Tp_Open     = My.GetUserVar("SUN_TH_Tp_Open") + 0   -- 19     -- treshold voor Temperature close
TH_Hour        = My.GetUserVar("SUN_TH_Hour") + 0      -- Treshold hour
ManualTime     = My.GetUserVar("SUN_ManualTime")      -- 'D'  D=Daytime / A=All
Debugging      = My.GetUserVar("SUN_Debugging")         -- 'Y'
Man_to_Auto    = My.GetUserVar("SUN_Man_to_Auto") + 0   -- 240  Minutes manual override
SwitchTime     = My.GetUserVar("SUN_SwitchTime") + 0   -- 10
LogAction      = My.GetUserVar("SUN_LogAction")         -- 'Y'    A=All, Y=Only on change
Notifications  = My.GetUserVar("SUN_Notifications")      -- 'Y'  Y=Yes, N=No

if UserVarErr> 0 then
   print (".  Please check user variables.")
   print (".  ")
end
InstV=tonumber(InstVersion)
if InstV==nil then InstV=100 end
if InstV < Version then
   print (".  ")
   print (".  Registered version : " .. InstV .. " , running version : " .. Version )
   print (".  Not able to update automatically.")
   print (".  ")
   -- commandArray['Variable:SUN_InstVersion']= tostring(Version)
   goto done
end
if UserVarErr> 0 then goto done end

if (otherdevices[DeviceLuaMstr]) == 'Off' then
   print (".  LUA Master switch is off")
   goto done
end

-- Variable
--
if (string.len(DeviceAddVal01)) > 1 then
   LogCap01     = DeviceAddVal01               --
   LogAdd01      = My.GetValue(otherdevices_svalues[DeviceAddVal01],1)
else
   LogCap01     = "nvt"               --
   LogAdd01      = 0
end
if (string.len(DeviceAddVal02)) > 1 then
   LogCap02     = DeviceAddVal02                  --
   LogAdd02      = My.GetValue(otherdevices_svalues[DeviceAddVal02],1)
else
   LogCap02     = "nvt"               --
   LogAdd02      = 0
end
if (string.len(DeviceAddVal03)) > 1 then
   LogCap03     = DeviceAddVal03                        --
   LogAdd03      = My.GetValue(otherdevices_svalues[DeviceAddVal03],1)            
else
   LogCap03     = "nvt"               --
   LogAdd03      = 0
end


--
-- Retrieve values from weather devices
--
Wu_Dev_Temp = otherdevices_svalues[DeviceTemp]
Wu_Dev_Rain = otherdevices_svalues[DeviceRain]
Wu_Dev_UvMe = otherdevices_svalues[DeviceUvme]
Br_Dev_Rain = otherdevices_svalues[DeviceBuien]
--
-- Split values from devices
--
Wu_Wind = My.GetValue(Wu_Dev_Temp,3)
Wu_Gust = My.GetValue(Wu_Dev_Temp,4)
Wu_Temp = My.GetValue(Wu_Dev_Temp,5)
Wu_Rain = My.GetValue(Wu_Dev_Rain,2)
Wu_Uv = My.GetValue(Wu_Dev_UvMe,1)

Nu_Hour=tonumber(os.date('%H',time))
Reason=""
Reascl=""
Reasop=""
Uv_Wim=""
--
-- Special correction for hot days
--
Uv_Sim=""
if Wu_Uv < TH_Uv_Close and Wu_Temp >= 20 and Nu_Hour >= 7 and Nu_Hour <= 9 then
   Wu_Uv = TH_Uv_Close
   Uv_Sim = "01 Hot day rule"
end
if Wu_Uv < TH_Uv_Close and Wu_Uv >= 0.1 and  Wu_Temp >= 20 and Nu_Hour >= 9 and Nu_Hour <= 11 then
   Wu_Uv = TH_Uv_Close
   Uv_Sim = "02 Hot day rule"
end
--
-- Calculate pre results
-- Redenen om niet naar beneden te gaan
RainPrediction = My.Round(My.IsItGonnaRain(15, lat, lon),1)
-- Br_Rain=My.Round(10^((RainPrediction-109)/32),1)
Br_Rain = RainPrediction

if (timeofday['Daytime'])   then Res_Dayl=1   else Res_Dayl=0 Reason=Reason .. "Sunrise ," end
if Nu_Hour < TH_Hour        then Res_Hour=1   else Res_Hour=0 Reason=Reason .. "Hour " .. Nu_Hour .. " ," end
if Wu_Wind <= TH_Wind       then Res_Wind=1   else Res_Wind=0 Reason=Reason .. "Wu Wind " .. Wu_Wind .. " ," end
if Wu_Gust <= TH_Gust       then Res_Gust=1   else Res_Gust=0 Reason=Reason .. "Wu Gust " .. Wu_Gust .. " ," end
if Wu_Rain <= TH_Wu_Rain    then Res_WuRain=1 else Res_WuRain=0 Reason=Reason .. "Wu Rain " .. Wu_Rain .. " ," end
if Br_Rain <= TH_Br_Rain    then Res_BrRain=1 else Res_BrRain=0 Reason=Reason .. "Br Rain " .. Br_Rain .. " ," end
-- Redenen om niet naar beneden te gaan
if Wu_Uv   >= TH_Uv_Close   then Res_UvCl=1   else Res_UvCl=0 Reascl=Reascl .. "Wu Uv Closed " .. Wu_Uv .. " ," end
if Wu_Temp >= TH_Tp_Close   then Res_TpCl=1   else Res_TpCl=0 Reascl=Reascl .. "Wu Temp Closed " .. Wu_Temp .. " ," end
-- Redenen om niet naar beneden te blijven (dus scherm omhoog)
if Wu_Uv   >= TH_Uv_Open    then Res_UvOp=1   else Res_UvOp=0 Reasop=Reasop .. "Wu Uv Open " .. Wu_Uv .. " ," end
if Wu_Temp >= TH_Tp_Open    then Res_TpOp=1   else Res_TpOp=0 Reasop=Reasop .. "Wu Temp Open " .. Wu_Temp .. " ," end
--
-- Print decision info in the log
--
if (otherdevices[DeviceName]) == 'Open' then
   print ( ".  These conditions are valid when sunscreen is Up / Open: " )
else
   print ( ".  These conditions are valid when sunscreen is Down / Closed: " )
end
if (timeofday['Daytime']) then
   print ( ".  " .. Res_Dayl .. " - Daytime   : True" )
else
   print ( ".  " .. Res_Dayl .. " - Daytime   : False" )
end
   print ( ".  " .. Res_Hour ..   " - Wu Hour  : " .. Nu_Hour .. " <= Th : " .. TH_Hour )
   print ( ".  " .. Res_Wind ..   " - Wu Wind  : " .. Wu_Wind .. " <= Th : " .. TH_Wind )
   print ( ".  " .. Res_Gust ..   " - Wu Gust  : " .. Wu_Gust .. " <= Th : " .. TH_Gust )
   print ( ".  " .. Res_WuRain .. " - Wu Rain  : " .. Wu_Rain .. " <= Th : " .. TH_Wu_Rain )
   print ( ".  " .. Res_BrRain .. " - Br Rain  : " .. Br_Rain .. " <= Th : " .. TH_Br_Rain )
if (otherdevices[DeviceName]) == 'Open' then
   print ( ".  " .. Res_UvCl ..   " - Wu Uv-i  : " .. Wu_Uv   .. " >= Th : " .. TH_Uv_Close .. " (Up / Open)")
   print ( ".  " .. Res_TpCl ..   " - Wu Temp  : " .. Wu_Temp .. " >= Th : " .. TH_Tp_Close .. " (Up / Open)")
   Reason=Reason .. Reascl
   Result = Res_Dayl + Res_Hour + Res_Wind + Res_Gust + Res_WuRain + Res_UvCl + Res_TpCl + Res_BrRain
else
   print ( ".  " .. Res_UvOp ..   " - Wu Uv-i  : " .. Wu_Uv   .. " >= Th : " .. TH_Uv_Open .. " (Down / Closed)")
   print ( ".  " .. Res_TpOp ..   " - Wu Temp  : " .. Wu_Temp .. " >= Th : " .. TH_Tp_Open .. " (Down / Closed)")
   Reason=Reason .. Reasop
   Result = Res_Dayl + Res_Hour + Res_Wind + Res_Gust + Res_WuRain + Res_UvOp + Res_TpOp + Res_BrRain
end
   print ( ".  " .. Result .. " / 8 score.")
if (Wu_Rain<1 and Br_Rain>1) or (Br_Rain<1 and Wu_Rain>1) then
   print ( ".  Difference between WU and Buienradar result.  WU : " .. Res_WuRain .. " Buienradar : " .. Res_BrRain)
end
   
--
-- Manual override for x minutes
--
SwManStart = otherdevices[DeviceManual]
TDiff = My.Round(My.TimeDiff(os.time(),otherdevices_lastupdate[DeviceManual])/60,0)
if (otherdevices[DeviceManual]) == 'On' then
   print (".  Last change manual state : " .. TDiff .. " minutes ago.")
   if TDiff >= Man_to_Auto then
      -- To long in manual mode, switch to auto
      print(".  Turn Manual switch off")
      commandArray[DeviceManual] = 'Off'   
   end

   if ManualTime~="D" and Res_Dayl==0 then
      -- Outside daytime period, turn manual override off
      print(".  Turn Manual switch off, outside daytime")
      commandArray[DeviceManual] = 'Off'   
   end
end

SwitchDiff = My.Round(My.TimeDiff(os.time(),otherdevices_lastupdate[DeviceName])/60,0)
-- print (".  Last change screen state : " .. SwitchDiff .. " minutes ago.")      
SwManEnd = otherdevices[DeviceManual]
SwManDif = TDiff

--
-- Current state Up / Open         Change to        Down / Closed   ?
--
if (otherdevices[DeviceName]) == 'Open' then
   CurState="Up / Open"
   if Res_Dayl + Res_Hour + Res_Wind + Res_Gust + Res_WuRain + Res_UvCl + Res_TpCl + Res_BrRain == 8 then
      if (otherdevices[DeviceManual]) == 'On' then
         print (".  Sunscreen Manual")
         Man_or_Auto = 'Manual'
         Reason=Reason .. " (Manual) , "
      else
         if SwitchDiff <= SwitchTime then
            print (".  Recent open, wait for switchtime")
            Reason=Reason .. "Recent open , "
         else
            -- Closed
            NewState = "Down / Closed"
            print (".  Action: Change to state : " .. NewState)
            commandArray[DeviceName] = ActionClose
            if Reason == "" then Reason = "No reason ," end
            if Notifications == 'Y' then SendANotification() end
            if LogAction == 'Y' or LogAction == 'A' then LogActions() end
            if (string.len(ShAfterAction)) > 1 then os.execute(ShAfterAction) end
         end
      end
   else
      if (otherdevices[DeviceManual]) == 'On' then
         print (".  Sunscreen Manual")
         Man_or_Auto = 'Manual'
         Reason=Reason .. " (Manual) , "
      end
      print (".  Action: None, Reason to stay in state Up / Open :")
   end
end


--
-- Current state Down / Closed      Change to       Up / Open      ?
--
if (otherdevices[DeviceName]) == 'Closed' or (otherdevices[DeviceName]) == 'Stopped' then
   if (otherdevices[DeviceName]) == 'Closed' then CurState = "Down / Closed" else CurState="Stopped" end
   if Res_Dayl + Res_Hour + Res_Wind + Res_Gust + Res_WuRain + Res_UvOp + Res_TpOp + Res_BrRain < 8 then
      if (otherdevices[DeviceManual]) == 'On' then
         print (".  Sunscreen Manual")
         Man_or_Auto = 'Manual'
         Reason=Reason .. "Manual , "
      else
            -- Open
            NewState = "Up / Open"
            print (".  Action: Change to state : " .. NewState)
            commandArray[DeviceName] = ActionOpen
            if Reason == "" then Reason = "No reason ," end
            if Notifications == 'Y' then SendANotification() end
            if LogAction == 'Y' or LogAction == 'A' then LogActions() end
            if (string.len(ShAfterAction)) > 1 then os.execute(ShAfterAction) end
      end
   else
      print (".  Action: None (Down / Closed)")
      end
end

NewState = "Idle"
if Reason == "" then Reason = "No reason ," end
print ( ".  Reason: " .. My.EnumClear(Reason))
if LogAction=='A' then LogActions() end
::done::
print ("______________________________________________________________________")
return commandArray

Justintime
Posts: 312
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby Justintime » Sunday 23 August 2015 12:08

WOW that looks very impresive......

I am going to try this when i have time. I allready have a working script for my sunscreen.
If i understand correctly i can name the devices in the Variables screen? So no editing in the Lua script??

Just wondering?? Does this script undermine the sometimes false values of buienradar? Like if value comes back three time then its true?

Because thats still a pain in the .... My script works like....if there is rain. stay closed the rest of the day. Otheriwse it will go up and down. I have set my value on 55 on Buienradar.

User avatar
remb0
Posts: 762
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby remb0 » Sunday 23 August 2015 16:53

let me know the feedback please.
you are right everything with switches and uservariables
yes I think we tried: It runs several times and takes a average.

We use it with info from WU. but I want to buy a own weather station. because the whole summer scripts runned fine but when it doesn't it was the fault of wrong info of WU.


Justintime wrote:WOW that looks very impresive......

I am going to try this when i have time. I allready have a working script for my sunscreen.

If i understand correctly i can name the devices in the Variables screen? So no editing in the Lua script??

Just wondering?? Does this script undermine the sometimes false values of buienradar? Like if value comes back three time then its true?

Because thats still a pain in the .... My script works like....if there is rain. stay closed the rest of the day. Otheriwse it will go up and down. I have set my value on 55 on Buienradar.

Justintime
Posts: 312
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby Justintime » Sunday 23 August 2015 19:23

I have copied all the uservariables from the manual in Domoticz.

I see in the log "Error: EventSystem: /home/pi/domoticz/scripts/lua/MyFunc.lua:57: field 'year' missing in date table"

Its related to this line in the script "ResTime = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}"

User avatar
remb0
Posts: 762
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby remb0 » Friday 28 August 2015 21:59

is your SUN_RunLast variable like: 2015-07-29 18:30:00


Justintime wrote:I have copied all the uservariables from the manual in Domoticz.

I see in the log "Error: EventSystem: /home/pi/domoticz/scripts/lua/MyFunc.lua:57: field 'year' missing in date table"

Its related to this line in the script "ResTime = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}"

miko1979
Posts: 16
Joined: Friday 29 January 2016 15:00
Target OS: -
Domoticz version:
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby miko1979 » Monday 21 March 2016 21:56

Hello remb0, i installed your scripts, but i get the error
2016-03-21 20:55:00.890 Error: EventSystem: in Sunscreen: /home/pi/domoticz/scripts/lua/MyFunc.lua:31: attempt to concatenate local 'Text' (a nil value) any idea what i did wrong?


Verzonden vanaf mijn iPad met Tapatalk

miko1979
Posts: 16
Joined: Friday 29 January 2016 15:00
Target OS: -
Domoticz version:
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby miko1979 » Monday 21 March 2016 22:06

Just found the problem, My temperature sensor had a space in the name, this was used in the 'SUN_AddValue01' the script can't handle spaces.


Verzonden vanaf mijn iPad met Tapatalk

schulpr
Posts: 65
Joined: Thursday 01 January 2015 10:10
Target OS: NAS (Synology & others)
Domoticz version: Beta
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby schulpr » Sunday 27 March 2016 15:45

Hello,

Can anyone please tell me how I get the "Wind" dummy filled with the proper value? This is what I have found in the forum:

--WU wind

local sensorwind = 'WUwind'
local idxw = 294

commandArray = {}

if devicechanged[sensorwind] then
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[sensorwind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWindSpeed = tonumber(sWindSpeed)

commandArray = {['UpdateDevice'] = idxw .. '|0|' .. sWindSpeed} --How can I fill dummy wind hardware I created?

end
return commandArray


Thanks in advance for the help!

Rob

RikkieB
Posts: 19
Joined: Monday 28 March 2016 17:11
Target OS: Raspberry Pi
Domoticz version: V3.6277
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby RikkieB » Saturday 16 April 2016 15:02

Hi,

I get an error on line 65:

2016-04-16 12:22:12.259 Error: EventSystem: in Rolluik_script_uitgebreid: [string "-- Time Sunscreen ..."]:65: unexpected symbol near '5'

It concerns:

RunFast = My.GetUserVar("SUN_RunFast") 5 -- 5

Any idea?

thx.

MaartenJB
Posts: 1
Joined: Wednesday 27 July 2016 18:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby MaartenJB » Wednesday 27 July 2016 18:29

Hi, great script, thanks for sharing.

I've got a little addition for it to improve the speed of the buien radar part.

Code: Select all

   function My.IsItGonnaRain( minutesinfuture, lat, lon )
   
........
-- Set timeout and retry here so the script won't hang, when it's not able to connect to buienradar
      read = os.execute('curl --retry 1 --connect-timeout 1 -s -o '..tempfilename..' "'..url..'"') 
      
      
.......
-- Here we will only process the lines that we care about, after that break out
        -- When a line entry has a time in the future AND is in the given range, then totalize the rainfall
        if (difference > 0) then
          if (difference<=minutesinfuture*60) then
           if debug then print('Line in time range found') end
           rain=tonumber(string.sub(tostring(line), 0, 3))
           totalrain = totalrain+rain
           rainlines=rainlines+1
           if debug then print('Rain in timerange: '..rain) end
           if debug then print('Total rain now: '..totalrain) end
         else
              if debug then print('Done processing rain data') end         
           break   
          end
        end
.........


bgitmans
Posts: 16
Joined: Thursday 20 August 2015 22:19
Target OS: OS X
Domoticz version: 3.5166
Location: Boxtel, the Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby bgitmans » Monday 05 September 2016 20:10

I get the following error: MyFunc.lua:62: bad argument #1 to 'len' (string expected, got nil).

I already solved some errors, however I don't know where to look to solve this one.

Could you be of any help?

User avatar
jvdz
Posts: 746
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby jvdz » Monday 05 September 2016 20:19

Have you specified 2 parameters when calling My.TimeDiff(Time1,Time2) ?

Jos

bgitmans
Posts: 16
Joined: Thursday 20 August 2015 22:19
Target OS: OS X
Domoticz version: 3.5166
Location: Boxtel, the Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby bgitmans » Monday 05 September 2016 22:40

I have followed the instructions on the google docs page, and created the user variables, there is no further instruction about creating specific parameters, besides this part in the code:

Code: Select all

   function My.TimeDiff(Time1,Time2)
      if string.len(Time1)>12 then Time1 = My.ConvTime(Time1) end
      if string.len(Time2)>12 then Time2 = My.ConvTime(Time2) end   
      ResTime=os.difftime (Time1,Time2)
      return ResTime
   end

User avatar
jvdz
Posts: 746
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby jvdz » Tuesday 06 September 2016 7:51

So, how does the line look that uses this function?

Jos

MichealLocus
Posts: 9
Joined: Saturday 03 December 2016 11:44
Target OS: Linux
Domoticz version:
Contact:

Re: Automate Sunscreen and Blinds with lua

Postby MichealLocus » Saturday 03 December 2016 15:32

I didn`t see that , May be if I see that I will convey it to you . THANKS


Return to “Temperature and Weather”

Who is online

Users browsing this forum: No registered users and 1 guest