Light brighten on button press return to original brightness second press (OPEN)

I have rules set up to dim my lights throughout the day.
is there a way too add a button too habpannel that when you press it brings lights up to full brightness and then when you click it again it returns the lights back too the brightness it was set to before the button press

The only way I could get to work was a switch set too alternate commands press 1 set too 100 press 2 set to 0 but that’s just on off not return to previous setting

You can do it in rules, but I don’t know how/if to do it in the Experimental Rules Engine.

You will need a Rule to save the state of the Dimmers before you bring them up to 100 and then a rule that restores the saved state when pressing the button again.

Could you send me example code of how you would save the origianal setting before changing brightnes

Like I said, not in the Experimental Rules Engine.

In the Rules DSL it would look something like:

Assuming the lights are in the same Group

var Map<Item, State> previousStates = null

rule "Save or restore dimmer states"
when
    Item MyDimmerSwitch received command
then
    if(receivedCommand == ON){
        previousStates = storeStates(AllDimmers) // you can list each Item individually if you don't have a Group
        AllDimmers.sendCommand(100) // send the lights to 100
    }
    else {
        if(previousStates != null)  {
            restoreStates(previousStates)
            previousStates = null
        }
        else {
            AllDimmers.sendCommand(0) // if we don't have previous states to restore to just turn them OFF
        }
    }
end

remved

Hi again rlkoshak

do i need to create any special items ? something to store the previous values ?

i just cant quite understand how it works

do i need to change anything in the variable section of the rule

Do you mean like this ?

var Map<Item, State> previousStates = null

rule "Save or restore dimmer states"
when
    Item Temp Bright received command
then
    if(receivedCommand == ON){
        previousStates = storeStates(GLRLightsDimmer) // you can list each Item individually if you don't have a Group
        GLRLightsDimmer.sendCommand(100) // send the lights to 100
    }
    else {
        if(previousStates != null)  {
            restoreStates(previousStates)
            previousStates = null
        }
        else {
            GLRLightsDimmer.sendCommand(0) // if we don't have previous states to restore to just turn them OFF
        }
    }
end

If i then created a switch called Temp Bright this rule would work ?

OH has special functions you can call from Rules called Actions. Two of the built in actions are storeStated and restoreStates.

storeStates takes a group or list of items and returns a Map containing a reference to each item and it’s current state.

restoreStates takes a Map containing a reference to items and a State and returns each item to that State.

No special Items are required.

The variable section of the file contains a variable to store that Map between runs of the rule. Otherwise the Map will go away when the rule exits.

You cannot have a space in an item name. I can’t guarantee it will work but it should.

Thanks rlkoshak i will remove the space from the temp bright gove it a try and get back too you