.state vs. .getstate()

Hi all

I am on Openhab 3.2, running in Windows 10

I have a rule that is based on the state of a TV (ON/OFF), Openhab does not always store the correct state so using (TVname.state == ON) does not work reliably. I am not at all familiar with object based programing but I have seen a function .getstate() so before I start trying to figure out how to use this, can someone tell me if this will query the TV or the binding directly or will it just lookup the state stored by Openhab?

If it will just report the stored state, is there a way to query the TV for its actual ON/OFF state

Thank you

What language?

In Rules DSL TVname.state and TVname.getState() are literally the same thing. Rules DSL provides some “syntactic sugar” to call so called “getters” like getState() as if it wasn’t a function call.

In other rules languages it’s different and I’d need to know the language to answer.

To answer your wider question, there is no mechanism to “query the TV or the binding directly” through an Item like that. Many binding support a REFRESH command which can cause the binding to go out and query the end device, but not all (or even many) bindings/technologies support that. You’d have to read the binding docs and/or experiment to see if your binding does respond to the REFRESH command.

Note though that it will all happen asynchronously. You’ll send the REFRESH command to the Item and that call will immediately return. The processing of that command and ultimate update of the Item’s state will happen in the background while the rest of your rule runs. So you won’t be able to immediately check the state of the Item and get the refreshed state.

Over all, it seems like your time might be better spent figuring out why the state is not always correct. There is no reason why that should be the case.

Thank you
It was Rules DSL
I’ll try to figure out why the state does not get updated in Openhab consistently