diff --git a/org.openhab.binding.zigbee/README.md b/org.openhab.binding.zigbee/README.md index 5da806313..0eae505b1 100644 --- a/org.openhab.binding.zigbee/README.md +++ b/org.openhab.binding.zigbee/README.md @@ -384,20 +384,22 @@ A set of channels will be created depending on what clusters and endpoints a dev The following channels are supported -: -| Channel UID | ZigBee Cluster | Type | Description | +| Channel Type ID | ZigBee Cluster | Type | Description | | ---------------------------- | ---------------------------------------- | ------------------------ | ----------- | | battery-level | `POWER_CONFIGURATION` (0x0001) | Number | | | battery_voltage | `POWER_CONFIGURATION` (0x0001) | Number:ElectricPotential | | | binaryinput | `BINARY_INPUT__BASIC` (0x000F) | Switch | | | color_color | `COLOR_CONTROL` (0x0300) | Color | | -| color_temperature | `COLOR_CONTROL` (0x0300) | Dimmer | | +| color-temperature | `COLOR_CONTROL` (0x0300) | Dimmer | Percent | +| color-temperature-abs | `COLOR_CONTROL` (0x0300) | Number:Temperature | Absolute | | door_state | `DOOR_LOCK` (0x0101) | Switch | | | electrical_activepower | `ELECTRICAL_MEASUREMENT` (0x0B04) | Number:Power | | | electrical_rmscurrent | `ELECTRICAL_MEASUREMENT` (0x0B04) | Number:ElectricCurrent | | | electrical_rmsvoltage | `ELECTRICAL_MEASUREMENT` (0x0B04) | Number:ElectricPotential | | | fancontrol | `FAN_CONTROL` (0x0202) | Number | | -| ias_codetector | `IAS_ZONE` (0x0500) | Switch | | +| ias_cosensor | `IAS_ZONE` (0x0500) | Switch | | | ias_contactportal1 | `IAS_ZONE` (0x0500) | Switch | | +| ias_contactportal2 | `IAS_ZONE` (0x0500) | Switch | | | ias_fire | `IAS_ZONE` (0x0500) | Switch | | | ias_motionintrusion | `IAS_ZONE` (0x0500) | Switch | | | ias_motionpresence | `IAS_ZONE` (0x0500) | Switch | | @@ -406,7 +408,7 @@ The following channels are supported -: | ias_movement | `IAS_ZONE` (0x0500) | Switch | | | ias_vibration | `IAS_ZONE` (0x0500) | Switch | | | ias_tamper | `IAS_ZONE` (0x0500) | Switch | | -| ias_tamper | `IAS_ZONE` (0x0500) | Switch | | +| low-battery | `POWER_CONFIGURATION` (0x0001) | Switch | | | measurement_illuminance | `ILLUMINANCE_MEASUREMENT` (0x0400) | Number | | | measurement_pressure | `PRESSURE_MEASUREMENT` (0x0403) | Number:Pressure | | | measurement_relativehumidity | `RELATIVE_HUMIDITY_MEASUREMENT` (0x0405) | Number | | diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeBindingConstants.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeBindingConstants.java index 6d62823d4..08ece6f24 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeBindingConstants.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeBindingConstants.java @@ -58,6 +58,9 @@ public class ZigBeeBindingConstants { public static final String CHANNEL_LABEL_COLOR_TEMPERATURE = "Color Temperature"; public static final ChannelTypeUID CHANNEL_COLOR_TEMPERATURE = SYSTEM_COLOR_TEMPERATURE.getUID(); + public static final String CHANNEL_NAME_COLOR_TEMP_ABSOLUTE = "colortempabsolute"; + public static final ChannelTypeUID CHANNEL_COLOR_TEMP_ABSOLUTE = SYSTEM_COLOR_TEMPERATURE_ABS.getUID(); + public static final String CHANNEL_NAME_ILLUMINANCE_VALUE = "illuminance"; public static final String CHANNEL_LABEL_ILLUMINANCE_VALUE = "Illuminance"; public static final ChannelTypeUID CHANNEL_ILLUMINANCE_VALUE = new ChannelTypeUID("zigbee:measurement_illuminance"); @@ -147,7 +150,7 @@ public class ZigBeeBindingConstants { public static final String CHANNEL_NAME_POWER_BATTERYPERCENT = "batterylevel"; public static final String CHANNEL_LABEL_POWER_BATTERYPERCENT = "Battery Level"; - public static final ChannelTypeUID CHANNEL_POWER_BATTERYPERCENT = new ChannelTypeUID("system:battery-level"); + public static final ChannelTypeUID CHANNEL_POWER_BATTERYPERCENT = SYSTEM_CHANNEL_BATTERY_LEVEL.getUID(); public static final String CHANNEL_NAME_POWER_BATTERYVOLTAGE = "batteryvoltage"; public static final String CHANNEL_LABEL_POWER_BATTERYVOLTAGE = "Battery Voltage"; diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTempAbsolute.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTempAbsolute.java new file mode 100644 index 000000000..e6bf6dd5f --- /dev/null +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTempAbsolute.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.zigbee.internal.converter; + +import java.math.BigDecimal; + +import org.openhab.binding.zigbee.ZigBeeBindingConstants; +import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; +import org.openhab.core.library.types.QuantityType; +import org.openhab.core.library.unit.Units; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.thing.binding.builder.ChannelBuilder; +import org.openhab.core.types.Command; +import org.openhab.core.types.StateDescriptionFragmentBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zsmartsystems.zigbee.ZigBeeEndpoint; +import com.zsmartsystems.zigbee.zcl.ZclAttribute; +import com.zsmartsystems.zigbee.zcl.clusters.ZclColorControlCluster; +import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToColorTemperatureCommand; +import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType; + +/** + * Channel converter for absolute color temperature based on {@link ZigBeeConverterColorTemperature}, that converts + * between the color control cluster and a QuantityType channel. + * + * @author Andrew Fiddian-Green - Initial Contribution + */ +public class ZigBeeConverterColorTempAbsolute extends ZigBeeConverterColorTemperature { + + private Logger logger = LoggerFactory.getLogger(ZigBeeConverterColorTempAbsolute.class); + + @Override + public boolean initializeConverter(ZigBeeThingHandler thing) { + if (super.initializeConverter(thing)) { + stateDescription = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.valueOf(kelvinMin)) + .withMaximum(BigDecimal.valueOf(kelvinMax)).withStep(BigDecimal.valueOf(100)).withPattern("%.0f K") + .build().toStateDescription(); + return true; + } + return false; + } + + @Override + public void handleCommand(final Command command) { + if (command instanceof QuantityType quantity) { + QuantityType mired = quantity.toInvertibleUnit(Units.MIRED); + if (mired != null) { + MoveToColorTemperatureCommand zclCommand = new MoveToColorTemperatureCommand(mired.intValue(), 10); + monitorCommandResponse(command, clusterColorControl.sendCommand(zclCommand)); + } + return; + } + super.handleCommand(command); + } + + @Override + public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { + return super.getChannel(thingUID, endpoint) == null ? null + : ChannelBuilder + .create(createChannelUID(thingUID, endpoint, + ZigBeeBindingConstants.CHANNEL_NAME_COLOR_TEMP_ABSOLUTE), + ZigBeeBindingConstants.ITEM_TYPE_NUMBER_TEMPERATURE) + .withType(ZigBeeBindingConstants.CHANNEL_COLOR_TEMP_ABSOLUTE) + .withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_COLOR_TEMPERATURE) + .withProperties(createProperties(endpoint)).build(); + } + + @Override + public void attributeUpdated(ZclAttribute attribute, Object val) { + if (attribute.getClusterType() == ZclClusterType.COLOR_CONTROL + && attribute.getId() == ZclColorControlCluster.ATTR_COLORTEMPERATURE) { + logger.debug("{}: ZigBee attribute reports {} on endpoint {}", endpoint.getIeeeAddress(), attribute, + endpoint.getEndpointId()); + if (val instanceof Integer mired) { + updateChannelState(QuantityType.valueOf(mired, Units.MIRED)); + } + return; + } + super.attributeUpdated(attribute, val); + } +} diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTemperature.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTemperature.java index d1ba182ae..9db51d501 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTemperature.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterColorTemperature.java @@ -52,12 +52,11 @@ public class ZigBeeConverterColorTemperature extends ZigBeeBaseChannelConverter private Logger logger = LoggerFactory.getLogger(ZigBeeConverterColorTemperature.class); - private ZclColorControlCluster clusterColorControl; + protected ZclColorControlCluster clusterColorControl; private ZclOnOffCluster clusterOnOff; - private double kelvinMin; - private double kelvinMax; - private double kelvinRange; + protected double kelvinMin; + protected double kelvinMax; // Default range of 2000K to 6500K private final Integer DEFAULT_MIN_TEMPERATURE_IN_KELVIN = 2000; @@ -268,8 +267,6 @@ private void determineMinMaxTemperature(ZclColorControlCluster serverClusterColo } else { kelvinMax = miredToKelvin(minTemperatureInMired); } - - kelvinRange = kelvinMax - kelvinMin; } /** diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeDefaultChannelConverterProvider.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeDefaultChannelConverterProvider.java index d02ef25e3..ce9756208 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeDefaultChannelConverterProvider.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeDefaultChannelConverterProvider.java @@ -39,6 +39,7 @@ public ZigBeeDefaultChannelConverterProvider() { // Add all the converters into the map... channelMap.put(ZigBeeBindingConstants.CHANNEL_COLOR_COLOR, ZigBeeConverterColorColor.class); channelMap.put(ZigBeeBindingConstants.CHANNEL_COLOR_TEMPERATURE, ZigBeeConverterColorTemperature.class); + channelMap.put(ZigBeeBindingConstants.CHANNEL_COLOR_TEMP_ABSOLUTE, ZigBeeConverterColorTempAbsolute.class); channelMap.put(ZigBeeBindingConstants.CHANNEL_DOORLOCK_STATE, ZigBeeConverterDoorLock.class); channelMap.put(ZigBeeBindingConstants.CHANNEL_ELECTRICAL_ACTIVEPOWER, ZigBeeConverterMeasurementPower.class); channelMap.put(ZigBeeBindingConstants.CHANNEL_HUMIDITY_VALUE, ZigBeeConverterRelativeHumidity.class);