Channels created via ChannelBuilder do not show up in OH3 UI

Hi,

I’m working on a new binding that requires several channels to be created dynamically, based on the feedback from the device.

I followed the example from updating-the-thing-structure and also the implementation from other bindings without success. Bundle loads without warning/exception, goes ONLINE but the channel list only shows the pre-defines static channels from thing-types.xml.

My code:
New Bundle skeleton named “Test” created via script and constructor extended as follows:

    @Override
    public void initialize() {
        config = getConfigAs(TestConfiguration.class);
        updateStatus(ThingStatus.UNKNOWN);

        ThingBuilder thingBuilder = editThing();
        Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), "testChannel"), "String").build();
        thingBuilder.withChannel(channel);
        updateThing(thingBuilder.build());
        
        updateStatus(ThingStatus.ONLINE);
    }

I think you are missing the bindingID as well as type in your call:

Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), “testChannel”), “String”).build();

try something like this:

Channel channel = ChannelBuilder.create(new ChannelUID(“addbindingIDhere”+“String”+thing.getUID(), “testChannel”), “String”).build();

Thx for the reply!
In the meanwhile I got it working:

        logger.warn("Thing UID: {}", thing.getUID());
        ChannelTypeUID channelTypeUID = new ChannelTypeUID("test:sample-channel");
        Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), "testChannel"), "Number:Temperature")
                .withType(channelTypeUID).withKind(ChannelKind.STATE).withLabel("label").build();

        ThingBuilder thingBuilder = editThing();
        thingBuilder.withoutChannel(channel.getUID());
        logger.warn("Channel UID: {}", channel.getUID());
        thingBuilder.withChannel(channel);
        updateThing(thingBuilder.build());

I guess the missing (or invalid) ChannelType caused the problem. In the above example the ChannelType is defined via thing-types.xml.

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