Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse SmartHome » list of channels(Determine if any item is interested in an event)
list of channels [message #1746819] Sat, 05 November 2016 01:12 Go to next message
Bernhard Boser is currently offline Bernhard BoserFriend
Messages: 2
Registered: November 2016
Junior Member
How do I get a listing of all channels linked to a thing?

I tried overriding
channelLinked

in the ThingHandler of my binding, but it is never called. (though I do have channels linked to my binding and receive commands and can update their status).

Background:

I am trying to connect OH2 to a security system that has lots of "items" with all sorts of properties.

Defining a channel for all of these in thing-types.xml (following the yahooweatherchannel example) is therefore impossible. Instead, I'd like to just send updates to linked channels and determine what events they are interested in from the channel argument.

Concerning channel parameters I have a 2nd question:

How do I specify parameters of the events an item is interested in? OH1 apparently was rather flexible in the channel syntax (or whatever it was called there), permitting e.g. things like
nx584="addr=4F:8D:73,partition=3"

OH2 has a more restrictive syntax. I've used workarounds like
channel="nx584:security:x:addr#4F:8D:73#partition#3"


Is there a better way to accomplish this?
Re: list of channels [message #1746878 is a reply to message #1746819] Mon, 07 November 2016 08:30 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 661
Registered: December 2011
Senior Member
Hi Bernhard,

The channelLinked() method is the right place to be informed about newly linked channels - it definitely is called by the framework!

Besides this, you can at any time call "isLinked(String channelId)" to see whether you need to send updates for a certain channel. The full list of channels that are defined on the Thing (independent of whether they are coming through the thing type definition or through a user configuration) is available through "getThing().getChannels()".

Regarding channel parameters, you need to note that those are configured in the Thing definition, e.g. within the *.things files. The *.items file that you refer to above only hold a reference to a channel, but no further details. You might also want to read http://docs.openhab.org/tutorials/migration#understanding-things to better understand this change from OH1 syntax to OH2 syntax.

Regards,
Kai
Re: list of channels [message #1746925 is a reply to message #1746878] Mon, 07 November 2016 17:58 Go to previous messageGo to next message
Bernhard Boser is currently offline Bernhard BoserFriend
Messages: 2
Registered: November 2016
Junior Member
Hi Kai,

Many thanks for the quick response. It's incredible how you manage to personally respond to these questions.

Kai Kreuzer wrote on Mon, 07 November 2016 08:30
The channelLinked() method is the right place to be informed about newly linked channels - it definitely is called by the framework!


This method is never called in my OH2 binding (the IDE marks it correctly as overloaded).

Quote:
The full list of channels that are defined on the Thing (independent of whether they are coming through the thing type definition or through a user configuration) is available through "getThing().getChannels()".


"getThing().getChannels().size()" is always zero, no matter when I call it (I've even added a special "switch" that let's me call it from the gui).

But the links are definitely created. In the log, just after startup, I first see the links (from my items file), e.g.
09:34:23.297 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'doorStairs-nx584:security:creston:zone18#status' has been added.

and a bit later the thing (from my thing file):
09:34:28.919 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'nx584:security:creston' has been added.

The binding sends updates to these links (or channels, are they the same?) and the sitemap is updated as expected.

I did not define the channels in the thing_types.xml file, just in the items file.

Quote:
Regarding channel parameters, you need to note that those are configured in the Thing definition, e.g. within the *.things files. The *.items file that you refer to above only hold a reference to a channel, but no further details. You might also want to read http://docs.openhab.org/tutorials/migration#understanding-things to better understand this change from OH1 syntax to OH2 syntax.

Regards,
Kai

I've read the tutorial and though it does make sense for the weather binding, I to see how to best deal with the following case: The ISY binding (currently unresolved PR, OH1) identifies lights with 2 addresses (has to do with Insteon - I can go into details). Per the tutorial, these should be parameters and specified in the .things file. Since each address combination represents a single light (precisely, scene), there is now a 1-to-1 correspondence between things and items! While possible, this would add significant redundancy to the user configuration.

Regards,
Bernhard
Re: list of channels [message #1746973 is a reply to message #1746925] Tue, 08 November 2016 09:00 Go to previous message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 661
Registered: December 2011
Senior Member
Quote:
did not define the channels in the thing_types.xml file, just in the items file.


The important part is the *.things file - this is where you need to define the channels - if you do not define any, it is clear that getChannels().size() is always 0.

See here for details: https://www.eclipse.org/smarthome/documentation/features/dsl.html#thing-configuration-dsl

Quote:
there is now a 1-to-1 correspondence between things and items!


Well, if your physical "thing" (the light) only provides a single functionality, then this is as it is.

Your other option is to treat the external system as a single Thing with one channel per light/functionality.

Which is the better approach depends on the capabilities of your system. Having separate Things is especially helpful, if you can easily discover newly added devices.

A similar discussion is done around KNX, maybe this helps to get a better understanding.

Regards,
Kai
Previous Topic:REST : ItemResource : only PUT to update state?
Next Topic:newbie needs help starting binding
Goto Forum:
  


Current Time: Fri Nov 16 14:28:00 GMT 2018

Powered by FUDForum. Page generated in 0.01693 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top