Expire binding - how to streamline the code

I would like to switch a bulb socket by pressing a Xiaomi switch in connection with expire binding.

Is there a more convenient way than the code below?

// items
Switch EG_az_l_e27fassung1      "Fassung 1" <light> (gM,gR,gPresenceSim,Gzwave,Glicht,Gschalter,Gad) ["Switchable"] {channel="zwave:everspring_XYZ:controller:node2:switch_binary"}

Switch E27_expire "E27 expire" <light> (gM,gR,Glicht) { expire="10s,command=OFF" }

// rules
rule "EXPIRE"
when
    Channel "mihome:sensor_switch:YYY:ZZZ:button" triggered LONG_PRESSED  
then
    E27_expire.sendCommand(ON)
end


rule "E27 EXPIRE"
when
    Item E27_expire received command  // Xiaomi MiniSwitch2 (Round)
then
    switch EG_az_l_e27fassung1.state {
        case OFF : {
            EG_az_l_e27fassung1.sendCommand(ON)
        }
        case ON : {
            EG_az_l_e27fassung1.sendCommand(OFF)
        }
    }
end

Try using Item E27_expire changed to ON in the rule. Otherwise it will go back off 10 seconds later when the switch changes to OFF after getting the OFF from expire.

rule "E27 EXPIRE"
when
    Item E27_expire changed to ON  // Xiaomi MiniSwitch2 (Round)
then
    switch EG_az_l_e27fassung1.state {
        case OFF : {
            EG_az_l_e27fassung1.sendCommand(ON)
        }
        case ON : {
            EG_az_l_e27fassung1.sendCommand(OFF)
        }
    }
end

This will result in always on of the LED, as there is no OFF command for EG_az_l_e27fassung1 .

I was just wondering if it’s possible to do the magic with just one rule or even without any rule …

Yes I forgot to mention the switch case will need to be removed.

rule "E27 EXPIRE"
when
    Item E27_expire changed to ON  // Xiaomi MiniSwitch2 (Round)
then
    if ( EG_az_l_e27fassung1.state == OFF ) {
       EG_az_l_e27fassung1.sendCommand(ON)
    }
end

It still doesn’t work …

The intention of this thread was to find out whether there is an easier way to use the expire binding - the rules in my first post do work.

Sorry if this was somewhat misleading …

The expire binding is normally used so that a rule is not needed e.g. Turn on a light and x time later it automatically turns off. I do not know of an easier way to use this binding as it’s pretty straight forward.

By using profiles, you wouldn’t need a rule or expire.

1 Like

Is it yet possible to use profiles to replace expire? Could you elaborate a bit on this?
And: How to use a link profile on items not linked to any channel (e.g. “proxy items”)?

1 Like

Not yet… look for it or some other replacement for expire in OH 3.0.

Profiles require an Item with Channels.