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

[gree] Add channel for temperature sensor #8303

Merged
merged 13 commits into from
Sep 10, 2020
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
65 changes: 36 additions & 29 deletions bundles/org.openhab.binding.gree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ No binding configuration is required.

## Thing Configuration

| Channel Name | Type | Description |
|------------------|------------|-----------------------------------------------------------------------------------------------|
| ipAddress | IP Address | IP address of the unit. |
| broadcastAddress | IP Address | Broadcast address being used for discovery, usually derived from the IP interface address. |
| refresh | Integer | Refresh interval in seconds for polling the device status. |
| Channel Name | Type | Description |
|--------------------------|------------|-----------------------------------------------------------------------------------------------|
| ipAddress | IP Address | IP address of the unit. |
| broadcastAddress | IP Address | Broadcast address being used for discovery, usually derived from the IP interface address. |
| refresh | Integer | Refresh interval in seconds for polling the device status. |
| currentTemperatureOffset | Decimal | The offset in Celsius for the current temperature value received from the device. |

The Air Conditioner's IP address is mandatory, all other parameters are optional.
If the broadcast is not set (default) it will be derived from openHAB's network setting (PaperUI:Configuration:System:Network Settings).
Expand All @@ -33,27 +34,28 @@ Only change this if you have a good reason to.

The following channels are supported for fans:

| Channel Name | Item Type | Description |
|---------------|-----------|---------------------------------------------------------------------------------------------------|
| power | Switch | Power on/off the Air Conditioner |
| mode | String | Sets the operating mode of the Air Conditioner |
| | | Mode can be one of auto/cool/eco/dry/fan/heat or on/off |
| | | Check the Air Conditioner's operating manual for supported modes. |
| temperature | Number:Temperature | Sets the desired room temperature |
| air | Switch | Set on/off the Air Conditioner's Air function if applicable to the Air Conditioner model |
| dry | Switch | Set on/off the Air Conditioner's Dry function if applicable to the Air Conditioner model |
| health | Switch | Set on/off the Air Conditioner's Health function if applicable to the Air Conditioner model |
| turbo | Switch | Set on/off the Air Conditioner's Turbo Mode. |
| quiet | String | Set Quiet Mode: off/auto/quiet |
| swingUpDown | Number | Sets the vertical (up..down) swing action on the Air Conditioner, |
| | | OFF: 0, Full Swing: 1, Up: 2, MidUp: 3, Mid: 4, Mid Down: 5, Down : 6 |
| swingLeftRight| Number | Sets the horizontal (left..right) swing action on the Air Conditioner |
| | | OFF: 0, Full Swing: 1, Left: 2, Mid Left: 3, Mid: 4, Mid Right: 5, Right : 6 |
| windspeed | Number | Sets the fan speed on the Air conditioner Auto:0, Low:1, MidLow:2, Mid:3, MidHigh:4, High:5 |
| | | The number of speeds depends on the Air Conditioner model. |
| powersave | Switch | Set on/off the Air Conditioner's Power Saving function if applicable to the Air Conditioner model |
| light | Switch | Enable/disable the front display on the Air Conditioner if applicable to the Air Conditioner model|
| | | Full Swing: 1, Up: 2, MidUp: 3, Mid: 4, Mid Down: 5, Down : 6 |
| Channel Name | Item Type | Description |
|--------------------|-----------|---------------------------------------------------------------------------------------------------|
| power | Switch | Power on/off the Air Conditioner |
| mode | String | Sets the operating mode of the Air Conditioner |
| | | Mode can be one of auto/cool/eco/dry/fan/heat or on/off |
| | | Check the Air Conditioner's operating manual for supported modes. |
| temperature | Number:Temperature | Sets the desired room temperature. |
| currentTemperature | Number:Temperature | Displays the current room temperature. |
| air | Switch | Set on/off the Air Conditioner's Air function if applicable to the Air Conditioner model |
| dry | Switch | Set on/off the Air Conditioner's Dry function if applicable to the Air Conditioner model |
| health | Switch | Set on/off the Air Conditioner's Health function if applicable to the Air Conditioner model |
| turbo | Switch | Set on/off the Air Conditioner's Turbo Mode. |
| quiet | String | Set Quiet Mode: off/auto/quiet |
| swingUpDown | Number | Sets the vertical (up..down) swing action on the Air Conditioner, |
| | | OFF: 0, Full Swing: 1, Up: 2, MidUp: 3, Mid: 4, Mid Down: 5, Down : 6 |
| swingLeftRight | Number | Sets the horizontal (left..right) swing action on the Air Conditioner |
| | | OFF: 0, Full Swing: 1, Left: 2, Mid Left: 3, Mid: 4, Mid Right: 5, Right : 6 |
| windspeed | Number | Sets the fan speed on the Air conditioner Auto:0, Low:1, MidLow:2, Mid:3, MidHigh:4, High:5 |
| | | The number of speeds depends on the Air Conditioner model. |
| powersave | Switch | Set on/off the Air Conditioner's Power Saving function if applicable to the Air Conditioner model |
| light | Switch | Enable/disable the front display on the Air Conditioner if applicable to the Air Conditioner model|
| | | Full Swing: 1, Up: 2, MidUp: 3, Mid: 4, Mid Down: 5, Down : 6 |


