Jump to content
  • 0

display sunset time


Question

Hi all,

I would like to display a debug message with the time of sunset + an x amount of minutes. So there needs to be a calculation.

I have a few scenes whose start is dependent of the month, turning lights on earlier or later.

My debug message should be something like "today lights will be on at 21:15". That 21:15 is the calculated time.

I have these declarations at the start of scenes:

local sunsettime    = fibaro:getGlobalValue("SunsetTime");
local sunsetHour   = fibaro:getValue(1,'sunsetHour')

But I can't figure out how to do this. Shouldn't be very complicated, but i'm not good in LUA programming with time.

Hope someone can help me out.

Link to post
Share on other sites
  • Answers 53
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

@theuksbest now some magic. find in your HC3 device with Humidity (for example) ok found! change a new icon uploading nice icon for sunset done. do not change device.

Sun_calc.fqa    

10der is king If the HC3 was the old fw (5.031), I couldn't change the icon for the "com.fibaro.deviceController" device (QA). After upgrading to fw 5.040, this tweak can be used. Thanks.

Posted Images

Recommended Posts

  • 1
10 hours ago, 10der said:

@ErnstH OK! Sir! trying to help you!

 

function sec2hmStr(hms)
    local h, m, s = math.floor(hms / 3600), math.floor((hms % 3600) / 60), hms % 60
    return string.format("%02d:%02d:%02d", h, m, s)
end

function hm2sec(hmstr, margin)
    local h, m, s = hmstr:match("(%d+):(%d+):?(%d*)")
    return h * 3600 + m * 60 + (tonumber(s) or 0) + (tonumber(margin) or 0)
end

local margin = 45 * 60 -- amount of seconds before sunset/after sunrise

local sunset = fibaro.getValue(1, "sunsetHour")
local sunrise = fibaro.getValue(1, "sunriseHour")

print(sunset, sunrise)
print(sec2hmStr(hm2sec(sunset, -margin)), sec2hmStr(hm2sec(sunrise, margin)))

image.png.5b628d0fb9fbb7e8831e937a243b13f9.png

is the what you asking?

 

 

Hi 10der,

Looks good though quite complicated. But I understand it.

I pasted it into my script and it returns an error, that hmstr seems to be undefined yet:

[DEBUG] 20:46:20: nil nil
[DEBUG] 20:46:20: 2020-08-11 20:46:20.915000 [ fatal] Unknown exception: /opt/fibaro/scenes/5.lua:47: attempt to index local 'hmstr' (a nil value). Shouldn't that as well as margin be defined before the function?

Nearly there I guess...

Link to post
Share on other sites
  • 0

Have you tried creating a block scene that activates say 10 mins after sunset (there is a standard block for this), and then converting that scene to LUA?

Link to post
Share on other sites
  • 0

Hope this VD can help you better understand the LUA code for what you want. 

 

I've found this VD a while ago but I don't know the creator, all the credits are for him or her 😉

Zon.vfib

Link to post
Share on other sites
  • 0
7 hours ago, Tim__ said:

creating a block scene

That is not the problem.

I do have such a code: if os.date("%H:%M", os.time()+tonumber(BeforeSunset)*60) == sunsetHour   This works fine.

But I want it the other way around: with a print of debug command I want to display the time lamps go on today.

Thanks for trying to help.

Link to post
Share on other sites
  • 0
7 hours ago, kevin said:

Hope this VD can help you better understand the LUA code for what you want. 

 

I've found this VD a while ago but I don't know the creator, all the credits are for him or her 😉

Zon.vfib 1.29 kB · 1 download

Thanks for the suggestion. I looked into that. Not just what I'm looking for, it is code I already have. Just displaying sunset time.

Not with a calculation.

I think I need something like os.date("%H:%M", os.time() = sunsetHour - tonumber(BeforeSunset)*60). But I need a better syntax.

5 hours ago, 10der said:

maybe, but how do I open or import this type of file?

Link to post
Share on other sites
  • 0

@10der - that looks good, i could benefit from something like that

Quote
17 hours ago, 10der said:

