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)

Hi @Sjakie,

in your script you are defining TimeOfDay representing value of global variable TijdStip, but you are not testing on TimeOfDay, but on TijdStip.

I hope this helps....

Edited by Bodyart
  • 0
  • Inquirer
  • Posted

    Bodyart@, Thanks for the tip.

    I corrected it but it still gives me Script can only run "Autostart" while other scene shows in debug the present GV.

     

    • 0
    Posted

    Hi @Sjakie ,

     

    try this code:

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    Hi @Sankotronic, thank you very much!

    It is almost working, it will stay on "Ochtendgloren"

    I thought for you to better understand I will translate and I added one extra line to test if it is working.

    Regretfully  it is doing something it is changing between Dawn and DayTime, please can you look into it?

    Thanks in advance and sorry to bother you

     

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

    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 Sanco3         = fibaro:getGlobal("Sanco3")
        local currentTime   = os.date("%H:%M")
        local dawn          = os.date("%H:%M", os.time()+50*60)
        local curtainopen = os.date("%H:%M", os.time()+15*60)
        local sunrise       = fibaro:getValue(1, "sunriseHour")
        local daytime       = os.date("%H:%M", os.time()+1*60)
        local sunset        = fibaro:getValue(1, "sunsetHour")
        local curtainclose = os.date("%H:%M", os.time()-50*60)
        local eveningred     = os.date("%H:%M", os.time()-50*60)
        --Sunrise
        if (dawn >= sunrise and currentTime < curtainopen and Sanco3 ~= "Dawn" ) then
          fibaro:setGlobal("Sanco3", "Dawn")
          if debug then fibaro:debug("Dawn") end
       
        elseif ( curtainopen >= sunrise and currentTime < sunrise and Sanco3 ~= "CurtainOpen" ) then
          fibaro:setGlobal("Sanco3", "CurtainOpen")
          if debug then fibaro:debug("CurtainOpen") end

       elseif ( daytime >= sunrise and currentTime < sunset and Sanco3 ~= "DayTime" ) then
          fibaro:setGlobal("Sanco3", "DayTime")
          if debug then fibaro:debug("DayTime") end   
          
          
          
          --sunset  
        elseif ( curtainclose >= sunset and currentTime > sunset and Sanco3 ~= "CurtainClose" ) then
          fibaro:setGlobal("Sanco3", "CurtainClose");
          if debug then fibaro:debug("CurtainClose"); end
        elseif ( eveningred >= sunset and currentTime > sunset and Sanco3 ~= "EveningRed" ) then
          fibaro:setGlobal("Sanco3", "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

    Please login or register to see this attachment.

    • 0
    Posted

    Hi @Sjakie,

     

    your script works perfectly on my HC2 :-D

    image.png.5c3932215631bef1bd0333c6daf2e90f.png

     

    Dit you define the global variable with filled in values?

    image.png.0d38f2ad6202cc5b4695c74a7f7d124e.png

    • 0
  • Inquirer
  • Posted

    Hi, see what you get as second line in debug.

    • 0
    Posted (edited)

    I've added some debug lines:

    Please login or register to see this image.

    /monthly_2019_04/image.png.f4953bb21ce27737238342c85f3256e2.png" />

    those values don't look right to me except sunrise & sunset

     

    Edited by Bodyart
    • 0
  • Inquirer
  • Posted

    yep thats why he is changing GV what is not expected and I do not have a clue what is wrong.

    what did you add?

    • 0
    Posted

    This:

    Please login or register to see this attachment.

    • 0
  • Inquirer
  • Posted

    the time behind the debug include the difference between the actions only the begin time is wrong?

    • 0
    Posted

    I think your definition of ochtendgloren should depend in sunrise and avondrood on sunset, doesn't it?

    • 0
  • Inquirer
  • Posted

    yes it is

    • 0
    Posted

    is it???

    then why it shows such weird time?? see debug above 16:41 !

    • 0
  • Inquirer
  • Posted

    hi use this one its in English

     

     

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

    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 Sanco3         = fibaro:getGlobal("Sanco3")
        local currentTime   = os.date("%H:%M")
        local dawn          = os.date("%H:%M", os.time()+50*60)
        local curtainopen = os.date("%H:%M", os.time()+15*60)
        local sunrise       = fibaro:getValue(1, "sunriseHour")
        local daytime       = os.date("%H:%M", os.time()+1*60)
        local sunset        = fibaro:getValue(1, "sunsetHour")
        local curtainclose = os.date("%H:%M", os.time()-50*60)
        local eveningred     = os.date("%H:%M", os.time()-50*60)
        
    fibaro:debug("sunrise: ".. sunrise)
      fibaro:debug("sunset: "..sunset)
        fibaro:debug("Sanco3: ".. Sanco3)
          fibaro:debug("dawn: "..dawn)
        fibaro:debug("curtainopen: ".. curtainopen)
      fibaro:debug("daytime: "..daytime)
        fibaro:debug("curtainclose: ".. curtainclose)
          fibaro:debug("eveningred: "..eveningred)
        
        --Sunrise
        if (dawn >= sunrise and currentTime < curtainopen and Sanco3 ~= "Dawn" ) then
          fibaro:setGlobal("Sanco3", "Dawn")
          if debug then fibaro:debug("Dawn") end
       
        elseif ( curtainopen >= sunrise and currentTime < sunrise and Sanco3 ~= "CurtainOpen" ) then
          fibaro:setGlobal("Sanco3", "CurtainOpen")
          if debug then fibaro:debug("CurtainOpen") end

       elseif ( daytime >= sunrise and currentTime < sunset and Sanco3 ~= "DayTime" ) then
          fibaro:setGlobal("Sanco3", "DayTime")
          if debug then fibaro:debug("DayTime") end   
          
          
          
          --sunset  
        elseif ( curtainclose >= sunset and currentTime > sunset and Sanco3 ~= "CurtainClose" ) then
          fibaro:setGlobal("Sanco3", "CurtainClose");
          if debug then fibaro:debug("CurtainClose"); end
        elseif ( eveningred >= sunset and currentTime > sunset and Sanco3 ~= "EveningRed" ) then
          fibaro:setGlobal("Sanco3", "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

    the debug order is always starting with sunrise and sunset

     

    This scene is changing between daytime and dawn.

    First I thought if there is a typo or something wrong he will show the firts value in GV >>>false

    • 0
  • Inquirer
  • Posted

    Why he skips "curtainOpen" is wierd

    • 0
  • Inquirer
  • Posted

    I think line 35 should be":

      if (dawn >= curtainopen and currentTime < curtainopen and Sanco3 ~= "Dawn" ) then

     

    no luck either

    • 0
    Posted (edited)
    27 minutes ago, Sjakie said:

    local curtainopen = os.date("%H:%M", os.time()+15*60)

    your definitions are wrong

    Please login or register to see this image.

    /monthly_2019_04/image.png.6cf91b00e3daee578bb9a89b03299dec.png" />

    You don't want to open the curtains @ 17:01, nor close them @ 15:56!

     

    Please login or register to see this code.

    if (17:36 >= 06:52 and 16:47 < 17:01 DayTime ~= Dawn) then

     

    IT IS ALWAYS "Dawn"

    Edited by Bodyart
    • 0
  • Inquirer
  • Posted

    os.date("%H:%M", os.time()+15*60)

    is 15 minutes before sunrise

    • 0
    Posted (edited)
    3 minutes ago, Sjakie said:

    os.date("%H:%M", os.time()+15*60)

    is 15 minutes before sunrise

    nope. it has nothing to do with sunrise

    You need to convert the string sunrise to time format and then add your desired difference.

    Edited by Bodyart
    • 0
  • Inquirer
  • Posted

    perhaps you are right If I change in "fixed"times it looks better( I hope)

    now I am lost

     

    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...