Author Topic: Scene that will set a light level dependent on Time of Day  (Read 7269 times)

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene that will set a light level dependent on Time of Day
« Reply #15 on: September 28, 2011, 06:09:22 am »
The script works for me. I'm clueless ... You should check the LuaUPnP logfile for errors.

Offline big517

  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #16 on: September 28, 2011, 07:07:25 am »
Ok, so It must have been some copy past issues (i was doing it from an ipad  >:()
So i'm testing right now, it's 6:50am.  Definately "night".  And running this code sets my dimmer to 0.  I was hoping since it's night it would set it to "15%" so I changed the code to dim_level = 15 after your if/else statement.

I'm trying to wrap my head around what numbers are being created for the sunset_timestamp and os.time, i'm assuming something like 1934 for sunset (7:34pm).  is that a correct assumption?

Thanks!

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3256
  • Karma: +191/-9
Re: Scene that will set a light level dependent on Time of Day
« Reply #17 on: September 28, 2011, 07:42:42 am »
I'm trying to wrap my head around what numbers are being created for the sunset_timestamp and os.time, i'm assuming something like 1934 for sunset (7:34pm).  is that a correct assumption?

The numbers that are in the region of 1.3 billion are Unix epoch time.  That Wikipedia page links to a ton of online converters.

Offline big517

  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #18 on: September 28, 2011, 07:50:36 am »
Perhaps I just need to test this in the evening, but I was hoping this would also work in the morning so if it's just after sunset the level is set to 30%, and 30 minutes after sunset its set to 40% or something relative like that...  Thats why I was asking about the math involved.
Heading to work, thanks all!

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene that will set a light level dependent on Time of Day
« Reply #19 on: September 28, 2011, 09:55:45 am »
Please find attached a visualization of the dimming level for sunrise at 9:00 and sunset at 16:00. It should match your requirements outlined at http://forum.micasaverde.com/index.php?topic=7860.msg50295#msg50295.
« Last Edit: September 28, 2011, 09:57:23 am by Ap15e »

Offline big517

  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #20 on: September 28, 2011, 03:53:09 pm »
Please find attached a visualization of the dimming level for sunrise at 9:00 and sunset at 16:00. It should match your requirements outlined at http://forum.micasaverde.com/index.php?topic=7860.msg50295#msg50295.

@Ap15e,
You are an asset to this board, thank you.  Does this use sunset as a dynamic time pulled from DAD so it's always using the true "sunset" time?

Can this be reversed to ramp up during sunrise?

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3256
  • Karma: +191/-9
Re: Scene that will set a light level dependent on Time of Day
« Reply #21 on: September 28, 2011, 06:15:33 pm »
[...] if it's just after sunset the level is set to 30%, and 30 minutes after sunset its set to 40% or something relative like that...

Unix epoch times are essentially a count of seconds, so if you take two of them (now and sunset, say), and difference them, you can divide it by 60 to get a number of minutes.

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene that will set a light level dependent on Time of Day
« Reply #22 on: September 29, 2011, 12:49:59 pm »
Quote
Does this use sunset as a dynamic time pulled from DAD so it's always using the true "sunset" time?

Exactly.

Quote
Can this be reversed to ramp up during sunrise?

Anything that can be expressed in Lua code is possible.