Gentle wakeup

Posted on
Wed Dec 23, 2015 10:12 am
simdude offline
Posts: 51
Joined: Apr 03, 2006

Gentle wakeup

So, I'm just getting back into Indigo and playing a bit with Python. Before playing with Vera and SmartThings, I did a little Applescripting with Indigo a long time ago but even that is rusty.

Anyway, I wanted to duplicate a feature with SmartThings that simulated a sunrise for a gentle wakeup by very slowly fading up a lamp. I thought I would share the little script if this is the place to do that. Any comments to help me learn more would be appreciated. I found initially, it didn't work because it looks like my Intermatic dimmer wasn't responding to the brighten command so I had to use the setBrightness and calculate the level. This script brightens a light over 30 minutes (1800 seconds) updating every minute. I found I had to make it external because when I embedded it would not run as embedded scripts must complete in 10 seconds. For other newbies out there, just save to a text file and select in the Actions tab of a schedule. Choose Execute Script from the Server actions and select the file.

EDIT: Script below was edited for corrections

Code: Select all
#!/usr/bin/env python
# Filename:    wakeUp.py
# Description: Gently fade up one dimmer

import time
import indigo

dimmerDevice = "Master Bedroom Dressor"
ramptime = 1800.0
interval = 60
timer = 0
bright_amount = int((100.0/ramptime) * interval)
bright_level = 0

while ( timer < ramptime ):
    bright_level=bright_level + bright_amount
    if (bright_level <= 100 ):

        # The dimmer being used doesn't respond to
        # the brighten command so we have to set the brightness
        # with the setBrightness command

        indigo.dimmer.setBrightness(dimmerDevice, value=bright_level)

    time.sleep(interval)
    timer = timer + interval


Last edited by simdude on Fri Dec 25, 2015 6:14 am, edited 1 time in total.

Posted on
Thu Dec 24, 2015 5:14 am
simdude offline
Posts: 51
Joined: Apr 03, 2006

Re: Gentle wakeup

Actually, I do need a little help with the script. When I selected the file, and hit the run button to test in the Actions tab, it worked when. When it got called via a schedule, this is what I'm seeing in the log each minute:

Z-Wave sent "Master Bedroom Dressor" set brightness to 0

For some reason, when the script is called via the scheduler, the variable bright_amount never changes. When I tested it hitting the run button, it calculated correctly. What am I missing?

Posted on
Thu Dec 24, 2015 8:58 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Gentle wakeup

You have integers defined
Change them to float i.e. 100. Not 100

100/1800 is always 0
100./1800. is what you want.


Sent from my iPhone using Tapatalk

Posted on
Thu Dec 24, 2015 12:23 pm
simdude offline
Posts: 51
Joined: Apr 03, 2006

Re: Gentle wakeup

thanks. I forgot about that.....

Posted on
Thu Dec 24, 2015 2:52 pm
Shutter offline
Posts: 345
Joined: Mar 07, 2014
Location: London, UK

Re: Gentle wakeup

Once tested and you know it works could you be so kind as to post the updated script?

Thanks

Posted on
Fri Dec 25, 2015 5:51 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Gentle wakeup

you might need to convert back to integer or string once you set brightness in indigo:
Code: Select all
indigo.dimmer.setBrightness(dimmerDevice, value=int(bright_level))
or
Code: Select all
indigo.dimmer.setBrightness(dimmerDevice, value=str(int(bright_level)))
don't know what type indigo accept as value

Karl

Posted on
Fri Dec 25, 2015 6:03 am
simdude offline
Posts: 51
Joined: Apr 03, 2006

Re: Gentle wakeup

