Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zigbee] Add a color temperature absolute channel #868

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions org.openhab.binding.zigbee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand All @@ -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 | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Temperature> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,8 +267,6 @@ private void determineMinMaxTemperature(ZclColorControlCluster serverClusterColo
} else {
kelvinMax = miredToKelvin(minTemperatureInMired);
}

kelvinRange = kelvinMax - kelvinMin;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down