Programming remote control with code

Hope everyone's doing fine.
Long story short, I'm a new user. I want to control my room with a 3-button remote control to cycle through my five scenes. When button 1 is pressed, a new scene should add on top of whatever is already lit. When nothing is lit, the last activated scene should be turned on. (If you get where I'm going with this, that way I can both isolate scenes, and combine them when needed)
Below is what a generic code could look like. Is anyone fluent in Hubitat code willing translate this, if it'll take a minute? It would save me days of struggle on my own :smiley:

//5 scenes: A, B, C, D, E
//'LightsOff' is a scene where all lights are off

Remote: button1

If LightsOff=true

  • If last scene activated=A

  • Turn on: A

  • If last scene activated=B

  • Turn on: B

  • If last scene activated=C

  • Turn on: C

  • If last scene activated=D

  • Turn on: D

  • If last scene activated=E

  • Turn on: E

  • Else

  • Turn on: A

Else

  • If current scene=E

  • Turn on: A

  • If current scene=A

  • Turn on: B

  • If current scene=B

  • Turn on: C

  • If current scene=C

  • Turn on: D

  • If current scene=D

  • Turn on: E

Do you want to write an app to do this, or use one of the built-in apps, like Rule Machine?

I couldn't figure out how to do it with the Rule Machine, so I figured it might be easier to write a small app.

I don't completely understand your use-case, but regardless I think it's possible with RM. Tagging @Clye just in case you didn't get notified on my reply.

You can also create a custom app relatively simply, but it may get unwieldy depending on how many unique combinations and behaviors you need to implement.

Here's a snippet that I pared down from an app of mine. It shows how to subscribe to events on an input device (like a button) and then to execute commands or other actions on output devices (in this case, a multi-select switch input). You could implement whatever complicated logic you wanted within the event handler function in the app for button press events.

These references will be helpful to figure out what you can do based on apps, events, and devices:
https://docs.hubitat.com/index.php?title=Device_Object
https://docs.hubitat.com/index.php?title=App_Object
https://docs.hubitat.com/index.php?title=Event_Object

/*

 */

definition(
    name: "input output example",
    namespace: "tomw",
    author: "tomw",
    description: "",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")

preferences
{
    page(name: "mainPage1")
}

def mainPage1()
{
    dynamicPage(name: "mainPage1", title: "", install: true, uninstall: true)
    {
        section
        {
            input name: "inputButton", type: "capability.pushableButton", title: "Input Button", multiple: false, required: true
        }
        section
        {
            input name:	"outputSwitches", type:	"capability.switch", title: "Output Switches", multiple: true, required: true
        }
        section
        {
            input name:	"enableLogging", type: "bool", title: "Enable Debug Logging?", defaultValue: true, required: true
        } 
    }
}

def logDebug(msg)
{
    if(enableLogging)
    {
        log.debug "${msg}"
    }
}

def installed()
{
    logDebug("installed")
    unsubscribe()
    
    initialize()
}

def updated()
{
    logDebug("updated")
    installed()
}

def initialize()
{
    logDebug("initialize")
    
    subscribe(inputButton, "pushed", pushedHandler)
}

def uninstalled()
{
    logDebug("uninstalled")    
    unsubscribe()
}

def pushedHandler(evt)
{
    logDebug("evt.getDevice().name = ${evt.getDevice().name}")
    logDebug("evt.name = ${evt.name}")
    logDebug("evt.value = ${evt.value}")    

    def switchState, newState

    for(thisSwitch in outputSwitches)
    {
        switch(thisSwitch.currentValue("switch"))
        {
            case "on":
                thisSwitch.off()
                break
            
            case "off":
                thisSwitch.on()
                break
        }
    }
}