Author Topic: Scene with dimming increment  (Read 719 times)

Offline kartcon

  • Jr. Member
  • **
  • Posts: 75
  • Karma: +2/-0
Re: Scene with dimming increment
« Reply #15 on: September 13, 2017, 07:23:51 pm »
P-a, Sorry for the late response but we were offline for several days due to Irma. Here is some code we use in our parrot rooms to slowly dim the lights from 30 minutes before sunset through 9pm (their bedtime). You can modify the code for any time interval you need, but the core requirements are there. In addition, we wanted to be able to lower or raise the light level in the midst of the code and have the dim ramp use the current level and continue on. One last note - I placed this code in a PLEG action so that it can recover from a Lua restart and continue. I originally had it as a scene but that was an issue because a lot of my coding work occurred while that particular scene was active, resulting in lights frozen at a particular level and no way to 'restart' the scene. Please feel free to strip out the SceneWatch code as this is a custom variable that I use to indicate the status of the code as it progresses and for troubleshooting. I left it in place so you could see how things worked.

Code: [Select]
luup.log("PL_Act: c_BirdRm_Lights_Dim")
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable1"," ",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable2"," ",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable3"," ",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable4"," ",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable5"," ",50)
varDevice1 = 52
varDevice2 = 53
varMax = 70
varMin = 10
varDimStep = (varMax-varMin)/10
varDimLevel1 = varMax
varDimLevel2 = varMax

varLupSS = luup.sunset()
varLuaSST = os.date("*t", varLupSS)
varSunsetTime = varLuaSST.hour * 60 + varLuaSST.min
varSSTHr = math.floor(varSunsetTime/60)
varSSTMin = varSunsetTime-(varSSTHr*60)
varSST = varSSTHr .. ":" .. varSSTMin
varSSoffset = 30

varStartTime = varSunsetTime - varSSoffset
varSTHr = math.floor(varStartTime/60)
varSTMin = varStartTime-(varSTHr*60)
varST = varSTHr .. ":" .. varSTMin

varEndTime = "21:00"
varETHr = tonumber( varEndTime:sub( varEndTime:find("%d+") ) )
varETMin = tonumber(varEndTime:sub(-2))
if varETHr and varETMin then
varEndTime = varETHr * 60 + varETMin
else
luup.log("ERROR: invalid end time")
return false
end

varDelayPeriod = ((varEndTime - varStartTime)*6)
varCurTime = os.date("*t")
varCurrentTime = varCurTime.hour * 60 + varCurTime.min
varHumanTime = os.date("%m/%d/%Y %H:%M:%S")
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName1","Sunset",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable1",varSST,50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName2","Start Time",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable2",varST,50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName3","Dim Delay",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable3",varDelayPeriod/60,50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName4","Dim Step",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable4",varDimStep,50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName5","First Step",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable5",varHumanTime,50)

function DimDelay()
varDimLevel1 = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",varDevice1)
varDimLevel1 = varDimLevel1 - varDimStep
luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget=varDimLevel1 },varDevice1)
varDimLevel2 = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",varDevice2)
varDimLevel2 = varDimLevel2 - varDimStep
luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget=varDimLevel2 },varDevice2)
varActionTime = os.date("%m/%d/%Y %H:%M:%S")
luup.log("PL_Act: c_BirdRm_Lights_Dim")
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","VariableName5","Last Action",50)
luup.variable_set("urn:upnp-org:serviceId:SceneWatch1","Variable5",varActionTime,50)
if (varDimLevel1 >= varMin) or (varDimLevel2 >= varMin) then
luup.call_timer("DimDelay", 1 , varDelayPeriod,"","")
end
end

-- if the current time is in the given interval, run the scene.
if varStartTime <= varCurrentTime and varCurrentTime <= varEndTime then
if (varDimLevel1 > 0 or varDimLevel2 > 0)  then
luup.call_timer("DimDelay",1,varDelayPeriod,"","")
return true
end
else
return false
end

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9741
  • Karma: +737/-136
    • RTS Services Plugins
Re: Scene with dimming increment
« Reply #16 on: September 13, 2017, 09:37:31 pm »
I had not actually tried the actions ...
When I did I got not implemented in the log file ... I do not know why Vera put these there and did not implement.


Offline P-a

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +2/-0
Re: Scene with dimming increment
« Reply #17 on: September 14, 2017, 01:38:36 pm »
Howdy folks!

2nd issue: when I trigger the scene for increasing the level, in Vera interface, there is a delay before "scene play" button turns white again. This results in that I cannot push the button "fast" or several consecutive clicks. However, I have another scene that increases and decreases the volume of my sonos speakers?!

Both scenes are constructed more or less in the same manner.

Any remedy or suggestions, because this feature is useless with this problem?

Best regards!

Offline Priest

  • Full Member
  • ***
  • Posts: 142
  • Karma: +5/-0
Re: Scene with dimming increment
« Reply #18 on: September 14, 2017, 11:05:33 pm »
Are you talking about initiating it from inside the Vera page? If so, everything has that pause for me there. If I run it from Authomation or Imperihome it runs as fast as I can tap it.

Offline P-a

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +2/-0
Re: Scene with dimming increment
« Reply #19 on: September 15, 2017, 12:55:08 am »
Hi,

In imperihome it does not run as fast as i can tap it....
I want your system behaviour. With one lamp in the scene
it is "acceptable", IF i add 1 more lamp it sucks.

This also happen in my all lights off scene, sometimes
All lamps go out directly, but more often there is a delay
Of 30 sec on some lamps.

IF i turn lamps on/off manually in Vera, they react instantly.
« Last Edit: September 15, 2017, 12:57:08 am by P-a »

Offline Priest

  • Full Member
  • ***
  • Posts: 142
  • Karma: +5/-0
Re: Scene with dimming increment
« Reply #20 on: September 15, 2017, 08:48:18 am »
Okay.... post your LUA with the multiple lights and lets see it.  I'll test this evening by adding multiples to mine as well.

I do have a question though... when you are doing it with multiple lights, are you making one light follow the dim level of another or are you letting them both have independent dimming?  or, to put it another way..... is one lamp being told to increment by 10% and the other being told to match whatever level that first lamp is, OR are both getting their levels checked and adjusted independently by one scene activation?

Offline P-a

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +2/-0
Re: Scene with dimming increment
« Reply #21 on: September 16, 2017, 04:34:00 am »
Hi,

What I did was created a manually activated scene, went to Advanced settings, posted your code 2 times for controlling 2 lamps.

They step down, from whatever Level they are at, independantly

Much appreciated!