Rule Machine: Need help with rule

Devices:
2 color bulbs - Bulb A and Bulb B
1 On/off switch

Condition:
When switch turns on

Result:

  1. Capture only on/off state of both bulbs (not color,etc)
  2. Set both bulbs to Color Temp 3600
  3. Set both bulbs back to the on/off state they were before the automation started.

I would like to accomplish this with as few rules/virtDevices as possible.

The reason I can't seem to get this to work is because of 2 issues.
1.Hue lights turn on when you set their temperature.
2. In RM, when you capture the state of a color bulb, it captures all its attributes including HSL info. When the restore occurs, it resends all this info including HSL which reverts the color of the bulb.

Another solution would be if there was a way to send a setTemperature command to the Hue bulb without turning it on...which I don't think is possible.

Hopefully one of the great minds here can point out an easy solution or something obvious I'm not seeing.

Stephan

P.S. Above is a simplified version of what I'm deploying - There will be at least 6 bulbs as part of this automation so anything involving a separate rule or VirtDevice per bulb will not be practical for me.

Why don't you write a little app to do this? There's not much to it. You can't do it with RM within the constraints you've specified.

The app does these things:
input to select the on/off switch
Input to select the color bulbs

Like this:

preferences {
        input "onOffSwitch", "capability.switch", title: "Select control switch"
        input "bulbs", "capability.colorTemperature", title: "Select bulbs"
}

subscribe to the on/off switch.on

Like this:

def initialize() {
    subscribe(onOffSwitch, "switch.on", bulbHandler)
}

The handler runs through the list of bulbs, grabbing bulb.currentSwitch, sets the color temp for each, and then if it was off before, turning it off. Like this:

def bulbHandler(evt) {
        def needsOff = false    
        bulbs.each {
                needsOff = it.currentSwitch == "off"
                it.setColorTemperature(3600)
                if(needsOff) it.off()
       }
}

It's about a 20 line app all in. The above is the guts of it.

3 Likes

My hope was to not have this done through an app because there were multiple reasons why I might call this action each with different scenarios. I think I am asking too much of this automation and it's time to simplify to smaller pieces.

I was just starting to formulate an app or driver in my head but of course I started going down the line of learning the Hue Api and sending a httpPut commands...instead of a simpler route like you suggested. Thanks @bravenel. I'll give it a shot.

So you could do something sort of flexible, with a lot of bulbs, and numbered subsets of the bulbs. Each subset has a number associated with it. You would define all of these subsets in an app, and have to know that numbering. The guts would be the little thing above, but instead of acting on the full set of selected bulbs, would only act on a specific subset of bulbs.

Then instead of a control switch, use a control virtual dimmer. You set the dimmer to the level for the number of the subset you want to zap. That's still fairly simple. Obviously, one can get as fancy as one is willing to code...

Edited:

Or just use separate inputs for each subset group, and input a number for each group, Same principle inside to use a dimmer level to select the subset.

1 Like

Our Zigbee bulb driver has this capability built-in. If your bulbs were connected directly, instead of through the Hue bridge, this would be very doable with nothing special.

It allows you to not have setColorTemperature turn on the bulb.

@bravenel
Using your example I created the following which works beautifully 99% of the time (Muchas Gracias):

/**
 *  Hue Revert
 *
 *  Copyright 2018 Stephan Hackett
 *
 *  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: "Hue Revert",
    namespace: "stephack",
    author: "Stephan Hackett",
    description: "Revert Hue to Custom Defaults",
    category: "My Apps",
    iconUrl: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png",
    iconX2Url: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png",
    iconX3Url: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png"
)

preferences {
    section("") {
        input ("controlDevice", "capability.switch", title: "Select Control Switch:")
        input ("bulbs", "capability.colorTemperature", title: "Select bulbs:", multiple:true)
    	input ("defTemp", "number", title: "Set Default Temp to Revert To:")
    }
}
    
def initialize() {
    subscribe(controlDevice, "switch.on", revertHandler)
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
	initialize()
}

def revertHandler(evt) {
        def bulbState
    	//runIn(5,test)
    	bulbs.each {
            it.refresh()
            log.info it.displayName + it.currentSwitch
            bulbState = it.currentSwitch
            it.setColorTemperature(defTemp)
            if(bulbState) it.$bulbState
        }
}

def test(){
	log.info "test"
    
    bulbs.each {
            	
       }
}

I am using the "it.refresh" for the 1% scenario where the bulb may have been recently turned on/off (in between the 1 minute bridge poll). It does not appear to be getting the updated state from the hub. Is possible to do a refresh() for hue bulb groups?

I tried adding a 5 second delay between the refresh and the rest of the script but nogo on that as well.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.