Creating dynamic channels of type Trigger

I need to create channels dynamically. Using the code below this works fine with standard State channels, but creating a trigger channel also results in a State channel to acceptableType Strong even kind Trigger is specified. I want to use the pre-defined typeId “system.button” (system:button)

    private static void addChannel(Thing thing, Map<String, Channel> newChannels, boolean supported, String group,
            String channelName) throws IllegalArgumentException {
        if (supported) {
            String channelId = group + "#" + channelName;
            ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);
            ShellyChannel channelDef = getDefinition(channelId);
            if (channelDef != null) {
                ChannelTypeUID channelTypeUID = channelDef.typeId.contains("system:")
                        ? new ChannelTypeUID(channelDef.typeId)
                        : new ChannelTypeUID(BINDING_ID, channelDef.typeId);
                Channel channel;
                if (channelDef.typeId.equalsIgnoreCase("system:button")) {
                    channel = ChannelBuilder.create(channelUID, ITEMT_STRING).withKind(ChannelKind.TRIGGER)
                            .withType(channelTypeUID).build();
                } else {
                    channel = ChannelBuilder.create(channelUID, channelDef.itemType).withType(channelTypeUID).build();
                }
                newChannels.put(channelId, channel);
            }
        }
    }

I looked to some other bindings, looks very similar, but not in my case. I removed the static channel definitions from the xml and deleted the thing several times. Channels get created, trigger channel has the right name, but is created as State channel of type Strong.

<thing-type id="shellydimmer2">
		<label>Shelly Dimmer 2 (SHDM-2)</label>
		<description>Shelly Dimmer 2</description>
		<category>DimmableLight</category>
		<channel-groups>
			<channel-group id="relay" typeId="dimmerChannel"/>
			<channel-group id="meter" typeId="meter"/>
			<channel-group id="device" typeId="deviceStatus"/>
		</channel-groups>

		<representation-property>deviceName</representation-property>
		<config-description-ref uri="thing-type:shelly:dimmer"/>
	</thing-type>

	<channel-group-type id="dimmerChannel">
		<label>Dimmer</label>
		<description>A Shelly Dimmer channel</description>
		<!--  channels>
			<channel id="brightness" typeId="dimmerBrightness"/>
			<channel id="input1" typeId="inputState1"/>
			<channel id="input2" typeId="inputState2"/>
			<channel id="button" typeId="system.button"/>
			<channel id="autoOn" typeId="timerAutoOn"/>
			<channel id="autoOff" typeId="timerAutoOff"/>
		</channels -->
	</channel-group-type>

(note the XML comment around the old channel definition)

Any hint welcome. Is it required to have a StateDescriptionProvider to create a Trigger channel?

@cweitkamp Could you help?

Hi Markus,

From which class do you create the new Channel? From the handler? If so I would suggest to use the callback.createChannelBuilder(ChannelUID, ChannelTypeUID) method instead of the ChannelBuilder directly. What happens if you do not pass the acceptedItemType and use ChannwlBuilder.create(ChannleUID):

No. A Trigger Channel is stateless.

found it, chaging code to

ChannelBuilder.create(channelUID, null).withKind(ChannelKind.TRIGGER) .withType(channelTypeUID).build();

did it

@cweitkamp thanks

Good to know. Did you check on the way to use the callback too?

nope, this is a static class, callback is provided by the ThingHandler, correct?

Yes, that is correct.