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

QA does not loop


Jay Ess

Question

Hi

USING HC3.

I have a QA to fetch times of sunset and other calender related functions.

I have it on a 1 minute loop which works.

 

My issue is I have a function called GetTimes() saved in a sub sheet in the QA, if i add a line like this in the QA it runs once and then does not loop it self again with no debug errors visible.

What I can't figure out is I run the exact line of code elsewhere in the QA without getting any issues.

local hNewDay = GetTimes(currentTimeSec,sunDegree)

 

Could anyone shed some light on to how to find out what is going wrong and on how to fix this?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
1 hour ago, Jay Ess said:

Hi

USING HC3.

I have a QA to fetch times of sunset and other calender related functions.

I have it on a 1 minute loop which works.

 

My issue is I have a function called GetTimes() saved in a sub sheet in the QA, if i add a line like this in the QA it runs once and then does not loop it self again with no debug errors visible.

What I can't figure out is I run the exact line of code elsewhere in the QA without getting any issues.

local hNewDay = GetTimes(currentTimeSec,sunDegree)

 

Could anyone shed some light on to how to find out what is going wrong and on how to fix this?

 

Sorry, can you provide some example code - I can't really understand.

What do you mean with QA doesn't loop?

If you run a loop with setTimeout/setInterval, then you should wrap the function in a pcall so you can trap and print the error.

Edited by jgab
Link to comment
Share on other sites

  • 0
  • Inquirer
  • what do you mean by pcal? will send snippet of the code

    function GetTimes(gDate,gAngle)

        local currentDate = os.date("*t")

        local year = tonumber(os.date("%Y",gDate))

        local month = tonumber(os.date("%m",gDate))

        local day = tonumber(os.date("%d",gDate))

        local hour = tonumber(os.date("%H",gDate))

        local minute = tonumber(os.date("%M",gDate)) 

        local weekday = tonumber(os.date("%w",gDate))

        T = getT(year,month,day,hour,minute)

        local GMT = 0

        if currentDate.isdst then

            if (weekday==5 or weekday==6) and month==10 and day>=24 then

                GMT = GMT

            else 

                GMT = GMT + 1

            end

        else

            if (weekday==5 or weekday==6) and month==3 and day>=24 then

                GMT = GMT + 1

            end

        end

        R = gAngle

        hour = "12"

        minute = "00"

        local returnTime

        if R == -8 then

            returnTime = wI(T,"U",year,month,day,GMT)

        elseif R == -0.8333 then

            returnTime = sec2str(str2sec(wI(T,"D",year,month,day,GMT))-(15*60))

        end

        return returnTime

    end

     

    this function retruns me sun times.

     

     

    this is my loop

    function QuickApp:loop()

        self:setHebrewDate()

        setInterval(

            function()

                self:setHebrewDate()

            end,

            1000 * 60 *1

        )

    end

     

     

    this is a nother funtion which gets called on the loop

    function QuickApp:setHebrewDate()

        local currentTime = os.date("%H:%M")

        local HebrewDayStart = (fibaro.getGlobalVariable("Sunset")) 

     

     

    if i change the last line to HebrewDayStart = GetTimes(os.time(),-0.8333)

    i get the time of 20.16 which is corect but then the qa does not run again

    Link to comment
    Share on other sites

    • 0
    7 hours ago, Jay Ess said:

    Hi

    USING HC3.

    I have a QA to fetch times of sunset and other calender related functions.

    I have it on a 1 minute loop which works.

     

    My issue is I have a function called GetTimes() saved in a sub sheet in the QA, if i add a line like this in the QA it runs once and then does not loop it self again with no debug errors visible.

    What I can't figure out is I run the exact line of code elsewhere in the QA without getting any issues.

    local hNewDay = GetTimes(currentTimeSec,sunDegree)

     

    Could anyone shed some light on to how to find out what is going wrong and on how to fix this?

    Yes, known issue that in some cases HC3 doesn't show the error and just restarts the QA....

    As I can see you haven't posted the entire QA code, so you need to find the error by your self....

    Another question - why you don't use built-in sunset value?

    Edited by cag014
    Link to comment
    Share on other sites

    • 0

    Do

    Please login or register to see this code.

     

    If getT() that we don't see call http:request you need to wrap the success/error handler in pcall also.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @jgab thank you for that will implement it

    @cag014 yes found the error by putting a print line on each variable, took some time but found my error, one function needed 3 varibales and i was passing it 2 so the second variable which should be a number was a string and hence the crash although i dont understand why it ran some times, need to re-look at the code on a rainy day. I dont use the built in sunset times as need work out sunset with a higher degree of accuracy then the hc3 seems to be, need to be exact on the minute and control the roundup and round down, hence why needed my own sunrise and sunset time calculater.

     

    Thanks guys for you help now working as expected.

    function QuickApp:loop2Minute()

        local cLTime = os.date("%H:%M")

        local sec = os.date("%S")

        if sec == "00" then

            self:loop()

        else

            print("Seconds:",sec)

            fibaro.setTimeout(1000, function() self:loop2Minute() end)

        end

    end 

    am running this loop on startup but i find that the qa seems to drift off the 00 second mark, how can i keep it to run on 00 seconds all the time and if it drifts off then to adjust back?

    Link to comment
    Share on other sites

    • 0

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

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