Dimming Slowly... every 5 minutes

Hi,

I have a questions,

I installed a few more dimmers last weekend and I want to do two things:

1- program one dimmer to very slowly dim a light over a period of say 30 minutes. For example:

at 7:00PM dim to 90%
at 7:05PM dim to 80%
at 7:10PM dim to 70%
at 7:15PM dim to 60%
at 7:20PM dim to 60%
etc until it turns off. so 10% dim every 5 minutes. It’s for a bird cage and I want to simulate sunset for them :slight_smile:

How can I do that?

thank you.

Manufacturer and model of the dimmer you want to do the fade?

Hi,

sorry I didn’t mention that. I want to do this on:

Linear PD300Z-2 Z-Wave 300-watt Plug-In Lamp Dimmer Module, Small, White

and possibly as well ion the future:

Linear WD500Z-1 Z-Wave 500-watt Wall Mount Dimmer Switch, Small, White

Thanks,

Here is the code for an app that does this. Select the dimmers, and the number of minutes. Also select a Momentary Button to trigger the app. That button can be created in the IDE, and used in Hello Home phrases to launch the dim down. It dims once a minute until off, dimming by how much is needed to take the total amount of time.

/**
     *  Slow Dimmer
     *
     *  Copyright 2015 Bruce Ravenel
     *
     *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
     *  in compliance with the License. You may obtain a copy of the License at:
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
     *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
     *  for the specific language governing permissions and limitations under the License.
     *
     */
    definition(
        name: "Slow Dimmer",
        namespace: "bravenel",
        author: "Bruce Ravenel",
        description: "Slowly reduce dim level",
        category: "My Apps",
        iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
        iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
        iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
    
    
    preferences {
    	section("Select dimmers to slowly dim...") {
    		input "dimmers", "capability.switchLevel", title: "Which?", required: true, multiple: true
    	}
        
        section("Over how many minutes to dim...") {
        	input "minutes", "number", title: "Minutes?", required: true, multiple: false
        }
        
        section("Select momentary button to launch...") {
        	input "trigger", "capability.momentary", title: "Which?", required: true
        }
    }
    
    def installed() {
    	initialize()
    }
    
    def updated() {
    	unsubscribe()
    	initialize()
    }
    
    def initialize() {
    	subscribe(trigger, "switch.on", triggerHandler)
    }
    
def triggerHandler(evt) {
    if(dimmers[0].currentSwitch == "off") state.currentLevel = 0
    else state.currentLevel = dimmers[0].currentLevel
    if(minutes == 0) return
    state.dimStep = state.currentLevel / minutes
    state.dimLevel = state.currentLevel
    dimStep()
}

def dimStep() {
    if(state.currentLevel > 0) {
        state.dimLevel = state.dimLevel - state.dimStep
        state.currentLevel = state.dimLevel.toInteger()
    	dimmers.setLevel(state.currentLevel)
        runIn(60,dimStep)
    } else dimmers.off()
}
5 Likes

Thanks a lot. That looks perfect. I will use this to learn how to do some coding here…

I will also have to figure out how to then schedule this to start say at 7:00PM…

Thanks, this is a great start.

That’s the idea!! Everyone has to start somewhere. Good luck!!

1 Like

Hi,

Well, so I think I changed the program to make it run based on a schedule :slight_smile: Is this correct:

definition(
    name: "Slow Dimmer",
    namespace: "",
    author: "Bruce Ravenel",
    description: "Slowly reduce dim level",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
	section("Select dimmers to slowly dim...") {
		input "dimmers", "capability.switchLevel", title: "Which?", required: true, multiple: true
	}

    section("Over how many minutes to dim...") {
    	input "minutes", "number", title: "Minutes?", required: true, multiple: false
    }
    
    section("Time to run") {
        input "time1", "time", required: true
    }
}

def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
	schedule(time1, triggerHandler)
}

def triggerHandler(evt) {
    state.currentLevel = dimmers[0].currentValue("level")
    if(minutes == 0) return
    state.dimStep = state.currentLevel / minutes
    state.dimStep = state.dimStep.toInteger()
    state.currentLevel = state.currentLevel - state.dimStep
         if(state.currentLevel > 0) {
        dimmers.setLevel(state.currentLevel)
        runIn(60,dimStep)
    } else dimmers.off()
}

but it fails :slight_smile: I get unexpected error…

I wouldn’t do it that way. It’s cleaner to just to use a Hello Home phrase to do it. Every Hello Home phrase has a section called “Automatically perform “phrase” at…”. In there are options like, “At a certain time”, etc. Presumably, the time of day you want to do this makes sense in the overall daily schedule of your home. If that’s true, it may be just something that happens in a daily Hello Home phrase (e.g., Good Evening!, which might run at Sunset). The Hello Home phrase simply turns on the trigger to launch the app – pushes its virtual button. Then the app does the dim-down.

The reason to use a Hello Home phrase instead of coding the time into the app is because Hello Home phrases provide much more sophisticated refined control over what happens when the phrase runs, or when it runs or not. There is no advantage to attempting to duplicate that functionality in a SmartApp. ST is like a toy with boxes and connectors and some basic designs to follow to make cool things. Use the built in designs/connectors whenever possible (Lights & Switches, Hello Home phrases, etc). Custom apps are connectors that you make because the standard ones don’t offer the function you need – for example, dimming some lights gradually over 30 minutes.

1 Like

hmm :wink: Ok. Will try that now… :slight_smile:

Have fun with it (20 chars)

Or you could just use Lights & Switches, if that makes more sense. You use the trigger as the device, and “Turn on using a schedule”.

1 Like

I ended up using Hello and it works perfectly and I learned a lot in the process. THANK YOU so much for all your help :smile:

I wanted to use this to also make a nice movie dimmer… You know how when u start movies the lights dont dim instantly… They take a minute or two. So I changed the runin every 10 seconds so that I can dim lights in about 2 minutes… But looks like run in doesn’t like to work with short intervals :slight_smile: I also tried dimOnce but no luck with short intervals.
It also seems that even the older code where it does every 60 seconds… It taking longer than that. If I want to dim in 30 minutes it seems its taking about double that.

It still works for what I want it but thought I would not it…

Thanks…

The app uses runIn(), which generally does not work for times of less than 60 seconds. Also, even when set for 60 seconds, it’s approximate at best. There is also a rounding issue in this app, because it’s dividing the dimLevel by the amount of time to take, and rounding down. So if, for example, one specified 30 minutes to dim from 59%, it would take close to twice as long to fully dim. For most situations, the round off doesn’t matter, but you can certainly get situations where it does.

Thanks. That’s what I thought…

HaHa!! The challenge for the reader: Fix the app so the round-off doesn’t have such an impact. Not hard to do…

I am looking to do the same thing but i just started with smartthings yesterday. can you give me an example of how i could use the Hello Home to start this at a specific time. Thank you

Hello Home is now called Routines. The app has a selection you make for a “trigger” switch, which is a Momentary Button Tile.

So, first, you have to create a Momentary Button Tile using the IDE (https://graph.api.smartthings.com), in My Devices, New Device. You have to give it a name, an address (just make up 4 digit number), and Type (Momentary Button Tile).

Then you link that button into the app. In the Routine, you simply Turn On that button. That will fire the app to do what you asked it to.

In the Routine setup there is an option to “Automatically perform …” “At a specific time” … That’s how you get this to fire at a specific time.

You can always send a Private Message to me if you get stuck, and I’ll help…

Thankyou. i was able to get that setup but unfortunately it is not working. Any chance that script doesn’t work fordimming GE bulbs directly?

Not that I’m aware of. It should work with any dimmer.