Skip to content

Commit 891da2c

Browse files
authored
[avmfritz] Add light blub color temperature support (openhab#14373)
* added light blub color temperature support * align valiable nameing * fixed on off behavior of lights * change to math scaleing * add abs color temperature channel --------- Signed-off-by: Tobias Lange <[email protected]>
1 parent 8a2e8b4 commit 891da2c

File tree

7 files changed

+238
-40
lines changed

7 files changed

+238
-40
lines changed

bundles/org.openhab.binding.avmfritz/README.md

+35-33
Large diffs are not rendered by default.

bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public class AVMFritzBindingConstants {
143143
public static final String CHANNEL_LAST_CHANGE = "last_change";
144144
public static final String CHANNEL_ROLLERSHUTTER = "rollershutter";
145145
public static final String CHANNEL_COLOR = "color";
146+
public static final String CHANNEL_COLORTEMPERATURE = "color_temperature";
147+
public static final String CHANNEL_COLORTEMPERATURE_ABS = "color_temperature_abs";
146148
public static final String CHANNEL_BRIGHTNESS = "brightness";
147149
public static final String CHANNEL_ON_OFF = "on_off";
148150

bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java

+102-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,50 @@
1212
*/
1313
package org.openhab.binding.avmfritz.internal.handler;
1414

15-
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
16-
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.*;
15+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.BINDING_ID;
16+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_ACTUALTEMP;
17+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_BATTERY;
18+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_BATTERY_LOW;
19+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_BRIGHTNESS;
20+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_COLOR;
21+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_COLORTEMPERATURE;
22+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_COLORTEMPERATURE_ABS;
23+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_COMFORTTEMP;
24+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_CONTACT_STATE;
25+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_DEVICE_LOCKED;
26+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_ECOTEMP;
27+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_ENERGY;
28+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_HUMIDITY;
29+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_LAST_CHANGE;
30+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_LOCKED;
31+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_MODE;
32+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_NEXTTEMP;
33+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_NEXT_CHANGE;
34+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_OBSTRUCTION_ALARM;
35+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_ON_OFF;
36+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_OUTLET;
37+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_POWER;
38+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_RADIATOR_MODE;
39+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_ROLLERSHUTTER;
40+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_SETTEMP;
41+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_TEMPERATURE;
42+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_TEMPERATURE_ALARM;
43+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CHANNEL_VOLTAGE;
44+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.CONFIG_CHANNEL_TEMP_OFFSET;
45+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_BOOST;
46+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_COMFORT;
47+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_ECO;
48+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_OFF;
49+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_ON;
50+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_UNKNOWN;
51+
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.MODE_WINDOW_OPEN;
52+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.TEMP_FRITZ_MAX;
53+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.TEMP_FRITZ_OFF;
54+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.TEMP_FRITZ_ON;
55+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.TEMP_FRITZ_UNDEFINED;
56+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.fromCelsius;
57+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.normalizeCelsius;
58+
import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.toCelsius;
1759

1860
import java.math.BigDecimal;
1961
import java.time.Instant;
@@ -82,6 +124,8 @@
82124
* @author Christoph Weitkamp - Added support for AVM FRITZ!DECT 300 and Comet DECT
83125
* @author Christoph Weitkamp - Added support for groups
84126
* @author Ulrich Mertin - Added support for HAN-FUN blinds
127+
* @author Christoph Sommer - Added support for color temperature
128+
* @author Tobias Lange - Added abs color temperature and fixed on/off behavior of light blub
85129
*/
86130
@NonNullByDefault
87131
public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implements FritzAhaStatusListener {
@@ -161,7 +205,8 @@ public void onDeviceUpdated(ThingUID thingUID, AVMFritzBaseModel device) {
161205
if (deviceModel.isHANFUNBlinds()) {
162206
updateLevelControl(deviceModel.getLevelControlModel());
163207
} else if (deviceModel.isColorLight()) {
164-
updateColorLight(deviceModel.getColorControlModel(), deviceModel.getLevelControlModel());
208+
updateColorLight(deviceModel.getColorControlModel(), deviceModel.getLevelControlModel(),
209+
deviceModel.getSimpleOnOffUnit());
165210
} else if (deviceModel.isDimmableLight() && !deviceModel.isHANFUNBlinds()) {
166211
updateDimmableLight(deviceModel.getLevelControlModel());
167212
} else if (deviceModel.isHANFUNUnit() && deviceModel.isHANFUNOnOff()) {
@@ -218,12 +263,28 @@ private void updateDimmableLight(@Nullable LevelControlModel levelControlModel)
218263
}
219264

220265
private void updateColorLight(@Nullable ColorControlModel colorControlModel,
221-
@Nullable LevelControlModel levelControlModel) {
222-
if (colorControlModel != null && levelControlModel != null) {
266+
@Nullable LevelControlModel levelControlModel, @Nullable SimpleOnOffModel simpleOnOff) {
267+
if (colorControlModel != null && levelControlModel != null && simpleOnOff != null) {
223268
DecimalType hue = new DecimalType(colorControlModel.hue);
224269
PercentType saturation = ColorControlModel.toPercent(colorControlModel.saturation);
225-
PercentType brightness = new PercentType(levelControlModel.getLevelPercentage());
270+
PercentType brightness;
271+
if (simpleOnOff.state) {
272+
brightness = new PercentType(levelControlModel.getLevelPercentage());
273+
} else {
274+
brightness = PercentType.ZERO;
275+
}
226276
updateThingChannelState(CHANNEL_COLOR, new HSBType(hue, saturation, brightness));
277+
278+
if (colorControlModel.currentMode == 4) {
279+
int temperature = colorControlModel.temperature;
280+
int tempMired = 1000000 / temperature;
281+
int tempMinMired = 1000000 / 2700;
282+
int tempMaxMired = 1000000 / 6500;
283+
int pct = (tempMired - tempMinMired) * 100 / (tempMaxMired - tempMinMired);
284+
updateThingChannelState(CHANNEL_COLORTEMPERATURE, new PercentType(pct));
285+
updateThingChannelState(CHANNEL_COLORTEMPERATURE_ABS,
286+
new QuantityType<>(BigDecimal.valueOf(temperature), Units.KELVIN));
287+
}
227288
}
228289
}
229290

@@ -454,7 +515,41 @@ public void handleCommand(ChannelUID channelUID, Command command) {
454515
}
455516
}
456517
if (brightness != null) {
457-
fritzBox.setLevelPercentage(ain, brightness);
518+
if (brightness.equals(BigDecimal.ZERO)) {
519+
fritzBox.setSwitch(ain, false);
520+
} else {
521+
fritzBox.setSwitch(ain, true);
522+
fritzBox.setLevelPercentage(ain, brightness);
523+
}
524+
}
525+
break;
526+
case CHANNEL_COLORTEMPERATURE:
527+
BigDecimal colorTemperaturePct = null;
528+
if (command instanceof PercentType) {
529+
colorTemperaturePct = ((PercentType) command).toBigDecimal();
530+
}
531+
if (colorTemperaturePct != null) {
532+
int pct = colorTemperaturePct.intValue();
533+
// AHA-HTTP-Inteface docu say that the values typically between 2700K and 6500K
534+
int tempMinMired = 1000000 / 2700;
535+
int tempMaxMired = 1000000 / 6500;
536+
int tempScaledMired = tempMinMired + ((tempMaxMired - tempMinMired) * pct / 100);
537+
int tempKelvin = 1000000 / tempScaledMired;
538+
fritzBox.setColorTemperature(ain, tempKelvin, 0);
539+
}
540+
break;
541+
case CHANNEL_COLORTEMPERATURE_ABS:
542+
BigDecimal colorTemperature = null;
543+
if (command instanceof QuantityType) {
544+
QuantityType<?> convertedCommand = ((QuantityType<?>) command).toInvertibleUnit(Units.KELVIN);
545+
if (convertedCommand != null) {
546+
colorTemperature = convertedCommand.toBigDecimal();
547+
}
548+
} else if (command instanceof DecimalType) {
549+
colorTemperature = ((DecimalType) command).toBigDecimal();
550+
}
551+
if (colorTemperature != null) {
552+
fritzBox.setColorTemperature(ain, colorTemperature.intValue(), 0);
458553
}
459554
break;
460555
case CHANNEL_SETTEMP:

bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/hardware/FritzAhaWebInterface.java

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetBlindTargetCallback;
3636
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetBlindTargetCallback.BlindCommand;
3737
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetColorCallback;
38+
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetColorTemperatureCallback;
3839
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetHeatingModeCallback;
3940
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetHeatingTemperatureCallback;
4041
import org.openhab.binding.avmfritz.internal.hardware.callbacks.FritzAhaSetLevelPercentageCallback;
@@ -53,6 +54,7 @@
5354
* DECT
5455
* @author Christoph Weitkamp - Added support for groups
5556
* @author Ulrich Mertin - Added support for HAN-FUN blinds
57+
* @author Christoph Sommer - Added support for color temperature
5658
*/
5759
@NonNullByDefault
5860
public class FritzAhaWebInterface {
@@ -340,6 +342,12 @@ public FritzAhaContentExchange setUnmappedHueAndSaturation(String ain, int hue,
340342
return asyncGet(callback);
341343
}
342344

345+
public FritzAhaContentExchange setColorTemperature(String ain, int temperature, int duration) {
346+
FritzAhaSetColorTemperatureCallback callback = new FritzAhaSetColorTemperatureCallback(this, ain, temperature,
347+
duration);
348+
return asyncGet(callback);
349+
}
350+
343351
public FritzAhaContentExchange setBlind(String ain, BlindCommand command) {
344352
FritzAhaSetBlindTargetCallback callback = new FritzAhaSetBlindTargetCallback(this, ain, command);
345353
return asyncGet(callback);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) 2010-2023 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.avmfritz.internal.hardware.callbacks;
14+
15+
import static org.eclipse.jetty.http.HttpMethod.GET;
16+
17+
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.openhab.binding.avmfritz.internal.hardware.FritzAhaWebInterface;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
/**
23+
* Callback implementation for updating colortemperature. Supports reauthorization
24+
*
25+
* @author Christoph Sommer - Initial contribution
26+
*/
27+
@NonNullByDefault
28+
public class FritzAhaSetColorTemperatureCallback extends FritzAhaReauthCallback {
29+
30+
private final Logger logger = LoggerFactory.getLogger(FritzAhaSetColorTemperatureCallback.class);
31+
32+
private final String ain;
33+
34+
/**
35+
* Constructor
36+
*
37+
* @param webIface Interface to FRITZ!Box
38+
* @param ain AIN of the device that should be switched
39+
* @param temperature Color Temperature in Kelvin (typ.: 2700 to 6500)
40+
* @param duration Duration of the change in 100ms. 0 immediately.
41+
*/
42+
public FritzAhaSetColorTemperatureCallback(FritzAhaWebInterface webIface, String ain, int temperature,
43+
int duration) {
44+
super(WEBSERVICE_PATH,
45+
"switchcmd=setcolortemperature&temperature=" + temperature + "&duration=" + duration + "&ain=" + ain,
46+
webIface, GET, 1);
47+
this.ain = ain;
48+
}
49+
50+
@Override
51+
public void execute(int status, String response) {
52+
super.execute(status, response);
53+
if (isValidRequest()) {
54+
logger.debug("Received response '{}' for item '{}'", response, ain);
55+
}
56+
}
57+
}

bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/thing/thing-types.xml

+12
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515

1616
<channels>
1717
<channel id="color" typeId="system.color"/>
18+
<channel id="color_temperature" typeId="system.color-temperature"/>
19+
<channel id="color_temperature_abs" typeId="system.color-temperature-abs"/>
1820
</channels>
1921

22+
<properties>
23+
<property name="thingTypeVersion">1</property>
24+
</properties>
25+
2026
<representation-property>ain</representation-property>
2127

2228
<config-description-ref uri="thing-type:avmfritz:fritzdevice"/>
@@ -411,8 +417,14 @@
411417

412418
<channels>
413419
<channel id="color" typeId="system.color"/>
420+
<channel id="color_temperature" typeId="system.color-temperature"/>
421+
<channel id="color_temperature_abs" typeId="system.color-temperature-abs"/>
414422
</channels>
415423

424+
<properties>
425+
<property name="thingTypeVersion">1</property>
426+
</properties>
427+
416428
<representation-property>ain</representation-property>
417429

418430
<config-description-ref uri="thing-type:avmfritz:fritzdevice"/>

bundles/org.openhab.binding.avmfritz/src/main/resources/OH-INF/update/instructions.xml

+22
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,26 @@
113113
</instruction-set>
114114
</thing-type>
115115

116+
<thing-type uid="avmfritz:FRITZ_DECT_500">
117+
<instruction-set targetVersion="1">
118+
<add-channel id="color_temperature">
119+
<type>system:color-temperature</type>
120+
</add-channel>
121+
<add-channel id="color_temperature_abs">
122+
<type>system:color-temperature-abs</type>
123+
</add-channel>
124+
</instruction-set>
125+
</thing-type>
126+
127+
<thing-type uid="avmfritz:HAN_FUN_COLOR_BULB">
128+
<instruction-set targetVersion="1">
129+
<add-channel id="color_temperature">
130+
<type>system:color-temperature</type>
131+
</add-channel>
132+
<add-channel id="color_temperature_abs">
133+
<type>system:color-temperature-abs</type>
134+
</add-channel>
135+
</instruction-set>
136+
</thing-type>
137+
116138
</update:update-descriptions>

0 commit comments

Comments
 (0)