Logic Machine Forum
Wake up light - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Wake up light (/showthread.php?tid=718)



Wake up light - Mr.D - 05.04.2017

Hi,

I am completely new to lua scripting and are hoping someone is able to help me out.
This is what i would like the script to do:

I have a scheduled event "Morning Wake-up" that is set to turn on every day at a certain time.
When this event happens i would like a script that dims the light up by 1% every 30th second. 
It will dim the light up untill it reaches 30%. The script needs to be "while" based, since I would like the dimming up to stop if  "Morning wake-up" is turned off.

Thanks for all help!


RE: Wake up light - admin - 05.04.2017

Code:
for val = 0, 30 do
  -- set new light value
  grp.write('1/1/1', val)

  -- stop if script is disabled
  if not script.status(_SCRIPTNAME) then
    break
  end

  -- wait 30 seconds
  os.sleep(30)
end



RE: Wake up light - Mr.D - 05.04.2017

Thanks Smile
Workes perfectly!


RE: Wake up light - Mr.D - 03.05.2017

Hi,

Just an additional question in regards to set value and Dali lighting.

When using the code you supplied: for val = 0, 30 do
It states that the lights should start at value 0 and work its way up to 30.

When this script is triggered, I am experiencing that when the set value is set to 1, the lights turns on, and it should, and the set value is 1. However, for the first second or so the light is really bright before it adjusts down to 1. Its almost like when the 1 is received the starting value is 100, and it have to turn down quickly to 1.

On a similar note, when using the circle for controlling the lights in visualization, I can turn the light off by pressing the down arrow, but when pressing the up arrow the lights turns on, but not to last set/dimming value, but to 100%.

I would think these two things are related?
Is there a way to alter this behavior?

Thanks,
Mr.D


RE: Wake up light - admin - 03.05.2017

Unless step is set, up/down arrows will always set max/min value. As for the script, it does nothing more than sending values from 0 to 30 every 30 seconds, you can do the same manually and check what's happening.


RE: Wake up light - Erwin van der Zwart - 03.05.2017

Hi,

Check your ETS parameters, the channel probably starts at 100% on start, see if you can set it to last value (memory)

BR,

Erwin


RE: Wake up light - Mr.D - 03.05.2017

Hi,
I have tested manually and it does start at last value (memory). So for example, if the last value was 30 (memory) and you use the circle/slider in the visualization, and you want to go from off to 1, it triggers the light go go from off to 30 and then down to 1. So if the room is completely dark, and you set the value to 1, it gets really bright for a quick moment before it very fast goes down to 1.
However, if the last value was 1, then you do not get this quick moment with very bright.
The ETS parameters states turn on by last received dimming value.
For the slider/circle this is not a big problem, but for my wake up light its. Because if last value before bed was 30, then I get a bright light, before it goes down to 1, and this is not very comfortable way of waking up. The only way I can see this issue solved is when turning of the night in the rom, it sets the value to 1, before turing off the light...
BR
Mr.D


RE: Wake up light - Mr.D - 04.05.2017

Hi,

Something must have happened to my script during the upgrade to the new firmware, because the break function no longer works.
I did some alterations to the original one, that worked fine until the upgrade...
Event-Based Script
value = event.getvalue()
if value == true then
for val = 0, 10 do
grp.write('Lys - Settverdi - 2 etg - Master Bedroom', val)
os.sleep(30)
if not value == true then break
end
end
end

The scripts starts as it should, but if event value is false, nothing happens, the lights keeps getting brighter...
Help!
Mr.D


RE: Wake up light - Erwin van der Zwart - 04.05.2017

Hi,

Yes there is a small mistake in your script (see remarks inside the script)

Code:
value = event.getvalue()
if value == true then -- first condition
  for val = 0, 10 do
     grp.write('Lys - Settverdi - 2 etg - Master Bedroom', val)
     os.sleep(30)
     if not value == true then -- it will always be true because of first condition
        break
     end
  end
end

So try:

Code:
for val = 0, 10 do
  value = grp.getvalue(event.dst)
  if value == true then
     grp.write('Lys - Settverdi - 2 etg - Master Bedroom', val)
     os.sleep(30)
  else
     break
  end
