Switch item for Homematic dimmer to switch between OFF and OLD_LEVEL

Hi all!

I have a question following up on this old post from 2016:

It has been over a year since this thread. The “OLD_LEVEL” virtual channel is a result of this discussion and long since available. Thanks for implementing it, btw!

While this is great, any Switch item linked to this channel behaves like a push button. So in order to set the old dimmer level for a dimmer that got switched off, this switch needs to be switched on. It then immediately returns back to off and the old dimmer level is set. So far, so good. Unfortunately there seems to be no easy way to get a “real” switch out of this. What I mean is one that turns the light off if the switch is set to OFF and back on again (to OLD_LEVEL!) when it is set to ON.

My question is if there is an easy way to achieve this or if a rule is needed. I know this rule would be quite simple. But still… the less code, the better.

So, how did you solve this? Rule or some other “standard” way I 'm not seeing?

Thanks a lot in advance!

Jens

Maybe I’m answering my own question. But I wanted to post the current solution, which is based on rules (because I currently don’t know better :slight_smile:)

What I want to be able to do is to quickly toggle a dimmer’s state between OFF and OLD_LEVEL while at the same time being able to adjust the level flexibly. The UI will be a HABpanel. Here’s my current setup:

// Link to the actual dimmer (controllable via UI)
Dimmer DimmerDiningRoom "Licht im Esszimmer" {channel="homematic:<...>#LEVEL"}
// Virtual toggle switch (controllable via UI)
Switch DimmerDiningRoomToggle "Licht im Esszimmer ein/aus"
// Auxiliary switch linked to virtual channel. Note: Behaves like a pushbutton
Switch DimmerDiningRoomLastLevel "Letzter Wert Licht im Esszimmer" {channel="homematic:<...>#OLD_LEVEL"}

Those items are controlled by the following rules (which are too complicated for my taste, but here we go):

rule "Dimmer Dining Room Toggle"
when
    Item DimmerDiningRoomToggle changed
then
    /*
     * Only change the dimmer item if it is necessary because
     * the dimmer item might otherwise change the toggle item
     * leading to unwanted behavior.
     */
    if (DimmerDiningRoomToggle.state == ON && DimmerDiningRoom.state == 0) {
        // Restore the last dimmer level
        DimmerDiningRoomLastLevel.sendCommand(ON)
    }
    if (DimmerDiningRoomToggle.state == OFF && DimmerDiningRoom.state > 0) {
        // Switch the dimmer off
        DimmerDiningRoom.sendCommand(0)
    }
end

rule "Dimmer Dining Room"
when
    Item DimmerDiningRoom changed
then
    if (DimmerDiningRoom.state == 0) {
        // The dimmer is OFF
        DimmerDiningRoomToggle.postUpdate(OFF)
    } else {
        // The dimmer is ON
        DimmerDiningRoomToggle.postUpdate(ON)
    }
end

In HABPanel I use a switch (linked to DimmerDiningRoomToggle) and a slider (linked to DimmerDiningRoom):

I’m very open to suggestions for simplifying this. :slight_smile: It’s perfectly fine, but I’d rater not have two rules per dimmer.