Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Dynamically created channels are not shown
Dynamically created channels are not shown [message #1714505] Fri, 13 November 2015 09:45 Go to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Hello all,

I'm trying to implement a binding which dynamically creates channels as described here: https://www.eclipse.org/smarthome/documentation/development/bindings/thing-handler.html

During runtime the Thing is created just fine, I do not get any error but the Item is not showing any channel in the UI.

What am I doing wrong?!

I've attached the source of my TestHandler and two screenshots showing what I mean...

Thank you and regards,
Osman
  • Attachment: TestHandler.java
    (Size: 1.76KB, Downloaded 257 times)
  • Attachment: s1.png
    (Size: 6.59KB, Downloaded 326 times)
  • Attachment: s2.png
    (Size: 5.58KB, Downloaded 369 times)
Re: Dynamically created channels are not shown [message #1714589 is a reply to message #1714505] Fri, 13 November 2015 17:34 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
I guess it is the same error as discussed here: https://www.eclipse.org/forums/index.php?t=msg&th=1067757&goto=1708449&#msg_1708449

So if you added channels without existing channel types, the Paper UI does not show them. Very recently some PRs were merged which allow better support for dynamic channels. Nevertheless the Paper UI still needs to be adapted for this. I will try to work on that in the next 2 weeks.
Re: Dynamically created channels are not shown [message #1714608 is a reply to message #1714505] Fri, 13 November 2015 20:39 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Dennis, thank you for the hint... it seems to be the same error.

Now, I've defined a channel-type within the XML file
<thing:thing-descriptions bindingId="test" ...
	...
	<channel-type id="temperatureType">
		<item-type>Number</item-type>
		<label>Temperature</label>
		<category>Temperature</category>
		<state step="0.5" pattern="%d °C" readOnly="false" />
	</channel-type>
</thing:thing-descriptions>

... but how do I exactly assign this channel-type to the channel?!

If I'm getting the things right, then there are at least 2 TODOs:
        // TODO: channelType = get a reference to the channel-type "temperatureType"
        ThingBuilder thingBuilder = editThing();
        Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), "1"), "Number").build();
        // TODO: assign channelType to channel
        thingBuilder.withChannel(channel);
        updateThing(thingBuilder.build());


Unfortunatelly I did not find the right API calls to get a reference to this channel-type and I also did not find any method within the ChannelBuilder which would let me assign this channel-type to the newly created channel.

So, could you please help me to find the right way here?!

