Author Topic: Bedroom Sunrise Simulation Lighting Event: Can this be done?  (Read 16340 times)

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Bedroom Sunrise Simulation Lighting Event: Can this be done?
« on: February 18, 2010, 05:32:29 pm »
I have a problem with waking up in the morning, and I'm hoping my LinuxMCE setup can help me. The traditional auditory alarm clock doesn't suit me very well. The key, for me, to waking up early with a feeling of being refreshed appears to be light.

I would like to dim my bedroom lights from 0 to 100% gradually over a 15 minute period, beginning at a time that can be set each night before bed, like a traditional alarm clock. For the most realistic sunrise-simulation, I'd like to use as many discrete intervals as allowed by the Zwave protocol (I think it's 128?)

I see that I can use a timed lighting event to set a certain level on my bedroom lights, but I'd like to avoid having to create 128 or so different events occuring 7 seconds apart. I'm wondering if there's a way to create a single alarm clock event which executes a script. Conceptually it would look like:

<Bedroom_Sunrise_Simulation_Event_Script>
setlevel lightingdeviceXYZ 1
pause 7
setlevel lightingdeviceXYZ 2
pause 7
setlevel lightingdevice XYZ 3
pause 7
etc... but done using a loop and incrementing variable.

Can someone let me know if this is possible, and if so, point me in the right direction for getting started?

Thanks in advance.

Dave

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #1 on: February 18, 2010, 10:31:31 pm »
Warning, this is my first bash script EVER.

#!/bin/bash

Code: [Select]
NEXTLEVEL=1

#loop for 15 minutes (900 seconds)
for ((i=1;i<900;i+=1))
do

#logarithmically adjust time for increases to provide a more even light gradient
NEXTTIME=$(echo "scale=5;450*l($NEXTLEVEL)/l(10)" | bc -l)
#convert to integer
NEXTTIME=$(printf %.0f $NEXTTIME)

#execute if it's time to advance to the next lighting level
if [ "$i" -gt "$NEXTTIME" ]
        then
        /usr/pluto/bin/MessageSend localhost 0 34 1 184 76 "$NEXTLEVEL"
        (( NEXTLEVEL++ ))
        fi
#pause 1 second
sleep 1
done


Quick test ran fine. We'll find out tomorrow morning how well it works.

purps

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1402
  • If it ain't broke, tweak it
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #2 on: February 18, 2010, 10:41:44 pm »
Let us know how well it works! I would be very interested in this.
1004 RC :: looking good :: upgraded 01/04/2013
my setup :: http://wiki.linuxmce.org/index.php/User:Purps

totallymaxed

  • LinuxMCE God
  • ****
  • Posts: 4660
  • Smart Home Consulting
    • View Profile
    • Dianemo - at home with technology
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #3 on: February 18, 2010, 11:29:32 pm »
Warning, this is my first bash script EVER.

#!/bin/bash

Code: [Select]
NEXTLEVEL=1

#loop for 15 minutes (900 seconds)
for ((i=1;i<900;i+=1))
do

#logarithmically adjust time for increases to provide a more even light gradient
NEXTTIME=$(echo "scale=5;450*l($NEXTLEVEL)/l(10)" | bc -l)
#convert to integer
NEXTTIME=$(printf %.0f $NEXTTIME)

#execute if it's time to advance to the next lighting level
if [ "$i" -gt "$NEXTTIME" ]
        then
        /usr/pluto/bin/MessageSend localhost 0 34 1 184 76 "$NEXTLEVEL"
        (( NEXTLEVEL++ ))
        fi
#pause 1 second
sleep 1
done


Quick test ran fine. We'll find out tomorrow morning how well it works.

Cool :-)

Andrew
Andy Herron,
CHT Ltd

For Dianemo/LinuxMCE consulting advice;
@herron on Twitter, totallymaxed+inquiries@gmail.com via email or PM me here.

Get Dianemo-Rpi2 ARM Licenses http://forum.linuxmce.org/index.php?topic=14026.0

Get RaspSqueeze-CEC or Raspbmc-CEC for Dianemo/LinuxMCE: http://wp.me/P4KgIc-5P

Facebook: https://www.facebook.com/pages/Dianemo-Home-Automation/226019387454465

