Searching for a getSate() function

195 views
Skip to first unread message

Tim Oberföll

unread,
Jul 30, 2015, 8:39:01 AM7/30/15
to openhab2

Hi!

I'm looking for a way to get the current "state" of a channel. To set the state of an channel i use:

updateState(channel, State);

but how do I read the state? For example if I have a thing connected to a channel that displays 25°C, how am I able to read the value "25"?

Greetings,
Tim

Kai Kreuzer

unread,
Jul 30, 2015, 8:56:53 AM7/30/15
to open...@googlegroups.com
Where would you want to do so?
To the „external“ world, items are the entities that store the states and that are used by rules and UIs.

Regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab2+u...@googlegroups.com.
To post to this group, send email to open...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab2/ee05e84a-7987-4d53-ad9c-6e2cca747344%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Oberföll

unread,
Jul 30, 2015, 9:03:00 AM7/30/15
to openhab2, k...@openhab.org
I would like to implement that in my BaseThingHandler or BaseBridgeHandler, so it is part of the binding not the "external" world.

Greetings,
Tim

Kai Kreuzer

unread,
Jul 30, 2015, 9:19:37 AM7/30/15
to Tim Oberföll, openhab2
Then your binding can simply internally cache all the values it thinks it needs to keep; there is no such mechanism, since usually a binding should only act upon events and forward them from the physical device to the event bus and vice versa.

Regards,
Kai

Tim Oberföll

unread,
Jul 30, 2015, 9:40:41 AM7/30/15
to openhab2, k...@openhab.org
Hm okay, but I want that (changing) value to persist during restarts of OpenHAB and thought about using the persistence addons.

Maybe I'm on the wrong way. What I like to to do is:

I've a thing, a power pulsemeter, that counts pulses from an energy meter. The thing knows how to calculate these pulses into the amount of energy used. While running, the thing reports the amount of energy used and the pulse count since installation. The thing itself is not able to remember the amount of energy used or the pulsecount, so after a restart of the thing, it knows nothing. When the thing gets restartet it asks the Controller/OpenHAB to deliver the last known pulsecount and starts working based on that information.
So I'm able to store the pulsecount in OpenHAB (updateState), but I can't read it? If I cache the value in the binding, the value don't persist during a restart of OpenHAB.

Do you have a suggestion how to solve that?

Greetings,
Tim

Kai Kreuzer

unread,
Jul 30, 2015, 10:01:11 AM7/30/15
to open...@googlegroups.com
Well, I guess the best solution is to acknowledge that your hardware is not capable to provide anything more than a pulse and hence not to pretend your Thing is able to.

The „pulse count“ is rather a feature of your application that you are building and not of your Thing. So you should put this logic into a rule, not in the binding. Having it in the binding, it would somehow suggest that it is the number of pulses since installation - which is not true as it won’t count all the pulses while openHAB is down or the device is offline for some reason.

Regards,
Kai


Tim Oberföll

unread,
Jul 31, 2015, 1:46:47 AM7/31/15
to openhab2, k...@openhab.org
Hey Kai,

thank you for your response!

Greetings,
Tim
Reply all
Reply to author
Forward
0 new messages