end

PS: Not tested it so i hope it will work (:

BR,

Erwin


RE: Wake up light - admin - 04.05.2017

You should replace event.getvalue() with grp.getvalue(event.dst), since event.getvalue() will always return the value that triggered the script. There's also a problem in case value changes twice during sleep: you will get two copies of the same script running.


RE: Wake up light - Mr.D - 04.05.2017

Thanks you guys!
It works perfectly now Smile

Final script:
for val = 0, 10 do
  value = grp.getvalue(event.dst)
  if value == true then
     grp.write('Lys - Settverdi - 2 etg - Master Bedroom', val)
     os.sleep(30)
  else
     break
  end
end

Thanks!
Mr.D


RE: Wake up light - Erwin van der Zwart - 04.05.2017

Hi,

If you want to avoid a double instance of the script like admin adviced, add this code on top of your script:

Code:
storagename = 'wakeuplight_pid'
oldpid = storage.get(storagename)
pid = os.getpid()
storage.set(storagename, pid)  
if oldpid ~= nil then  
 os.kill(oldpid, signal.SIGKILL)
end

and put this at the end of the script:

Code:
storage.remove(storagename)

This code will check if there is already / still a instance running from a previous event and kill it.

BR,

Erwin


RE: Wake up light - Mr.D - 04.05.2017

Thanks Erwin!
This will definitely come in handy! Not just for this script, but for others I am running as well!

I also figured out why my lights got really bright to begin with, before very quickly dimming down to the right value.
I checked one of the parameters in ETS, and there were five different options in regards to how the Dali should behave for set value when related to ON and OFF behavior... playing around with these settings I was able to make the lights behave "normally" Smile
BR
Mr.D


RE: Wake up light - Erwin van der Zwart - 04.05.2017

Hi,

Good to hear, already thought it was a ETS parameter (:

BR.

Erwin


RE: Wake up light - Mr.D - 06.05.2017

Hi,

I might have jumped the gun on this one.
I have set ETS Paramaters to the exact same for all lights... but they act differently when going from OFF to 1%.
For one object if the value 1% is sent, the lights goes from from OFF and directly to 1%.
For another object if the value 1% is sent, the lights first goes to last dimming value and then really quickly dims down to 1%.
This is within the same DALI driver in ETS, and all my lights uses the same types of TRAFO.

I have further noticed that if the value 2% is sent, then all objects goes directly from OFF to 2%.
Furthermore, if the current value is set to 1%, and I increase it to 2%, the lights dims up, but there is no change in the status object. It still states 1%.
The same goes for, if the value is 2%, and I change it to 1%, the status object is not changed, but the lights still dims down slightly.
Also if the value 50% is written, the status always comes out stating 51% or 49%?????
Anyone knows whats going on?

PS if the same steps are done directly in ETS, then all lights goes from OFF and directly to 1%... so here it works fine...
Also if the value 50% is written, the status always comes out stating 51% or 49%...
BR
Mr.D


RE: Wake up light - PassivPluss - 07.05.2017

Hi
Is it one type of lightning that does the bright light and down to 1 %. My reason for asking is that some of the manufactors of lamps have a booster function that does thisSmile
Ruben


RE: Wake up light - Mr.D - 07.05.2017

Hi,
I have 2 Dali Gateway (Siemens 5WG1 141-1AB02) that controls my spotlights in the ceiling.
As far as I know, there is no booster function on this gateway. The weird part is that for one group of spotlights the lights do not "boost" up before dimming down, but for another set of spotlights it does and all this within the same Dali Gateway.... And these spotlights are all the same and uses the same type of trafo.
I have controlled the parameters within ETS for the group that does "boost" up against the ones that dont. As far as I can tell the parameters are identical.

I use data type scale (%) to control the lights... When sending 1% for some spotlights it boost up, for others it dont.
I have tried altering the data type, to 0-255 instead. If I send the value 2 it boosts up, but if I send the value 3 it dont boost up.
Both 2 and 3 produce 1% lights.
So it seems to me that for some objects the Dali Gateway interprets 1% as a value 2, but for others it is interpreted as 3...?
It is really annoying!!!

BR,
Mr.D