Setting Semantic Class from Binding

In my Binding, I am creating groups of channels based on the configuration I obtain from the device.

For me, this is groups of Air-Conditioner Units and their channels, and Air-Conditioner Zones and their applicable channels.

I am configuring the channel-types in things-types.xml, and then creating channels after retrieving the properties of the unit.

example:

	<channel-type id="airconditioner-zone-temperature">
		<item-type>Number:Temperature</item-type>
		<label>Zone Temperature</label>
		<description>The temperature as measured by the Zone. Typically read via a device located in the room.</description>
		<category>Temperature</category>
	</channel-type>

I am then creating the channel in code like this…

        Channel channelZoneTemperature = ChannelBuilder
                .create(new ChannelUID(channelGroupUID, "airconditioner-zone-temperature"))
                .withLabel(String.format("Zone Temperature - %s", zoneName))
                .withType(new ChannelTypeUID(AirTouchBindingConstants.BINDING_ID,
                        "airconditioner-zone-temperature"))
                .build();
        thingBuilder.withChannel(channelZoneTemperature);

This is working great. However when I create the item from the channel, I have to remember to set the Semantic Class and Semantic Property as per this screenshot.

Each Zone has a number different properties (eg, on/off, mode, setpoint, temperature, battery low, damper open percentage), and from experimentation they all appear to have different semantic values so that they appear sensibly on the cards in the UI.

image

I keep forgetting which ones have what semantic settings, and I would love to be able to provide sensible defaults for each channel.

Is it possible to set the Semantic Class and/or Semantic Property when creating the Channel?

I’m hoping there is some recommended XML or code that I can use to save my users having to go in and change every new Item. My system will have nearly 50 items, and mine is a small install.

I do not know the answer to this specific question. I know bindings can push State Description Item Metadata but I don’t think I’ve ever seen them push tags.

I personally tend to be somewhat against bindings pushing semantic tags because:

  • the semantic model is optional
  • a sizable portion of Items do not belong in the semantic model in the first place (rule of thumb is about 60% of Items)
  • your choice in default tags may conflict with the approach chosen by the end user, which can become even more pronounced in OH 4 where users will be able to create custom semantic tags.

In short, I tend to be generally against changes that help a few users but at the expense of causing more work for other users.

But I’m just one guy with an opinion. I just want to make sure the full ramifications this feature might impose.

cc @netwolfuk

It is already possible and used e.g. within the OWM Binding

	<channel-type id="carbon-monoxide">
		<item-type>Number:Density</item-type>
		<label>Carbon Monoxide</label>
		<description>Current concentration of carbon monoxide.</description>
		<tags>
			<tag>Measurement</tag>
			<tag>CO</tag>
		</tags>
		<state readOnly="true" pattern="%.1f %unit%"/>
	</channel-type>

See also:

ChannelBuilder has .withDefaultTags(Set<String>). I think you can just add the tags (e.g. Measurement,Property_Temperature) you need with that.