# Expire binding - how to streamline the code

**URL:** <https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053>\
**Category:** Scripts & Rules\
**Tags:** expire-binding\
**Created:** [January 10, 2020, 3:34pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053 "2020-01-10T15:34:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selter](https://community.openhab.org/user_avatar/community.openhab.org/selter/32/25134_2.png) [@Selter](https://community.openhab.org/u/Selter)\
**Post date:** [January 10, 2020, 3:34pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/1 "2020-01-10T15:34:34Z")

</div>

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?

```csv
// 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" }

```

```php
// 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

```

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [January 10, 2020, 3:40pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/2 "2020-01-10T15:40:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Selter](https://community.openhab.org/user_avatar/community.openhab.org/selter/32/25134_2.png) [@Selter](https://community.openhab.org/u/Selter)\
**Post date:** [January 10, 2020, 4:04pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/3 "2020-01-10T16:04:24Z")

</div>

> [@H102](#):
>
> Try using **Item E27\_expire changed to ON** in the rule

```php
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 …

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [January 10, 2020, 4:08pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/4 "2020-01-10T16:08:47Z")

</div>

> [@Selter](#):
>
> This will result in always on of the LED, as there is no OFF command for `EG_az_l_e27fassung1` .

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

```csv
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

```

---

<div class="post-metadata">

**Author:** ![Selter](https://community.openhab.org/user_avatar/community.openhab.org/selter/32/25134_2.png) [@Selter](https://community.openhab.org/u/Selter)\
**Post date:** [January 10, 2020, 4:40pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/5 "2020-01-10T16:40:00Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [January 10, 2020, 4:43pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/6 "2020-01-10T16:43:53Z")

</div>

> [@Selter](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [January 10, 2020, 4:57pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/7 "2020-01-10T16:57:27Z")

</div>

By using [profiles](https://www.openhab.org/docs/configuration/items.html#profiles), you wouldn’t need a rule or expire.

---

<div class="post-metadata">

**Author:** ![curlyel](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/71e660/32.png) [@curlyel](https://community.openhab.org/u/curlyel)\
**Post date:** [January 11, 2020, 7:43am UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/8 "2020-01-11T07:43:15Z")

</div>

> [@](#):
>
> By using [profiles](https://www.openhab.org/docs/configuration/items.html#profiles), you wouldn’t need . . . expire.

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”)?

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [January 11, 2020, 6:15pm UTC](https://community.openhab.org/t/expire-binding-how-to-streamline-the-code/90053/9 "2020-01-11T18:15:00Z")

</div>

> [@curlyel](#):
>
> Is it yet possible to use profiles to replace expire?

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

> [@curlyel](#):
>
> And: How to use a link profile on items _not_ linked to any channel (e.g. “proxy items”)?

Profiles require an Item with Channels.
