Rule manager target triggered device

I'd like to be able to target just the triggered device in my rule so I can use a single rule to manage changing the color temperature of my lights so I don't have to create and manage a rule per light:

A very simple custom app can do this. However, adding this to RM would introduce a great deal of UI overhead.

definition(
    name: "Lights Color Temp",
    namespace: "hubitat",
    author: "Bruce Ravenel",
    description: "Simple lighting automation",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: ""
)

preferences {
    section {
		input "lights", "capability.colorTemperature", title: "Select lights to set", multiple: true
		input "cTemp", "number", title: "Select color temperature"
    }
}

def onHandler(evt) {
	evt.device.setColorTemperature(cTemp)
}

def initialize() {
	subscribe(lights, "switch.on", onHandler)
}

def installed() {
    initialize()
}

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

Thanks for the tip! Here's the custom app that I ended up with:

definition(
    name: "Lights Color Temp",
    namespace: "richardpeng",
    author: "Richard Peng",
    description: "Simple lighting automation",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: ""
)

preferences {
    section {
		input "lights", "capability.colorTemperature", title: "Select lights to set", multiple: true
		input "fromTime", "time", title: "Start time"
		input "toTime", "time", title: "End time"
		input "cTempDuring", "number", title: "Select color temperature during time range"
		input "cTempOutside", "number", title: "Select color temperature outside time range"
    }
}

def onHandler(evt) {
	def between = timeOfDayIsBetween(toDateTime(fromTime), toDateTime(toTime), new Date(), location.timeZone)
	def cTemp = between ? cTempDuring : cTempOutside
	log.debug "${evt.device.label}: Setting color temperature to ${cTemp}"
	evt.device.setColorTemperature(cTemp)
}

def initialize() {
	subscribe(lights, "switch.on", onHandler)
}

def installed() {
    initialize()
}

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