Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Question

Posted

Hi guys,

I am stucked can you please help me?

In below code the GV will stay on "Ochtendgloren"

Thanks in advanced for your help

 

 --[[
%% autostart
%% properties
%% globals
--]]
local sourceTrigger = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
 
  local debug = true;

  -- check script instance count in memory
  if (tonumber(fibaro:countScenes()) > 1) then
    if debug then fibaro:debug("Script already running."); end
    fibaro:abort();
  end

  if debug then fibaro:debug("HC2 start script at " .. os.date()); end

  while true do
    local ochtendgloren = os.date("%H:%M", os.time()+50*60)
    local gordijnopen      = os.date("%H:%M", os.time()+15*60)
    local sunrise         = fibaro:getValue(1, "sunriseHour")

    
    local sunset         = fibaro:getValue(1, "sunsetHour")
    local gordijndicht  =os.date("%H:%M", os.time()-50*60)
    local avondrood      = os.date("%H:%M", os.time()-50*60)

    local currentTime     = os.date("%H:%M");
    local TimeOfDay     = fibaro:getGlobal("TijdStip");


--Sunrise
    
    if ( ochtendgloren >= sunrise and currentTime < gordijnopen and TijdStip ~= "Ochtendgloren" )
    then
      fibaro:setGlobal("TijdStip", "Ochtendgloren");
      if debug then fibaro:debug("Ochtendgloren"); end
     
      
       if ( gordijnopen >= sunrise and currentTime < sunrise and TijdStip ~= "GordijnOpen" )
    then
      fibaro:setGlobal("TijdStip", "GordijnOpen");
      if debug then fibaro:debug("GordijnOpen"); end

         
        
        
        
--sunset  
 

        
    elseif ( gordijndicht >= sunset and currentTime > sunset and TijdStip ~= "GordijnDicht" )
   then
    fibaro:setGlobal("TijdStip", "GordijnDicht");
     if debug then fibaro:debug("GordijnDicht"); end
              
    
        
    elseif ( avondrood >= sunset and currentTime > sunset and TijdStip ~= "Avondrood" )
    then
      fibaro:setGlobal("TijdStip", "Avondrood");
      if debug then fibaro:debug("Avondrood"); end
      
     end
    fibaro:sleep(60*1000);
  end
end
   else
  fibaro:debug("Script can only be run via autostart")
  end

Recommended Posts

  • 0
Posted (edited)

Ok @Sjakie,

 

try this:

Please login or register to see this code.

Please login or register to see this image.

/monthly_2019_04/image.png.8e2ca3678a8accbba43748dc12cdd19d.png" />

 

you can do the same with sunset and curtain closing :-D

So can you make your curtains depending on sunrise and sunset

