Help with another rule

Hi everyone

im trying too create a guest mode using a rule

when guestmode changed to on
remember status of all items
then change some items…

when guestmode is turned off
set all the items back too the remembered state

rule so far

rule "Guest Mode Enable"
when
    Item GuestMode changed to ON
then
//remeber status of all items about too change
    GDisable.sendCommand (ON) // group item that contains switces too disable automations
        createTimer(now.plusSeconds(10), [|
            DisableAmeliasTvButton.sendCommand (OFF) // member of GDisable that doesent need turning off
            DisableTylersTvButton.sendCommand (OFF) // """"
            DisableTylersRules.sendCommand (OFF) // """"
            DisableAmeliaRules.sendCommand (OFF) // """"
            DisableSystemWarning.sendCommand (OFF) // """"
            DisableServerDoorWarnings.sendCommand (OFF) // """"
            DisableKidsRules.sendCommand (OFF) // """"
            DisableServerRackWarning.sendCommand (OFF) // """"
            LrLightLock.sendCommand (ON) // Stops living room lights from changing
            PartyMode.sendCommand (ON) // enables legacy rule too be remomoved soon
                createTimer(now.plusSeconds(10), [|
                    GLRSpeakerLights.sendCommand ("19,100,50") // sets livingroom lights on
                    LivingRoomLamp_Brightness.sendCommand ("50")
                ])
        ])
end

rule "Guest Mode Disable"
when
    Item GuestMode changed to OFF
then
    // set items back too rememebered state
end

I haven’t got a clue how too do the remember and restore of items little experience with using historic states

If you don’t need it to survive a restart of OH (or a reload of the .rules file) you can use the storeStates and restoreStates Actions.

If not, you’ll need an additional set of Items to save/restore the old states.

The third alternative is to take a timestamp saved to a DateTime Item that is saved in persistence. Then use MyItem.historicState(TimeStampItem.state.zonedDateTime).state to get the state of the Item at the time of the timestamp to restore from.

2 Likes