http://www.dianemo.co.uk

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #4 on: February 19, 2010, 03:13:29 pm »
Worked great! I woke up at 6:30am feeling like I slept in till noon. I think 15 minutes might be a bit too fast so I'm gonna play around with the timing algorithm a bit.

I received a question about what brand of zwave device I'm using. The answer is the Act Homepro lamp module.

Would be ideal if we could build in this functionality into lighting control. Instead of just specifying setlevel, you could also specify the time over which you want the change to occur - or a beginlevel, endleve, and time delta


jimbodude

  • Guru
  • ****
  • Posts: 372
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #5 on: February 19, 2010, 07:13:12 pm »
Would be ideal if we could build in this functionality into lighting control. Instead of just specifying setlevel, you could also specify the time over which you want the change to occur - or a beginlevel, endleve, and time delta

Fade in/out would, indeed, be a great addition - especially in home theater settings.  I'm not sure how often I would want it set to 15+ minutes, more like 15 seconds in my case, but whatever makes you happy.  ;)

sambuca

  • Guru
  • ****
  • Posts: 462
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #6 on: February 19, 2010, 08:36:40 pm »
Hi,

I just meddled around in the event plugin, and just ordered my first Z-wave gear. So I'm going to have a look at it. Don't expect it done right away, though ;) Might not even get into 810.

best regards,
sambuca

valent

  • Guru
  • ****
  • Posts: 381
    • View Profile
    • /kernel_reloaded/
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #7 on: February 20, 2010, 06:18:15 pm »
Whoow, cool idea, love it!

Is there a wall plug what I could control one self-standing lamp via zwave? I guess that the zwave wall plug should have support dimming feature, right? Which one do you recommend for 220V ?
LinuxMCE - If it was easy, everybody would be doing it!!
My setup - http://wiki.linuxmce.org/index.php/User:Valent

huh

  • Guru
  • ****
  • Posts: 245
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #8 on: April 20, 2010, 04:55:27 am »
This is a really cool idea- has it been implemented in the main build?



bongowongo

  • wants to work for LinuxMCE
  • **
  • Posts: 826
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #9 on: April 20, 2010, 09:27:33 am »
Whoow, cool idea, love it!

Is there a wall plug what I could control one self-standing lamp via zwave? I guess that the zwave wall plug should have support dimming feature, right? Which one do you recommend for 220V ?

Cool Idea?
Philips Wake up light
http://www.search.philips.com/search/search?q=Wake-up+Light&s=all&l=global&h=all&o=consumer

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #10 on: April 20, 2010, 03:06:19 pm »
Hadn't thought of adding audio to the wake-up experience. If you have a squeezebox or MD in the bedroom you could probably do this, and incorporate a fade-in.

bongowongo

  • wants to work for LinuxMCE
  • **
  • Posts: 826
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #11 on: April 20, 2010, 03:35:12 pm »
Yes like soft bird sounds, or crickets or an ocean breeze.

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #12 on: April 20, 2010, 07:16:15 pm »
I received a question about location and how to trigger this script.

I don't really know where a good place to locate the script is, but I chose /home/linuxmce/sunrise_sim.sh for lack of a better idea.

To trigger:

In webadmin, create a day-of-the-week based timed event. For the Device, select App-Server. For the Command, select Spawn Application. For #13 filename, enter the location of the script, eg /home/linuxmce/sunrise_sim.sh

That should be all. A router reload might be required.

davegravy

  • Addicted
  • *
  • Posts: 551
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #13 on: April 20, 2010, 07:29:13 pm »
Also note that you need to specifiy the device ID of the light you're trying to control in the line

Code: [Select]
/usr/pluto/bin/MessageSend localhost 0 34 1 184 76 "$NEXTLEVEL"
In the above case, the ID of the light is 76, you most likely need to replace this.

d0t

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Bedroom Sunrise Simulation Lighting Event: Can this be done?
« Reply #14 on: April 23, 2010, 11:56:15 pm »
Just an idea - how about having some text to speech using festival?  Would be cool to have the alarm clock MD read something like:

'Good morning.  Its 8 AM.  Outside conditions are currently sunny, 75 degrees with 50 percent humidity.  (blinds open)  You have 2 new voice mails.  Starting music playback.'

Weather could be pulled from an online source, or from Z-Wave climate sensors.  I haven't a clue how difficult this would be to script, however...

.