ChatGPT is actually pretty handy for getting a start on stuff like this. I know for me, it's easiest to see the code, then go figure out what it's doing to learn. I didn't even really look at the code, but it does look like the general gist of what you want. If nothing else, it's a good nudge in the right direction.
definition(
name: "Color Cycle",
namespace: "your namespace here",
author: "your name here"
)
preferences {
page(name: "settings")
}
def settings() {
dynamicPage(name: "settings", title: "Settings", install: true, uninstall: true) {
section("Select Bulbs") {
input "bulbs", "capability.colorControl", title: "Bulbs", multiple: true
}
section("Button Device") {
input "button", "capability.button", title: "Button Device", required: true
}
}
}
def installed() {
subscribe(button, "button.pushed", buttonPushedHandler)
}
def updated() {
unsubscribe()
subscribe(button, "button.pushed", buttonPushedHandler)
}
def buttonPushedHandler(evt) {
def currentColor = "red" // set the initial color to red
def colors = ["red", "green", "blue", "purple", "yellow", "orange"] // add more colors as desired
bulbs.each { bulb ->
bulb.setColor(currentColor) // set the initial color for each bulb
}
runEvery5Seconds(30, cycleColors) // cycle colors every 30 seconds
log.info("Button pushed: cycle colors")
}
def cycleColors() {
def currentColorIndex = colors.indexOf(currentColor)
def nextColorIndex = (currentColorIndex + 1) % colors.size()
def nextColor = colors[nextColorIndex]
bulbs.each { bulb ->
bulb.setColor(nextColor) // set the next color for each bulb
}
currentColor = nextColor
}
Conversation
This wasn't quite there, so I probed it a few more times and got to something that should at least cycle through colors.
definition(
name: "Color Cycle",
namespace: "your namespace here",
author: "your name here"
)
preferences {
page(name: "settings")
}
def settings() {
dynamicPage(name: "settings", title: "Settings", install: true, uninstall: true) {
section("Select Bulbs") {
input "bulbs", "capability.colorControl", title: "Bulbs", multiple: true
}
section("Button Device") {
input "button", "capability.button", title: "Button Device", required: true
}
}
}
def installed() {
subscribe(button, "button.pushed", buttonPushedHandler)
}
def updated() {
unsubscribe()
subscribe(button, "button.pushed", buttonPushedHandler)
}
def buttonPushedHandler(evt) {
def currentColor = bulbs[0].getCurrentColor() // get the current color of the first bulb
def colors = ["red", "green", "blue", "purple", "yellow", "orange"] // add more colors as desired
def currentIndex = colors.indexOf(currentColor) // get the index of the current color
def nextIndex = (currentIndex + 1) % colors.size() // get the index of the next color
def nextColor = colors[nextIndex] // get the next color
bulbs.each { bulb ->
bulb.setColor(nextColor) // set the next color for each bulb
}
log.info("Button pushed: cycle colors")
}
Conversation