Appreciate any help on this topic.
Re: Dynamically created channels are not shown [message #1714805 is a reply to message #1714608] Mon, 16 November 2015 20:20 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
The channel builder now has a method "withType" (see https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java#L63). It was intruded on friday last week. With that the channel gets the according type.
Re: Dynamically created channels are not shown [message #1714955 is a reply to message #1714805] Tue, 17 November 2015 22:15 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Cool, thank you for extending the API Smile
So... if I'm getting it right, I could simply reference the channel-type from my XML example file with ... = new ChannelTypeUID("test", "temperatureType"). Right?!

I would have checked this by myself, but actually I don't know how to get the newest ESH release into my OpenHAB2 dev. environment... Do you know, when these helpfull changes will find their way into the OpenHAB2 runtime?!

Thank you again!
Re: Dynamically created channels are not shown [message #1715056 is a reply to message #1714805] Wed, 18 November 2015 21:19 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Hello Dennis,
I just tryed the newly introduced method - unfortunatelly the channel is still not showing Sad

This is the code of my TestHandler Class:

public class TestHandler extends BaseThingHandler {
    private Logger logger = LoggerFactory.getLogger(TestHandler.class);

    public TestHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void initialize() {
        ThingBuilder thingBuilder = editThing();
        ChannelTypeUID channelTypeUID = new ChannelTypeUID("test", "temperatureType");
        Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), "1"), "Number")
                .withType(channelTypeUID).build();
        thingBuilder.withChannel(channel);
        updateThing(thingBuilder.build());

        updateStatus(ThingStatus.ONLINE);
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        // TODO Auto-generated method stub
    }
}


I do not know what I'm doing wrong... So, do you have any hint?

Thanks in advance.
Re: Dynamically created channels are not shown [message #1715143 is a reply to message #1715056] Thu, 19 November 2015 14:59 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Quote:
I just tryed the newly introduced method - unfortunately the channel is still not showing


If you mean it is not shown in the Paper UI, then this is unfortunately expected behavior. As written above (see https://www.eclipse.org/forums/index.php?t=msg&th=1072114&goto=1714589&#msg_1714589), the Paper UI still needs to be adapted for this newly introduced feature. I´m currently working on that.
Re: Dynamically created channels are not shown [message #1715165 is a reply to message #1715143] Thu, 19 November 2015 17:38 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Oh... then I think, we've been talking "leicht aneinander Vorbei" Very Happy
I thought the Paper UI is not showing the channels only because they do not have a channel type... But OK. I'll be waiting for the new Paper UI version.

Again, thank you much.
Re: Dynamically created channels are not shown [message #1715349 is a reply to message #1714805] Sun, 22 November 2015 16:09 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Since I've updated the core I see the Inbox is not working like before.

I'm not really sure if this is the cause:
Dennis Nobel wrote on Mon, 16 November 2015 21:20
The channel builder now has a method "withType" (see https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java#L63).


An approved thing from the inbox appears in the group. But after restarting openHAB the thing is not usable anymore. It's shown in the UI but not in the Configuration -> Things menu. It also cannot be removed from the UI.

This is what I've found in the log file:
2015-11-22 16:42:59 [WARN ] [e.s.storage.mapdb.MapDbStorage:156  ] - Couldn't deserialize value 'org.eclipse.smarthome.core.thing.internal.ThingImpl@@@{"channels":[{"acceptedItemType":"Number","uid":{"segments":["smaenergymeter","energymeter","9999999999","powerIn"]},"channelTypeUID":{"segments":["smaenergymeter","powerInType"]},"configuration":{"properties":{}},"properties":{},"defaultTags":[]},{"acceptedItemType":"Number","uid":{"segments":["smaenergymeter","energymeter","9999999999","powerOut"]},"channelTypeUID":{"segments":["smaenergymeter","powerOutType"]},"configuration":{"properties":{}},"properties":{},"defaultTags":[]},{"acceptedItemType":"Number","uid":{"segments":["smaenergymeter","energymeter","9999999999","energyIn"]},"channelTypeUID":{"segments":["smaenergymeter","energyInType"]},"configuration":{"properties":{}},"properties":{},"defaultTags":[]},{"acceptedItemType":"Number","uid":{"segments":["smaenergymeter","energymeter","9999999999","energyOut"]},"channelTypeUID":{"segments":["smaenergymeter","energyOutType"]},"configuration":{"properties":{}},"properties":{},"defaultTags":[]}],"configuration":{"properties":{"vendor":"SMA","serialNumber":"9999999999","mcastGroup":"239.12.255.254","port":9522,"pollingPeriod":30}},"properties":{"serialNumber":"Serial Number","vendor":"Vendor"},"uid":{"segments":["smaenergymeter","energymeter","9999999999"]},"thingTypeUID":{"segments":["smaenergymeter","energymeter"]}}'. Root cause is: Failed to invoke org.eclipse.smarthome.core.thing.type.ChannelTypeUID() with no args
2015-11-22 16:42:59 [WARN ] [.c.c.r.AbstractManagedProvider:138  ] - Could not update element with key smaenergymeter:energymeter:9999999999 in ManagedThingProvider, because it does not exists.


The behaviour can also be reproduced with other bindings.
Re: Dynamically created channels are not shown [message #1715381 is a reply to message #1715349] Mon, 23 November 2015 07:49 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
I can confirm this. It´s definitely a critical bug coming from the channel type UID change. I´m investigating this.
Re: Dynamically created channels are not shown [message #1715386 is a reply to message #1715381] Mon, 23 November 2015 08:06 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
I found the problem and created a PR: https://github.com/eclipse/smarthome/pull/530

Thank you very much for finding the bug!
Re: Dynamically created channels are not shown [message #1715464 is a reply to message #1715386] Mon, 23 November 2015 20:55 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Thank you for the PR.
I just pulled from master and rebuilt the solution - the bug seems to be still there... or the successor of that bug Sad

Exception: java.lang.RuntimeException: Failed to invoke org.eclipse.smarthome.core.thing.type.ChannelTypeUID() with no args
Root cause: java.lang.IllegalArgumentException: UID must have at least 2 segments.

index.php/fa/24053/0/

The line from the Log file:
2015-11-23 21:54:58 [WARN ] [e.s.storage.mapdb.MapDbStorage:156  ] - Couldn't deserialize value 'org.eclipse.smarthome.core.thing.internal.ThingImpl@@@{"bridgeUID":{"segments":["beckhoff","bridge","a94f2935"]},"channels":[{"acceptedItemType":"Rollershutter","uid":{"segments":["beckhoff","rollershutter","a94f2935","MAIN_fbEg_fbShutter1","channel"]},"channelTypeUID":{"segments":["beckhoff","rollershutter"]},"configuration":{"properties":{}},"properties":{},"defaultTags":[]}],"configuration":{"properties":{"symbolName":"MAIN.fbEg.fbShutter1","forcePolling":false,"pollingPeriod":10}},"properties":{},"uid":{"segments":["beckhoff","rollershutter","a94f2935","MAIN_fbEg_fbShutter1"]},"thingTypeUID":{"segments":["beckhoff","rollershutter"]}}'. Root cause is: Failed to invoke org.eclipse.smarthome.core.thing.type.ChannelTypeUID() with no args

  • Attachment: s.png
    (Size: 118.09KB, Downloaded 1425 times)
Re: Dynamically created channels are not shown [message #1715542 is a reply to message #1715464] Tue, 24 November 2015 10:34 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Hi Osman,

thanks for the feedback. Are you working with ESH directly or with openHAB2? Are you sure you have the latest sources including the fix? I can not reproduce it any more.

Regards

Dennis
Re: Dynamically created channels are not shown [message #1715638 is a reply to message #1715542] Tue, 24 November 2015 21:20 Go to previous messageGo to next message
Osman Basha is currently offline Osman BashaFriend
Messages: 9
Registered: November 2015
Location: Kassel, Germany
Junior Member
Hello Dennis,

you're right - the bug is fixed... Yesterday I pulled the latest sources, but I did not switch the "Run Configuration" to use the plug-ins from the workspace... mea culpa Embarrassed
I'm sorry if it caused trouble to you...

Now I'm waiting for the new Paper-UI update Smile

Thank you and regards,
Osman
Re: Dynamically created channels are not shown [message #1715930 is a reply to message #1715638] Fri, 27 November 2015 23:16 Go to previous messageGo to next message
Chris Jackson is currently offline Chris JacksonFriend
Messages: 256
Registered: December 2013
Senior Member
Hi Dennis,
Am I correct in assuming that for channels generated outside of the XML, the issue is that the channel information doesn't appear in the thingType? Does this require a new REST endpoint (I'm not quite sure where this information is coming from otherwise?).

On a separate (but related) question - when generating channels like this, I assume there's no item automatically generated - this might get confusing for users?

Chris
Re: Dynamically created channels are not shown [message #1715959 is a reply to message #1715930] Sun, 29 November 2015 12:30 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Hi Chris,

Quote:
Am I correct in assuming that for channels generated outside of the XML, the issue is that the channel information doesn't appear in the thingType?


You are correct. We are missing the ChannelType REST endpoint.

Quote:
On a separate (but related) question - when generating channels like this, I assume there's no item automatically generated - this might get confusing for users?


Maybe it is confusing for the users, but I think it would be sufficient to show the channel in the Paper UI and give the user the change to enable it manually. However the automatic generation is a feature of the Paper UI and not of the ESH core. With the recently introduced advanced mode, you now have the possibility to link your channel to existing items.

@Osman: Unfortunately I failed to implement it before I´m leaving for a long vacation now. If you need this feature immediately you may implement it yourself and contribute it to the Paper UI or you have to wait a few weeks until I´m back or someone else will implements it. I´m sorry for this Sad.

Regards

Dennis
Re: Dynamically created channels are not shown [message #1715960 is a reply to message #1715959] Sun, 29 November 2015 12:58 Go to previous messageGo to next message
Chris Jackson is currently offline Chris JacksonFriend
Messages: 256
Registered: December 2013
Senior Member
Thanks Dennis

Quote:

Maybe it is confusing for the users, but I think it would be sufficient to show the channel in the Paper UI and give the user the change to enable it manually.

Agreed - I have this in HABmin, although as there's no channels showing (since the thingType doesn't have them) it doesn't work at the moment...

Regarding the ChannelType REST endpoint implementation, I will likely need to implement this soon so might take a look at it...

(have a good holiday Smile ).

Chris
Re: Dynamically created channels are not shown [message #1716580 is a reply to message #1715960] Sat, 05 December 2015 12:01 Go to previous messageGo to next message
Mattias Tornblad is currently offline Mattias TornbladFriend
Messages: 6
Registered: October 2015
Junior Member
Hello,

Read through this post and found it helpful! Just wanted to add that i think it would be nice to have an option to have the channelbuilder to be called with an argument to autogenerate Items in the same manner as if they had been added through static config files! Why is the automatic generation of items a feature of the Paper UI and not of the ESH core?

//Mattias
Re: Dynamically created channels are not shown [message #1717413 is a reply to message #1716580] Sun, 13 December 2015 10:44 Go to previous messageGo to next message
Markus Rathgeb is currently offline Markus RathgebFriend
Messages: 105
Registered: August 2014
Senior Member

Perhaps you can found the intention here: https://github.com/eclipse/smarthome/pull/671#issuecomment-162810507
Items should be created by the user and not to cover a special device / channel architecture...
Re: Dynamically created channels are not shown [message #1719315 is a reply to message #1717413] Thu, 07 January 2016 07:31 Go to previous messageGo to next message
Marcel Verpaalen is currently offline Marcel VerpaalenFriend
Messages: 59
Registered: September 2014
Member
@Dennis Nobel Hope you had good holidays:)
I've created dynamic channels as well, but they are not showing up yet in PaperUI. Wanted to check on the progress on getting this in paper.
Are they not showing as it has not been implemented yet (hence expected) or some issue on my side?
Re: Dynamically created channels are not shown [message #1734789 is a reply to message #1719315] Sun, 12 June 2016 15:08 Go to previous messageGo to next message
Juergen Messmer is currently offline Juergen MessmerFriend
Messages: 4
Registered: June 2016
Junior Member
Hi,
I have a similar, but slightly different problem.
I am doing a similar thing as Osman:

    public void initialize() {
        logger.debug("Initializing FileRegexParser handler.");
        super.initialize();

        Configuration config = getThing().getConfiguration();

        try {
            fileName = (String) config.get("fileName");

        } catch (Exception e) {
            logger.debug("Cannot set fileName parameter.", e);
        }
        try {
            regEx = (String) config.get("regEx");
            pattern = Pattern.compile(regEx);
        } catch (Exception e) {
            logger.debug("Cannot set regEx parameter.", e);
        }
        matcher = pattern.matcher("");
        groupCount = matcher.groupCount();
        updateState(new ChannelUID(getThing().getUID(), CHANNEL_GROUPCOUNT), new DecimalType(matcher.groupCount()));
        updateStatus(ThingStatus.ONLINE);
        this.thingStructureChanged();

    }

      protected void thingStructureChanged() {
        ThingBuilder thingBuilder = editThing();
        Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), "test1"), "String").build();
        thingBuilder.withChannel(channel);
        updateThing(thingBuilder.build());
    }



This works and adds the channel "test1" when the thing is created via PaperUI.
If the thing is defined in a .thing file:
fileregexparser:filetoparse:jmefp [fileName="d:\\tmp\\test.txt", regEx="^\\s*(INFO:\\s)test\\s(.*)"]


Then the channel is not added and I get the following error message:

2016-06-12 17:05:34.327 [WARN ] [.c.c.r.AbstractManagedProvider:138  ] - Could not update element with key fileregexparser:filetoparse:jmefp in ManagedThingProvider, because it does not exists.
2016-06-12 17:05:34.331 [ERROR] [.c.thing.internal.ThingManager:699  ] - Exception occured while initializing handler of thing 'fileregexparser:filetoparse:jmefp': java.lang.IllegalStateException: Could not update thing fileregexparser:filetoparse:jmefp. Most likely because it is read-only.java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Could not update thing fileregexparser:filetoparse:jmefp. Most likely because it is read-only.
	at java.util.concurrent.FutureTask.report(Unknown Source)
	at java.util.concurrent.FutureTask.get(Unknown Source)
	at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:179)
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:72)
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:56)
	at org.eclipse.smarthome.core.thing.internal.ThingManager$7.run(ThingManager.java:684)
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
Caused by: java.lang.IllegalStateException: Could not update thing fileregexparser:filetoparse:jmefp. Most likely because it is read-only.
	at org.eclipse.smarthome.core.thing.internal.ThingManager$1.thingUpdated(ThingManager.java:235)
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.updateThing(BaseThingHandler.java:384)
	at org.openhab.binding.fileregexparser.handler.FileRegexParserHandler.thingStructureChanged(FileRegexParserHandler.java:97)
	at org.openhab.binding.fileregexparser.handler.FileRegexParserHandler.initialize(FileRegexParserHandler.java:72)
	at org.eclipse.smarthome.core.thing.internal.ThingManager$7$1.call(ThingManager.java:687)
	at org.eclipse.smarthome.core.thing.internal.ThingManager$7$1.call(ThingManager.java:1)
	at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:170)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)



How is creating the a thing different via PaperUI from creating it via the .items file?

Any idea where the problem is?

Thx, Juergen
Re: Dynamically created channels are not shown [message #1735246 is a reply to message #1734789] Thu, 16 June 2016 15:14 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Things from a DSL are as they are defined - it is not possible to change them in any way through code.

See this discussion: https://www.eclipse.org/forums/index.php/t/1072808/
Re: Dynamically created channels are not shown [message #1735410 is a reply to message #1735246] Sat, 18 June 2016 16:37 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Kai,

Despite all the discussion in the past, I still fail to see why it is not possible to have dynamic channels, configurations and properties for Things that are defined through the DSL. The same question/demand is coming back several times, and every time it is channels/properties/configuration elements that are the result of querying devices and so forth, and that we are all OK with that these are not persisted, and built up after a restart of the runtime.

The counter-arguments are always driven by the presence of a user interface, paperUI notably. Now, not everyone needs or wants paperUI to configure their installation, it is after all an optional component, but it heavily weighs in on other parts of the architecture. That is not logical.

K
Re: Dynamically created channels are not shown [message #1735745 is a reply to message #1735410] Wed, 22 June 2016 11:50 Go to previous message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
> I still fail to see why it is not possible to have dynamic channels, configurations and properties for Things

Well, we already made the step to allow (non-persisted) property updates. So yes, we can extend the discussion to configurations and channels and the "whole" Thing.

> that we are all OK with that these are not persisted, and built up after a restart of the runtime.

I do not recall this having been discussed. Right, if we all agree that we are only talking about not-persisted changes done through the binding, this can be applied to Things from the DSL in the same way.

> The counter-arguments are always driven by the presence of a user interface, paperUI notably.

Do you have a reference to this argument (sorry if I tend to forget my own arguments of past discussions)? For me, the main argument is that you never know what features your Thing actually provides, how it is configured and setup. You need to have this information when you want to link channels to your items, work with it in rules, etc. And you might want to be able to do so, even when you are "offline" (i.e. your environment is not fully up and operational). For thisto work, the persisted Thing is important, because it still exists, even if the binding might not be installed. How you get your Thing displayed, be it through the Paper UI or by console output, does not matter at all. So this is definitely not about the Paper UI - rather the contrary: About the (very desirable) reliability of the content of textual configuration - what we all want to keep from the OH1 world.

Previous Topic:Posting custom command types on the event bus
Next Topic:Usage of Thread Pools
Goto Forum:
  


Current Time: Thu Mar 28 11:16:25 GMT 2024

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

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

Back to the top