We have moved at community.getvera.com

Author Topic: VERY slow dim LUUP code  (Read 12770 times)

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
VERY slow dim LUUP code
« on: October 20, 2009, 10:30:09 pm »
Greetings,

Thanks to huwu, I've built the following code to slowly dim my outdoor lights.  An event that is triggered at sunset will turn my dimmable device 28 to 20% and stay there for 300 seconds.  Then it sets the light on to 80%.  Every 60 seconds it reduces the dim level by 1% until it reaches the Min level of 20%.  I have a 2nd event at 11pm to turn the light off.

Its my first easy and useful?? test of using the call_timer function, and putting code within a scene.  I hope someone finds it useful.



local brsDelayPeriod = 60
local brsFirstDelayPeriod = 300
local brsMax = 80
local brsMin = 20
local brsDevice = 28

local brsDimLevel = brsMax
luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget=brsMin },brsDevice)
luup.call_timer("LightFirstOn", 1 , brsFirstDelayPeriod,"","")

function LightOn()
   luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget=brsDimLevel },brsDevice)
   brsDimLevel = brsDimLevel - 1
   if (brsDimLevel >= brsMin) then
      luup.call_timer("LightOn", 1 , brsDelayPeriod,"","")
   end
end

function LightFirstOn()
   luup.call_timer("LightOn", 1 , brsDelayPeriod,"","")
end
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline mpenda

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-0
Re: VERY slow dim LUUP code
« Reply #1 on: January 17, 2010, 06:34:42 pm »
While this is very long after your post, thanks brsipaq for putting this up in the forum.
It came in very handy for me!!!
v1.0.980, HA09C, HA07C, WDTC-20, HRDS1, BLC131A, SM103, ZIR000, HA-18WD, ZRW103, HA02C, HA03C

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Re: VERY slow dim LUUP code
« Reply #2 on: January 18, 2010, 11:11:46 am »
Excellent!  What was your scenario that you used it for?

Thanks,
Brian
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #3 on: January 18, 2010, 09:08:48 pm »
Where would you paste this code?

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #4 on: January 19, 2010, 12:20:37 pm »
Well I went to Scenes, Went down to the device name, clicked on Luup Scene and pasted the code above into the box. Then Saved. I'll see tonight if this works.

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #5 on: January 19, 2010, 12:23:51 pm »
So I don't see any event in the Luup code based on sunset. Is this correct? So I'm going to try setting the sunset based on a timed event using the Add Timer button which is right above the Luup scene button mentioned above. We'll see what happens.

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Re: VERY slow dim LUUP code
« Reply #6 on: January 19, 2010, 02:30:36 pm »
aharding,
I have a scene called "Front Outdoor Light On" and has a timer within it that triggers 10 minutes after sunset.

In the same scene, I put the code into the "LUUP Scene"

So the LUUP code is run 10 minutes after sunset.

Since this is just a scene, you can run it at any time to test it.

I then have a totally separate scene that turns the light off at 23:00.

Thanks,
Brian
« Last Edit: January 19, 2010, 02:34:41 pm by brsipaq »
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #7 on: January 19, 2010, 11:31:37 pm »
Hi Brian,

I tried the code but it does not turn on my light. I had it set to hidden but unchecked it and then went and clicked on go to activate the scene. My light is #27 instead of #28 when I checked my node ID. So I changed that.

Alfred--

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #8 on: January 20, 2010, 12:07:05 am »
Never mind, I was using the NodeID (Z-Wave assigned) and not the Device # (Vera assigned). Luup uses the Device # apparently.

Offline aharding

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #9 on: January 26, 2010, 01:11:26 am »
Ok, how would you do this in reverse for morning wakeup? Start at 3%, then increase light level by 3% per minute until at 52% for example.

Then, if the off switch is pressed, work it like a snooze alarm. So after 10 minutes, turn the light back on and start the cycle again but start at 6%, and increase light level by 6% per minute until the light is at 72%.

Option to allow one or two additional snoozes, and then if you press the off button, the light turns back on to the previous light level immediately.

After one hour, allow the light to be turned off.

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Re: VERY slow dim LUUP code
« Reply #10 on: January 26, 2010, 12:31:45 pm »
aharding,

My wife would never go for that... but with that said, if I had to do this, I would:
1. Modify the code so it counts up instead of down.  Make sure that works.  I would start more in the 10-15% range instead of 3.
2. Modify the code to 'test' the current light value against the 'supposed to' be value (variable brsDimLevel).
3. If they are different (something else changed the light), have another 'call_timer' routine to just delay for 10 minutes.
4. After which you can proceed with your march upwards.
5. You'd probably need another variable that would hold the amount of times you would allow this to happen.  Modify the code to test against this condition.
6. If you use this approach, I don't think you could 'immediately' turn the light back on if the user violated the number of times to snooze.  I think you'd have to look into creating a LUUP Device and have all your code in there.  But I haven't built devices as yet.  Or you could create a scene/event for every time the light value changes and compare it against a virtual device which would indicate whether to snap the light back on or not.  But even this creates problems since I don't know how to share the variable that would indicate what the dim level should be.  Maybe someone knows how to implement global variables.


Hope this helps.
Brian
« Last Edit: January 26, 2010, 12:38:25 pm by brsipaq »
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline rayp

  • Jr. Member
  • **
  • Posts: 63
  • Karma: +3/-0
Re: VERY slow dim LUUP code
« Reply #11 on: August 01, 2014, 08:17:55 am »
This works perfect for dimming the lights in my livingroom to give the effects of movie lights dimming slowly as the movie starts using a scene button. Now if I could figure out how to have the scene triggered when my networked blueray players starts a movie, that would be sweet!
I know this post is old, but felt it worth responding to the orginal author.

Offline akilo

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #12 on: August 12, 2014, 02:54:10 am »
Hi rayp: I was thinking maybe you could use power metering? For example if your bluray player's power consumption > 20W, then trigger the movie scene.
You have to connect the bluray player to Fibaro wall plug for example (to get power usage data)

Offline naveen

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Re: VERY slow dim LUUP code
« Reply #13 on: October 01, 2014, 10:07:27 pm »
This code blocks right? E.g. it will continue to run until the light is off, regardless of any other triggers. Is there a way to set it to stop dimming if Vera changes the light to something else?

Edit: I suppose i could just add a line to check if the loadlevelstatus matches the previously set status, that is easy enough i guess.
« Last Edit: October 01, 2014, 10:10:12 pm by naveen »

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: VERY slow dim LUUP code
« Reply #14 on: October 02, 2014, 06:33:12 am »

Edit: I suppose i could just add a line to check if the loadlevelstatus matches the previously set status,

Yes, do that. This is how the WakeupRamp plugin does it, which your code is asymptotically approaching.