Sun_calc.fqa 12.11 kB · 8 downloads

 

 

Does it work on HC3, is this a QuickApp?

 

I tried adding the file but it just adds as a generic device with no code by the looks of it (com.fibaro.genericDevice)

Link to post
Share on other sites
  • 0
4 minutes ago, theuksbest said:

@10der - that looks good, i could benefit from something like that

 

Does it work on HC3, is this a QuickApp?

 

I tried adding the file but it just adds as a generic device with no code by the looks of it (com.fibaro.genericDevice)

maybe cuz you have old HC3 fw?

@theuksbest image.thumb.png.865373818f3c32574351b5cbabd4befa.png

Link to post
Share on other sites
  • 0

@10der 

1828987670_Screenshot2020-08-10at09_19_55.png.87e53005203331668e048df95f9db3d2.png

 

still learning here: i don't see any new ones added, should i add something here?

 

I have my Day/Night ones which i use in my scenes currently:

1260472727_Screenshot2020-08-10at09_22_39.thumb.png.54b0517021294ccfd38ad3ce183c957a.png

 

 

@ErnstH - sorry and thank for letting me hijack your thread for a bit! :)

Link to post
Share on other sites
  • 0

@theuksbest hust create 

DayPart

like

image.png.e85c035e0973782cac53c786b4b87091.png

 

after 1 min variable should re-filled

than you can use this var with more details sun events

 

    "nauticalDawn"-- 1
    "blueHourDawn"-- 2
    "dawn"-- 3
    "blueHourDawnEnd"-- 4
    "sunrise"-- 5
    "sunriseEnd"-- 6
    "goldenHourEnd"-- 7
    "solarNoon"-- 8
    "goldenHour"-- 9
    "sunsetStart"-- 10
    "sunset"-- 11
    "blueHourDusk"-- 12
    "dusk"-- 13
    "blueHourDuskEnd"-- 14
    "nauticalDusk"-- 15
    "night"-- 16
    "nadir"-- 17
    "nightEnd" -- 18
 
Link to post
Share on other sites
  • 0
11 hours ago, theuksbest said:

for letting me hijack your thread

That's okay, that's what forums should do sometimes. 🤪

Meanwhile, my question remains unresolved.

Link to post
Share on other sites
  • 0

@ErnstH OK! Sir! trying to help you!

 

function sec2hmStr(hms)
    local h, m, s = math.floor(hms / 3600), math.floor((hms % 3600) / 60), hms % 60
    return string.format("%02d:%02d:%02d", h, m, s)
end

function hm2sec(hmstr, margin)
    local h, m, s = hmstr:match("(%d+):(%d+):?(%d*)")
    return h * 3600 + m * 60 + (tonumber(s) or 0) + (tonumber(margin) or 0)
end

local margin = 45 * 60 -- amount of seconds before sunset/after sunrise

local sunset = fibaro:getValue(1, "sunsetHour")
local sunrise = fibaro:getValue(1, "sunriseHour")

print(sunset, sunrise)
print(sec2hmStr(hm2sec(sunset, -margin)), sec2hmStr(hm2sec(sunrise, margin)))

image.png.5b628d0fb9fbb7e8831e937a243b13f9.png

is the what you asking?

 

 

Edited by 10der
Link to post
Share on other sites
  • 0

@theuksbest now some magic.

find in your HC3 device with Humidity (for example)

ok found!

change a new icon

uploading nice icon for sunset

done.

do not change device.

just check what a new icon uploaded.

the next step - find icon id

image.thumb.png.93d51e82e678f480f71fac7761f1e1d4.png

 

[M[ - 1040

 

open your QA.

find self:updateProperty("deviceIcon",  and finallu change to 1040

 

self:updateProperty("deviceIcon", 1040)

 

 

  • Like 2
Link to post
Share on other sites
  • 0

10der is king :)
If the HC3 was the old fw (5.031), I couldn't change the icon for the "com.fibaro.deviceController" device (QA).
After upgrading to fw 5.040, this tweak can be used.
Thanks.

  • Thanks 1
Link to post
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...