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

run function and bring back array do better?


Question

Posted

i have a function wI which computes sun angles, i have an array called sunposition where i am storing the sun angles i want to compute. i would like to get back 6 values, which are the six values in the sunposition array, i am unsure how to set up the results part of this please?

 

sunPosition = { 

{-0.833, "sunrise", "sunset"},

    {-0.3, "sunriseEnd", "sunsetStart"},

{-8, "blueHourDawn", "blueHourDuskEnd"}

    }

 

function QuickApp:GetTimes()

    local tb = {}

    for k,v in pairs(sunPosition) do tb[#tb+1]={name=k,angle=v} end

    table.sort(tb,function(a,b) return a.angle > b.angle end)

    for _,a in ipairs(tb) do

        R = a.angle

        --print(R)

        hour = "12"

        minute = "00"

        local returnTime

        if R == -8 then

            returnTime = wI(T,"U")

            print("Shabbos Out Time",returnTime)

            if fibaro.getGlobalVariable("shabbosEndTime")   ~= returnTime then

                print("Updating Variable "..returnTime)

                fibaro.setGlobalVariable("shabbosEndTime", returnTime)

                self:updateProperty("log", returnTime.." "..os.date("%x %H:%M:%S"))

            end

            --self:updateView("lblShabbosOut", "text", "Shabbos Goes Out At "..returnTime)

        elseif R == -0.8333 then

        --shabbosStartTime

            returnTime = sec2str(str2sec(wI(T,"D"))-(15*60))

            print("Shabbos In Time",returnTime)

            if fibaro.getGlobalVariable("shabbosStartTime") ~= returnTime then

                print("Updating Variable "..returnTime)

                fibaro.setGlobalVariable("shabbosStartTime", returnTime)

            end

            --self:updateView("lblShabbosIn", "text", "Shabbos Comes In At "..returnTime)

        end

    end

    --self:updateView("lblShabbosIn","visible",false)

    --self:updateView("lblShabbosOut", "text", "Shabbos Goes Out At "..fibaro.getGlobalVariable("shabbosEndTime"))

    self:UpdateLabelView()

end

7 answers to this question

Recommended Posts

  • 0
Posted

Please login or register to see this image.

/monthly_2022_01/image.png.ff6501edaca7df8801a290756e3ae4af.png" />

 

Please login or register to see this attachment.

  • Like 1
  • 0
  • Inquirer
  • Posted

    @10der i use this app for basic sun times however i have found that your 8 degrees below sun time is out by between 1 and 3 degrees depending on the season, i have therefore also written another way of calculating sun times which seems to be slightly more accurate, i am comparing your data with suncalc.org for a long time i was looking for who wrote this qa and in my copy it does not have any comment in the top of the file of the author and it would be good to maybe include it LOL. would be great to be able to fine tune the sun_calc and not to have to use another app for it.

    • 0
    Posted
    17 hours ago, Jay Ess said:

    who wrote this qa

    i am. what's a questions?

    • 0
    Posted

    >"shabbosEndTime

    btw. as i can understand you want know time of shalom shabbos :) 

    as i know (sorry my mom is jewish) we should do like this:

     

    (This time is calculated as the point at which the center of the sun’s disk is 1.583 degrees below the horizon.)

     

    Please login or register to see this link.

     

    Please login or register to see this attachment.

     

     

     

    Please login or register to see this attachment.

     

     

    Please login or register to see this code.

     

     

     

    • Like 1
    • 0
  • Inquirer
  • Posted (edited)

    @10der LOL i have been breaking my head on this code for month's different communities work on different times, here in the uk we work on 8 degrees below the horizan, using suncalc and getting the 8 degrees works exactly with times out, here is a link to the local times, is there an easy way to print / dump every week of the year in one go so that it is easier to check the time given please?

     

    calender link

    Please login or register to see this link.

     

    i have run this using your blueHourDuskEnd and it brings back 17:05, while suncalc brings back 17:06 and the calender brings back 17:07, they are using arounding which adds on a minute and possibly your code is rounding down?

    thank you for your help.

     

     

    Edited by Jay Ess
    • 0
    Posted (edited)
    24 minutes ago, Jay Ess said:

    @10der LOL i have been breaking my head on this code for month's different communities work on different times, here in the uk we work on 8 degrees below the horizan, using suncalc and getting the 8 degrees works exactly with times out, here is a link to the local times, is there an easy way to print / dump every week of the year in one go so that it is easier to check the time given please?

     

    calender link

    Please login or register to see this link.

     

    i have run this using your blueHourDuskEnd and it brings back 17:05, while suncalc brings back 17:06 and the calender brings back 17:07, they are using arounding which adds on a minute and possibly your code is rounding down?

    thank you for your help.

     

     

    please provide your location like

    -- Kyiv, Kyiv Capital City Area, Ukraine
    local lat = 50.450001
    local lon = 30.523333

     

    Toda raba,

    O.

     

    the uk

    got it

    Edited by 10der
    • 0
  • Inquirer
  • Posted (edited)

    Manchester UK

     

    Edited by Jay Ess

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