[SOLVED] Expire Binding with TP-Link HS200

Hi There,

Very new to Openhab and like what I have so far. I have a bunch of TP-Link HS200 switches that are working fine in Openhab. I ran into an issue where I decided to use the expire binding on one of my switches to turn off the entranceway light after 5 minutes as the kids are always leaving it on. I know my syntax is correct because it works flawlessly with TP-Link plugs and bulbs but for some reason on the HS200 switch, it isn’t working properly. If I set the expire to 1 second, it works, 2 seconds it works. 3 seconds it works but takes about 6 seconds before light turns off. 4 seconds and it takes upwards of a minute (not consistent). 5 seconds and more and the light never seems to go off and I have waited for hours to see if the light would go off. Nothing shows up in the logs. Is there something unique about these switches or is there something odd with my implementation.

For the record, I am using Openhab 2.3 Debian snapshot running on a docker in Container Station on a QNAP NAS.

My Things file entry for the switch:
tplinksmarthome:hs200:EntSwitch “Entranceway Switch” [ ipAddress=“”, refresh=5 ]

My Items file entry for the switch:
Switch Entranceway_Switch “Entranceway Switch” [ “Switchable” ] { expire=“5s,command=OFF” , channel=“tplinksmarthome:hs200:EntSwitch:switch” }

Thank you

I’m using an HS100 with a things file like below and no issues with expire.

Thing tplinksmarthome:hs100:f2997757 "Smart Plug" [ ipAdress="", refresh=30, transitionPeriod=2500 ]

Maybe try adding the transition Period to your things file.

I also looked over the doc’s and didn’t find anything about placement of the expire within an item, so you can also try moving it to the end like this:

Switch Entranceway_Switch "Entranceway Switch" [ "Switchable" ] {  channel="tplinksmarthome:hs200:EntSwitch:switch", expire="5s,command=OFF" }

EDIT: Corrected the " " for the item above.

I also have a HS100 plug and don’t have any issues with the expire binding. Only with the HS200. I will try the transitionPeriod though. I have tried both at the beginning and end of the bindings section as well. Thanks for the feedback.


Are you using VSCode with OH extension? I ask b/c when coping your item from above the " " were wrong/funny.

Honestly, I have no idea. I am using WinSCP to access the file structure and files. Whatever SCP uses for a file editor is what I am using. I am not sure how to paste code into this community forum. Sorry that is very new to me.


If there were an issue with the " " in the file I would think the logs would show an error.:thinking:

You may be comfortable with WinSCP but VSCode with the OH extension is worth looking into, great tool for creating and editing OH files. Even bigger help when writing rules.:grinning:

Also another tip for posting items, things, rules, sitemaps on the forum is to use code fences. Second icon from the right (paper looking icon) when posting. Helps for reading the info.

From the expire readme:

If another binding is repeatedly updating the state of the item to be the same state it already was, the expiration timer will continue to be reset into the future.

I think that is what is happening. The refresh of the HS200 resets the expire binding. When they are almost the same, like 4s expire it’s random luck it is triggered, hence it takes somewhat longer to happen. If the expire time is higher then the refresh time, it will never expire because the expire is reset ever refresh of the HS200 So you need to set the expire time to be less then the refresh time to make it work.


The forum converts standard quotes to “smart” quotes when one pastes in code without using code fences.

@killarneygetaway, I think @hilbrand has the answer. Your switch is reporting it’s state every few seconds and every time it reports it the expire binding is being reset. You will probably need to write a Rule that triggers when your switch changes to ON and set the Timer there.

Hmm . Good thinking. But not the answer I don’t think. I had the refresh higher originally and changed it when I thought it was working. Never thought to change it back. Nonetheless, I have set the refresh set at 300s and the expiry at 10s. Turn light on and it never goes off. Still odd that it works fine with plugs and bulbs and not the switches. I would like someone else who has an HS200 switch to test and confirm for me if it is me or the switch. Hopefully someone else here has one and is willing to test.

Thanks for all the insight. Great community.


Hmm. Just something to check. If you use the switch does openHAB show the correct state? And if you control the switch manually from openHAB does the switch change?

Depending on the refresh value set in “Things”, the state does update within Openhab if I use the switch itself. Currently my refresh rate is 300s so will take up to 5 minutes for the state to update in Openhab. Yes, if I turn on or off the light switch from Openhab, the switch state does change.

This is probably just a typo but your missing Thing in the post above. Not trying to nit-pick but sometimes its the little things that cause the biggest headache.:grinning:

1 Like

OMG. I totally missed that. That my friend may be the solution. More testing is needed but thus far it looks like it. That and the refresh rate. It would appear that I need to set my refresh rate 1 second more than the expire rate.

Thank you all for your assistance. This is a great leap forward for me. I have been working on this for 2 weeks trying to figure it out. All because of a syntax error.

Thank you again,

Gotta watch the small things.:wink:

I’m surprised a warning or error, regarding the things file, didn’t pop up in the logs.

After testing to verify the switch/binding is working, please mark the thread solved by clicking the square box (lower right side) on the post that provided the solution.