Thanks all for the corrections. Updated script below. And lesson to self. When you do test cases, need to run many more as the ones I did initially all had the bright_amount ended up as an int so they worked. :-( I also updated because the while loop was using a timer but since we truncate the bright_amount, it's possible you wouldn't get to 100% so this will work better.

Code: Select all
#!/usr/bin/env python
# Filename:    wakeUp.py
# Description: Gently fade up one dimmer

import time
import indigo

dimmerDevice = "Master Bedroom Dressor"
ramptime = 1800.0
interval = 60
bright_amount = int((100.0/ramptime) * interval)
bright_level = 0

while ( bright_level < 100 ):
    bright_level=bright_level + bright_amount
    if (bright_level <= 100 ):

        # The dimmer being used doesn't respond to
        # the brighten command so we have to set the brightness
        # with the setBrightness command

        indigo.dimmer.setBrightness(dimmerDevice, value=bright_level)

    time.sleep(interval)


Posted on
Sat Feb 27, 2016 10:51 pm
dnomode offline
Posts: 366
Joined: Apr 12, 2008
Location: North Georgia

Re: Gentle wakeup

Great Script. Thanks

However is there a way to cancel the script. For example, lets say I'm going to take the day off from work, if I get up and turn off the light manually the script just continues from where it left off. I would like my manually turning off the light in the middle of the process to cancel the script from running any further. How would I do that?

Edmond

Posted on
Sun Feb 28, 2016 6:32 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gentle wakeup

A couple more suggestions for your script:

Rather than using the device name "Master Bedroom Dressor", I would suggest that it's better to use the device ID number. If you should ever rename your device in Indigo, your script will break. But if you use the device ID, that will always remain the same (unless you delete the device.)

Secondly, you maintain the current brightness level as a local value within your script. I would suggest reaching out to see what the bright level of the device currently is--and then ramp that value--that way you know that your script and the physical device are always in sync. (The likelihood is probably small that your local variable is wrong, but in my opinion it doesn't hurt to be extra sure.)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Mar 09, 2016 3:51 pm
simdude offline
Posts: 51
Joined: Apr 03, 2006

Re: Gentle wakeup

Thanks Dave and dnomode. Let me do some updates and testing and I'll post the changes.

I've actually gone back and forth a few times on using device ids or names. I went with the name here because if the device fails, or I switch from a zwave to an Insteon device etc., The script will work as long as I keep the name the same. I've had to re-link zwave devices and when I used the device ID number, I get hosed. But, your point is also well taken. I guess it depends on which situation might happen more often.

DaveL17 wrote:
A couple more suggestions for your script:

Rather than using the device name "Master Bedroom Dressor", I would suggest that it's better to use the device ID number. If you should ever rename your device in Indigo, your script will break. But if you use the device ID, that will always remain the same (unless you delete the device.)

Secondly, you maintain the current brightness level as a local value within your script. I would suggest reaching out to see what the bright level of the device currently is--and then ramp that value--that way you know that your script and the physical device are always in sync. (The likelihood is probably small that your local variable is wrong, but in my opinion it doesn't hurt to be extra sure.)

Posted on
Wed Mar 09, 2016 4:10 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Gentle wakeup

simdude wrote:
. I've had to re-link zwave devices and when I used the device ID number, I get hosed.

The device ID shouldn't change in this situation - just edit your current device and pick the new/updated zwave ID from the list. You don't need to create a new device when changing / relinking ZWave/Insteon etc.


Sent from my iPhone using Tapatalk

Posted on
Wed Mar 09, 2016 4:27 pm
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Gentle wakeup

As an alternative - I do this with a couple of schedules.

One schedule, disabled by default, is named "Bedroom light ramp-up" and runs every 30 seconds. It has one condition that is: "If condition match rules" and is if the the following is true: "bedroom light is less that 60%" (I don't want the super-bright LED lights brighter than 60% or I'll be grumpy when I wake up LOL)
The action is to brighten the bedroom light by 1%

So to summarize: the first schedule (which is disabled by default) when enabled will brighten the bedroom light in 1% increments every 30 seconds until the light is at 60% brightness

The second schedule, is simply the "alarm" at a preset time on weekdays, (5 am) it enables the above "Bedroom Light Ramp-up" schedule. I selected the "Auto-disable" option to stop the process after 60 minutes so it wouldn't attempt to ramp up the light all day when it's manually turned off. It does have a condition attached that is basically the on/off status of a virtual device that allows me to turn off the alarm from Indigo Touch.

Getting up and turning off the light only starts the ramp-up over again. I did add a secret trigger so that if the bathroom light switched was double-tapped off, it would disable the schedules and turn off the light.

It's super-simple and has never failed to run, plus is easy to control and manipulate with triggers and other schedules as needed.

Terry

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 21 guests