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

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Scene that will set a light level dependent on Time of Day
« on: September 17, 2011, 01:17:31 pm »
Hello All,
I've been searching for some examples of how to accomplish this.  I basically have a switch assigned to a scene that simply turns a light on.  I really want this Scene to set the brightness up or down dependent on the day (particularly around sunset)
So activating the scene after sunrise will turn brightness to 100%
Brightness 1 hour before Sunset will be 80%
Brightness at sunset will be 70%
1 hour after sunset will be 60%
etc...

There was another thread that Woodsby replied stating he was doing something very similar:
http://forum.micasaverde.com/index.php?topic=7384.msg47957#msg47957
But no response from him  :-\

If anyone can point me in the right direction or provide an example of how to accomplish this, it will make my investment a lot more enjoyable.

Thank you,


Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Scene that will set a light level dependent on Time of Day
« Reply #1 on: September 21, 2011, 05:20:58 am »
Maybe you can find this thread useful:
http://forum.mios.com/index.php?topic=2386.0

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #2 on: September 21, 2011, 10:12:57 am »
Not quite what i'm looking for, but I appreciate it, and that is one of the threads that inspired this request.

More specifically i'm looking to hit the "ON" button, and the light will be set to a certain dim % dependent on the time of day.

I actually found another thread with luup code to set it up based on "night" but that is only one variable, i'm looking for a 1 hour before sunset, and 1 hour after sunset, 2 hours after sunset etc...

So the Scene will be triggered by the device turning ON, and set dim level appropriately.

Thanks!

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 #3 on: September 21, 2011, 12:07:34 pm »
You could use Heliotrope (better adaption to the variable day length) or DAD.

The following code (untested, may contain typos/bugs) is based on DAD:
 
Code: [Select]
local DAD_device_id    =  11 -- adjust accordingly
local dimmer_device_id =  22 -- adjust accordingly

local sunset_timestamp = tonumber( luup.variable_get( 'urn:upnp-ap15e-com:serviceId:DAD1', 'Sunset', DAD_device_id ) or 0 )
 
local delta_h = ( sunset_timestamp - os.time() ) / 3600
 
local dim_level

if delta_h > 3 or delta_h < -7
 then
  if luup.is_night()
   then
    dim_level = 0
   else
    dim_level = 100
   end
 else
  dim_level = math.floor( ( delta_h + 7 ) * 10 + 0.5 )
 end
 
-- one never knows ...
 
dim_level = math.min( 100, dim_level )
dim_level = math.max(   0, dim_level )
 
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", { newLoadlevelTarget = dim_level }, dimmer_device_id )

Edit:
is_night() -> luup.is_night()
« Last Edit: September 27, 2011, 05:00:58 pm by Ap15e »

Offline oTi@

  • Master Member
  • *******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Scene that will set a light level dependent on Time of Day
« Reply #4 on: September 21, 2011, 12:46:13 pm »
More specifically i'm looking to hit the "ON" button, and the light will be set to a certain dim % dependent on the time of day.
What kind (model) switches are you looking to use? From your other post I get the impression it's regular light switches, not a scene controller, and you're looking to have Vera quickly adjust to the desired dim level after the light has come on?
Dezwaved at the moment...

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #5 on: September 23, 2011, 06:35:00 am »
I'm using the GE/Jasco Dimmers, and Vizia 4 button Zone Controllers.
Thank you for that code above, i'm not savvy enough to understand what some of those variables are, but I will paste it, and see what happens.  I also have tech support working on this as well so I will be sure to post their code as well. 
If anyone uses the code above in the meantime with success or makes changes / fixes to it, please post.

Ultimately once the right code and behavior is established it would be great to allow for ONE scene to be present and control all the dimmers in the house with this behavior instead of creating 40 scenes (1 for each dimmer)

Thank you!

Offline oTi@

  • Master Member
  • *******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Scene that will set a light level dependent on Time of Day
« Reply #6 on: September 23, 2011, 08:45:37 am »
I'm using the GE/Jasco Dimmers, and Vizia 4 button Zone Controllers.
OK; thanks.

The in-wall dimmers or the plug-in modules?
Are you looking to control the dimmers solely with the zone controllers, or would you also operate the dimmers with their local button?

