Item states


I have a nexa 433mhz controller that I was thinking of using to trigger rules or scripts on my openhab server. But I ran in to an issue were the system checks to see if the state is updated and if so says it changed from ON to OFF or from OFF to ON.

What I want it to do is send the command OFF or ON when I press OFF or ON on my remote no matter what it was the last time I pressed it. I tried including the rule to change the state to NULL, but it went and checked the thing and changed it self back to ON or OFF. When I send a command through the sitemap it does correctly what I want, if it says ON and I press ON it runs the rule as if it was OFF and tries to turn everything ON.

Is there a solution to this? If not do any of you have experience with using an ON/OFF remote to trigger rules and scripts? What is the best route?

Thanks, Vegard

It’s difficult to comment on invisible rules.

There are a lot of “it” in your description, and it’s not clear what you are talking about.
Let’s try to find out what “it” we have to begin with.
How many Items do you have involved here - one for light, one for remote-ON, one for remote-OFF perhaps?

Sorry for not defining everything.
So I have a rule which turns on my light and computer when triggered. And I have another rule for turning the computer and lights off.

What I want to do is when I press ON on my NEXA remote it calls the rule which turns ON the computer and lights. When I press OFF on my NEXA remote I want it to call the rule that turns OFF my computer and lights.

I have one item for computer, one for lights and one for the remote, all of which can be turned ON or OFF.

Can you tell us or show us how this one Item linked to your remote works? When you press on-button, Item changes to state ON? And Item stays ON until you press off-button?

It’s still not possible to comment on your invisible rule.

Yes I have one Item that cahges from ON to OFF or OFF to ON when I press ON/OFF button on remote.

Here is the code of my rule if that is what you want:
rule “PC_ONOFF”

Item PC_ON received command
if (PC_ON.state==ON) {
TaklampeKjeller_Dimmer.sendCommand(new PercentType(70))
else if (PC_ON.state==OFF) {

Alright. The problem with that is that two ON presses are undetectable - say you use the remote ON, something else to OFF - you cannot ON from the remote now.

I’d approach it by changing that remote Item so that it mimics the buttons more closely - like a press-then-release action.
We can cheat a bit because a Switch type Item can have states NULL or UNDEF as well as OFF and ON. So we can make a kind of three position switch.

The easiest way to do that is to use expire to set the Item state to UNDEF state after a second or two. Exactly how you do that depends on if you are using OH2 or OH3.

When that is done, you should have an Item that changes to ON for on-button, and returns to UNDEF after a time. So you can press ON more than once with no OFF in between.

Then you can have a rule that triggers from change. If state ON, do this, else if state OFF do that, else do nothing (ignore change to UNDEF).

You will want to check that you donot have this Item using restore-on-startup, because you don’t want to remember old presses.

Thanks a lot, I think this will solve my problem and at least be a starting point. I need to go to bed now but will continue on this tomorrow after work. I will update you on how its going.

Thanks again for the help so far!

Hi again

I have now been looking at this for a bit. I am currently using OH2 planning on upgrading to OH3 in the near future, but I want to build the setup from scratch so I need a bit more time then I have now.

How do I do this in Openhab2? Is it by using the expire binding addon or can I define it in the rule?


expire is easier for simple timing needs.

Sorry, I dont unsterstand how I define it in the rule. Can you give me an example?

So I solved my issue by using postUpdate(UNDEF), but if you can tell me how the expire addon works I would appreciate that as I could use it instead of the timers I have made for other rules

I read this, but if I understand it correctly I need to define the item in a items file and tell it to expire there? And not call a expire in the rule file?

Yes. It’s a version 1 binding, so you cannot link it to a Paper UI created Item.

That’s right. Expire binding is autonomous and automatic.

I understand

Thank you!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.