Edited by Bodyart
  • 0
  • Inquirer
  • Posted

    getting errorplease send complete scene

     

    • 0
    Posted (edited)

    Please login or register to see this code.

    Far from complete just added the calculation for curtain opening depending on sunrise. You need to do the same for curtain closing.....

    Edited by Bodyart
    • 0
  • Inquirer
  • Posted

    thanks!!!!!

    gona play with it

    • 0
    Posted

    If this is what you want to achieve:

    Please login or register to see this image.

    /monthly_2019_04/aaa.jpg.3917ba698fc3a6516db3eb3d79465f4a.jpg" style="width:600px;height:auto;" alt="aaa.jpg.3917ba698fc3a6516db3eb3d79465f4a.jpg" />

     

    then try this code with defined function calculate:

    Please login or register to see this code.

    Enjoy coding!

    • 0
    Posted

    @Sjakie,

     

    did you try the code already??

    • 0
  • Inquirer
  • Posted

    Hi @Bodyart,

    Yesterday I implemented the scene and regretely it was not working, snif, snif. This morning I started to look in to it and I must admit there where some errors in the scene. Now i hope it is okay.

    I added another day part in and it is changing the GV. I must see if he will change later on today.

    In advance I will modify all related scenes with the new names I created to avoid any interference of other GV or scenes.

    That is why I did not update you because I am still working on it.

    Thanks for your interest and support

    • 0
  • Inquirer
  • Posted

    Hi update:

    Curtain closed at 20.32

    Lights should be off by EveningRed >>>GV was updated, typo in scene after correction outside lights off.

    If tomorrow the curtains opens and outside lights switch I will be very happy

    Thanks

    • 0
  • Inquirer
  • Posted

    Hi @Bodyart,

    There is an error in I think "curtainclose" if I take it out the GV change into Test. others he will jump after the first save  into "curtainclose" while its Test time.

    I can not find what is wrong can you discover it?

    --[[
    %% autostart
    %% properties
    %% globals
    --]]


    local startSource = fibaro:getSourceTrigger();

     

    if tonumber(fibaro:countScenes())>1 then os.exit() end

    local sourceTrigger=fibaro:getSourceTrigger()
    if (sourceTrigger["type"]=="autostart") then
      local debug=true
      -- check script instance count in memory
      if debug then fibaro:debug("HC2 start script at "..os.date()) end
      while true do
        local Dagdeel       = fibaro:getGlobal("Dagdeel")
        local currentTime  = os.date("%H:%M")
        local sunrise      = fibaro:getValue(1, "sunriseHour")
        local sunset       = fibaro:getValue(1, "sunsetHour")
     --   local eveningred   = os.date("%H:%M", os.time()-50*60)
     --   local dawn         = os.date("%H:%M", os.time()+50*60)
     --   local daytime      = os.date("%H:%M", os.time()+1*60)
     --   local curtainclose = os.date("%H:%M", os.time()-50*60)

        
    --dawn
    local Hour,Minute=string.match(sunrise,"(%d+):(%d+)")
        local M=(Minute -50)%60
        local exH=math.floor((Minute -50)/60)
        local H=(Hour+0+exH)%24
        fibaro:debug('dawn, '..string.format("%02d:%02d",H,M))
        local dawn  = string.format("%02d:%02d",H,M)

    --curtainopen
        local Hour,Minute=string.match(sunrise,"(%d+):(%d+)")
        local M=(Minute -5)%60
        local exH=math.floor((Minute -5)/60)
        local H=(Hour+0+exH)%24
        fibaro:debug('Gordijn open '..string.format("%02d:%02d",H,M))
        local curtainopen  = string.format("%02d:%02d",H,M)
        
    --daytime
    local Hour,Minute=string.match(sunrise,"(%d+):(%d+)")
        local M=(Minute -1)%60
        local exH=math.floor((Minute -1)/60)
        local H=(Hour+0+exH)%24
        fibaro:debug('daytime '..string.format("%02d:%02d",H,M))
        local daytime  = string.format("%02d:%02d",H,M)

    --test
    local Hour,Minute=string.match(sunrise,"(%d+):(%d+)")
        local M=(Minute +140)%60
        local exH=math.floor((Minute +140)/60)
        local H=(Hour+0+exH)%24
        fibaro:debug('test '..string.format("%02d:%02d",H,M))
        local test  = string.format("%02d:%02d",H,M)
        
        
    --curtainclose
    local Hour,Minute=string.match(sunset,"(%d+):(%d+)")
        local M=(Minute +1)%60
        local exH=math.floor((Minute +1)/60)
        local H=(Hour+0+exH)%24
        fibaro:debug('curtainclose '..string.format("%02d:%02d",H,M))
        local curtainclose  = string.format("%02d:%02d",H,M)
        
    --eveningred
         local Hour,Minute=string.match(sunset,"(%d+):(%d+)")
         local M=(Minute +40)%60
         local exH=math.floor((Minute +40)/60)
         local H=(Hour+0+exH)%24
         fibaro:debug('eveningred '..string.format("%02d:%02d",H,M))
         local eveningred  = string.format("%02d:%02d",H,M)
        


        
        fibaro:debug("Dagdeel: ".. Dagdeel)
        fibaro:debug("dawn: "..dawn)
        fibaro:debug("curtainopen: ".. curtainopen)
        fibaro:debug("sunrise: ".. sunrise)
        fibaro:debug("daytime: "..daytime)
        fibaro:debug("test: "..test)
        fibaro:debug("sunset: "..sunset)
        fibaro:debug("curtainclose: ".. curtainclose)
        fibaro:debug("eveningred: "..eveningred)
        
        --Sunrise
        if (dawn >= curtainopen and currentTime < curtainopen and Dagdeel ~= "Dawn" ) then
          fibaro:setGlobal("Dagdeel", "Dawn")
          if debug then fibaro:debug("Dawn") end
       
        elseif ( curtainopen >= daytime and currentTime < daytime and Dagdeel ~= "CurtainOpen" ) then
          fibaro:setGlobal("Dagdeel", "CurtainOpen")
          if debug then fibaro:debug("CurtainOpen") end

       elseif ( daytime >= sunrise and currentTime < test and Dagdeel ~= "DayTime" ) then
          fibaro:setGlobal("Dagdeel", "DayTime")
          if debug then fibaro:debug("DayTime") end   
          
    elseif ( test >= daytime and currentTime < sunset and Dagdeel ~= "Test" ) then
          fibaro:setGlobal("Dagdeel", "Test")
         if debug then fibaro:debug("Test") end   
             
          
          --sunset  
        elseif ( curtainclose >= daytime and currentTime < sunset and Dagdeel ~= "CurtainClose" ) then
          fibaro:setGlobal("Dagdeel", "CurtainClose");
          if debug then fibaro:debug("CurtainClose"); end
        
        elseif ( eveningred >= sunset and currentTime > sunset and Sanco3 ~= "EveningRed" ) then
          fibaro:setGlobal("Dagdeel", "EveningRed");
          if debug then fibaro:debug("EveningRed"); end
        end
        fibaro:sleep(60*1000);
      end
    else
      fibaro:debug("Script can only be run via autostart")
    end

    • 0
  • Inquirer
  • Posted

    and at the end of the debug he write test without any time?

    • 0
  • Inquirer
  • Posted

    hehe found it evening red was not correct. Lets see if the curtains stays open today,ahahaha

    Thanks

    • 0
  • Inquirer
  • Posted

    shoot me it is changing every minute! Test or curtainclose

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...