In other words, I'm still not clear on what the event is that will trigger the scene you are describing. Is it switching the local dimmer (A device is turned on or off), a button on the zone controller (A scene is activated), possibly both?
« Last Edit: September 23, 2011, 08:47:51 am by oTi@ »
Dezwaved at the moment...

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #7 on: September 23, 2011, 11:47:38 am »
These are in-wall wired dimmers and controllers.

I want to turn on any light in my house with the local switch and have that particular light's brightness be determined by the hours around "sunset and sunrise" (the topic states "time" but really i'm looking for the solution based on light conditions outside)

So if it's a group of lights assigned to a Zone, Scene, or simply a single light, whatever light(s) we're turning on will only turn on to the brightness defined below:
Ideally these would be the rules;

DURING THE DAY (1 hour after sunrise, and 1 hour before sunset) brightness = 100%

1 Hour BEFORE sunset brightness = 80%
Within 10 minutes of sunset, brightness = 70%
1 hour AFTER sunset brightness = 60%
2 hours after sunset brightness = 40%
3 hours after sunset brightness = 20%

I dont want a timer that is set to dim in increments (I already use this for the patio lights).

Now that I'm thinking about this from a programming point, i'm wondering if there could be a script that globally goes through all interior dimmers (defined by device#?) and sets the brightness to these levels IF ALREADY ON, but ALSO be responsive enough to Catch a light that is currently off and being turned on by someone in the house to automatically set the level to the guidelines above.  (I say "responsive" enough" because it needs to catch the light at the time it's being turned on, not check it later then dim after 5 minutes or something).

Thanks!

Offline oTi@

  • Master Member
  • *******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Scene that will set a light level dependent on Time of Day
« Reply #8 on: September 23, 2011, 12:17:34 pm »
I want to turn on any light in my house with the local switch [...]it needs to catch the light at the time it's being turned on, not check it later then dim after 5 minutes or something.
The GE's don't support associations, i.e. they do not report back to Vera when switched on/off. But as far as I can tell MCV uses a workaround so you will see an 'instant' update in some cases. Probably only when the switch is close enough to Vera. And only when switched on the primary switch (not the auxiliary ones, in case of multi-way setups).

I guess ideally, you'd want to be able to preset the dim-level on each dimmer based on your requirements, without turning the load on; but I'm not aware of a way to do that.
Dezwaved at the moment...

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #9 on: September 23, 2011, 01:51:59 pm »
It doesnt need to make the level a preset.  There is a luup code in another thread I used that check if_night and sets the max brightness to 40% and that works flawlessly with the event "a light is switched on".  There appears to be no delay.
The problem is that only allows 1 setting, and I need to create that scene for EVERY dimmer.

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #10 on: September 26, 2011, 07:58:13 am »
@Ap15e


I've been trying to get your code above to work with no such luck. 


Nothing happens, i've pasted it in a LUA code checker and get this:
input:4: attempt to index global 'luup' (a nil value)

No errors coming from the Vera however so i'm not sure if it's because i'm testing at 7:55am which is 20 minutes AFTER sunset accorded to DAD.
I have it setup as a Scene with the event (the subject device is turned on)


If this works as needed, that would be great, the next step would be to have this 1 scene allow for multiple devices, but ONLY manipulate the respective device, not 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 #11 on: September 26, 2011, 04:48:26 pm »
Copy the code into the 'MiOS developers' -> 'Test Luup code (Lua)' window, adjust the device ids and click 'Go'. If it's working from there, something is wrong with your scene setup or your devices do not report back to Vera when switched on/off.
« Last Edit: September 26, 2011, 04:51:14 pm by Ap15e »

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #12 on: September 27, 2011, 06:01:11 am »
@Ap15e,
It says code failed.

Im testing on the ge dimmer.  Can you give it a shot?

Thanks,

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 #13 on: September 27, 2011, 04:59:50 pm »
Code updated, please try again.

Offline big517

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 576
  • Karma: +1/-4
Re: Scene that will set a light level dependent on Time of Day
« Reply #14 on: September 27, 2011, 11:10:21 pm »
Code updated, please try again.

Code failed again  :(