When changing mode, the air conditioner will be turned on unless "off" is selected.
Expand All @@ -73,7 +75,8 @@ Switch AirconPower { channel="gree:airconditioner:a1234561:powe
String AirconMode { channel="gree:airconditioner:a1234561:mode" }
Switch AirconTurbo { channel="gree:airconditioner:a1234561:turbo" }
Switch AirconLight { channel="gree:airconditioner:a1234561:light" }
Number AirconTemp "Temperature [%.1f °C]" {channel="gree:airconditioner:a1234561:temperature" }
Number AirconTargetTemp "Target Temperature [%.1f °C]" {channel="gree:airconditioner:a1234561:temperature" }
Number AirconCurrentTemp "Current Temperature [%.1f °C]" {channel="gree:airconditioner:a1234561:currentTemperature" }
Number AirconSwingVertical { channel="gree:airconditioner:a1234561:swingUpDown" }
Number AirconSwingHorizontal { channel="gree:airconditioner:a1234561:swingLeftRight" }
Number AirconFanSpeed { channel="gree:airconditioner:a1234561:windspeed" }
Expand All @@ -91,7 +94,11 @@ This is an example of how to set up your sitemap.
Frame label="Controls"
{
Switch item=AirconMode label="Mode" mappings=["auto"="Auto", "cool"="Cool", "eco"="Eco", "dry"="Dry", "fan"="Fan", "turbo"="Turbo", "heat"="Heat", "on"="ON", "off"="OFF"]
Setpoint item=AirconTemp label="Set temperature" icon=temperature minValue=16 maxValue=30 step=1
Setpoint item=AirconTargetTemp label="Set target temperature" icon=temperature minValue=16 maxValue=30 step=1
}
Frame label="Current Temperature"
{
Text item=AirconCurrentTemp label="Current temperature [%.1f °C]" icon="temperature"
}
Frame label="Fan Speed"
{
Expand Down Expand Up @@ -124,7 +131,7 @@ Group Gree_Modechannel "Gree" { ga="Thermostat" } //
Switch GreeAirConditioner_Power "Aircon" {channel="gree:airconditioner:a1234561:power", ga="Switch"}
String GreeAirConditioner_Mode "Aircon Mode" {channel="gree:airconditioner:a1234561:mode", ga="thermostatMode"}
Number GreeAirConditioner_Temp "Aircon Temperature" {channel="gree:airconditioner:a1234561:temperature}
Switch GreeAirConditioner_Lightl "Light" {channel="gree:airconditioner:a1234561:light"}
Switch GreeAirConditioner_Light "Light" {channel="gree:airconditioner:a1234561:light"}
```

**Rules**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class GreeBindingConstants {
public static final String MODE_CHANNEL = "mode";
public static final String TURBO_CHANNEL = "turbo";
public static final String LIGHT_CHANNEL = "light";
public static final String TEMP_CHANNEL = "temperature";
public static final String TARGET_TEMP_CHANNEL = "temperature";
public static final String CURRENT_TEMP_CHANNEL = "currentTemperature";
public static final String SWINGUD_CHANNEL = "swingUpDown";
public static final String SWINGLR_CHANNEL = "swingLeftRight";
public static final String WINDSPEED_CHANNEL = "windspeed";
Expand Down Expand Up @@ -137,6 +138,7 @@ public class GreeBindingConstants {
public static final String GREE_PROP_HEAT = "StHt";
public static final String GREE_PROP_HEATCOOL = "HeatCoolType";
public static final String GREE_PROP_NOISESET = "NoiseSet";
public static final String GREE_PROP_CURRENT_TEMP_SENSOR = "TemSen";

// Temperatur types and min/max ranges
public static final int TEMP_UNIT_CELSIUS = 0;
Expand All @@ -159,4 +161,15 @@ public class GreeBindingConstants {
public static final int REFRESH_INTERVAL_SEC = 5;

public static final int DIGITS_TEMP = 1;

/**
* The internal offset for the temperature sensor which is set to a constant of -40 degrees Celsius. GREE
* airconditioners usually return a value from the temperature sensor which is offset by +40 degrees Celsius. The
* temperature value shown on the device LCD display should match the value shown by this binding when the config
* parameter currentTemperatureOffset is set to 0.
*
* @See https://github.com/tomikaa87/gree-remote#getting-the-current-temperature-reading-from-the-internal-sensor
* for more details.
*/
public static final double INTERNAL_TEMP_SENSOR_OFFSET = -40.0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.gree.internal;

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -25,9 +27,15 @@ public class GreeConfiguration {
public String ipAddress = "";
public String broadcastAddress = "";
public int refresh = 60;
/**
* The currentTemperatureOffset is configureable in case the user wants to offset this temperature for calibration
* of the temperature sensor.
*/
public BigDecimal currentTemperatureOffset = new BigDecimal(0.0);

@Override
public String toString() {
return "Config: ipAddress=" + ipAddress + ", broadcastAddress=" + broadcastAddress + ", refresh=" + refresh;
return "Config: ipAddress=" + ipAddress + ", broadcastAddress=" + broadcastAddress + ", refresh=" + refresh
+ ", currentTemperatureOffset=" + currentTemperatureOffset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void getDeviceStatus(DatagramSocket clientSocket) throws GreeException {
columns.add(GREE_PROP_TEMPREC);
columns.add(GREE_PROP_PWR_SAVING);
columns.add(GREE_PROP_NOISESET);
columns.add(GREE_PROP_CURRENT_TEMP_SENSOR);

// Convert the parameter map values to arrays
String[] colArray = columns.toArray(new String[0]);
Expand Down Expand Up @@ -231,10 +232,6 @@ public void setQuietMode(DatagramSocket clientSocket, int value) throws GreeExce
setCommandValue(clientSocket, GREE_PROP_QUIET, value, 0, 2);
}

public int getDeviceTurbo() {
return getIntStatusVal(GREE_PROP_TURBO);
}

public void setDeviceLight(DatagramSocket clientSocket, int value) throws GreeException {
setCommandValue(clientSocket, GREE_PROP_LIGHT, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case LIGHT_CHANNEL:
device.setDeviceLight(socket, getOnOff(command));
break;
case TEMP_CHANNEL:
case TARGET_TEMP_CHANNEL:
markus7017 marked this conversation as resolved.
Show resolved Hide resolved
// Set value, read back effective one and update channel
// e.g. 22.5C will result in 22.0, because the AC doesn't support half-steps for C
device.setDeviceTempSet(socket, convertTemp(command));
Expand Down Expand Up @@ -405,8 +405,11 @@ private void publishChannel(ChannelUID channelUID) {
case LIGHT_CHANNEL:
state = updateOnOff(GREE_PROP_LIGHT);
break;
case TEMP_CHANNEL:
state = updateTemp();
case TARGET_TEMP_CHANNEL:
state = updateTargetTemp();
break;
case CURRENT_TEMP_CHANNEL:
state = updateCurrentTemp();
break;
case SWINGUD_CHANNEL:
state = updateNumber(GREE_PROP_SWINGUPDOWN);
Expand Down Expand Up @@ -505,7 +508,7 @@ private void publishChannel(ChannelUID channelUID) {
return null;
}

private @Nullable State updateTemp() throws GreeException {
private @Nullable State updateTargetTemp() throws GreeException {
if (device.hasStatusValChanged(GREE_PROP_SETTEMP) || device.hasStatusValChanged(GREE_PROP_TEMPUNIT)) {
int unit = device.getIntStatusVal(GREE_PROP_TEMPUNIT);
return toQuantityType(device.getIntStatusVal(GREE_PROP_SETTEMP), DIGITS_TEMP,
Expand All @@ -514,6 +517,14 @@ private void publishChannel(ChannelUID channelUID) {
return null;
}

private @Nullable State updateCurrentTemp() throws GreeException {
if (device.hasStatusValChanged(GREE_PROP_CURRENT_TEMP_SENSOR)) {
return new DecimalType(device.getIntStatusVal(GREE_PROP_CURRENT_TEMP_SENSOR) + INTERNAL_TEMP_SENSOR_OFFSET
+ config.currentTemperatureOffset.doubleValue());
}
return null;
}

private String logInfo(String msgKey, Object... arg) {
String message = messages.get(msgKey, arg);
logger.info("{}: {}", thingId, message);
Expand All @@ -525,7 +536,7 @@ public static QuantityType<?> toQuantityType(Number value, int digits, Unit<?> u
return new QuantityType<>(bd.setScale(digits, BigDecimal.ROUND_HALF_EVEN), unit);
}

private void stopRefrestTask() {
private void stopRefreshTask() {
forceRefresh = false;
if (refreshTask == null) {
return;
Expand All @@ -544,7 +555,7 @@ public void dispose() {
clientSocket.get().close();
clientSocket = Optional.empty();
}
stopRefrestTask();
stopRefreshTask();
if (initializeFuture != null) {
initializeFuture.cancel(true);
}
Expand Down
Loading