Skip to content

Commit

Permalink
[venstarthermostat] more functions issue enhancement 10823 (openhab#1…
Browse files Browse the repository at this point in the history
…1305)

* Adding several functions to binding to mimic local API

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Adding functionality according to API

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Updating Read me with new capability

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Additional commit with requested changes to pull request

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Updates to address all comments on previous commit.

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Updates as requested in review.

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Corrections for check style warnings

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Updates to address feedback from lolodomo.

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* Changes to address feedback from lolodomo's review

Signed-off-by: raveydavies <matthew.davies@skynet.be>

* FanState changed to Switch, Exception handling added as per review.

Signed-off-by: raveydavies <matthew.davies@skynet.be>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
  • Loading branch information
raveydavies authored and NickWaterton committed Dec 30, 2021
1 parent 1f5ac60 commit 74824c7
Show file tree
Hide file tree
Showing 21 changed files with 1,064 additions and 78 deletions.
102 changes: 85 additions & 17 deletions bundles/org.openhab.binding.venstarthermostat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,63 @@ After adding the Inbox item, enter the user name and password from the physical

### Channels

| Channel | Type | Description | Notes |
|--------------------|--------------------|------------------------------|--------------------------------------------------------|
| awayMode | String | Home or Away Mode | |
| awayModeRaw | Number | Away Mode Raw (Read Only) | 0 (Home) 1 (Away) |
| systemMode | String | System Mode | |
| systemModeRaw | Number | System Mode Raw (Read Only) | 0 (Off) 1 (Heat) 2 (Cool) 3 (Auto) |
| systemState | String | System State (Read Only) | |
| systemStateRaw | Number | System State Raw (Read Only) | 0 (Idle) 1 (Heating) 2 (Cooling) 3 (Lockout) 4 (Error) |
| heatingSetpoint | Number:Temperature | Heating Set Point | |
| coolingSetpoint | Number:Temperature | Cooling Set Point | |
| temperature | Number:Temperature | Current Temperature | |
| outdoorTemperature | Number:Temperature | Outdoor Temperature | |
| humidity | Number | Humidity | |

| Channel | Type | Description | Notes |
|--------------------|--------------------|---------------------------------------|--------------------------------------------------------|
| awayMode | String | Home or Away Mode | |
| awayModeRaw | Number | Away Mode Raw (Read Only) | 0 (Home) 1 (Away) |
| systemMode | String | System Mode | |
| systemModeRaw | Number | System Mode Raw (Read Only) | 0 (Off) 1 (Heat) 2 (Cool) 3 (Auto) |
| systemState | String | System State (Read Only) | |
| systemStateRaw | Number | System State Raw (Read Only) | 0 (Idle) 1 (Heating) 2 (Cooling) 3 (Lockout) 4 (Error) |
| heatingSetpoint | Number:Temperature | Heating Set Point | |
| coolingSetpoint | Number:Temperature | Cooling Set Point | |
| temperature | Number:Temperature | Current Temperature | |
| outdoorTemperature | Number:Temperature | Outdoor Temperature | |
| humidity | Number | Humidity | |
| fanMode | String | Fan Mode | |
| fanModeRaw | Number | Fan Mode Raw (Read Only) | 0 (Auto) 1 (On) |
| fanState | String | Fan State (Read Only) | |
| fanStateRaw | Number | Fan State Raw (Read Only) | 0 (Off) 1 (On) |
| scheduleMode | String | Current Schedule Mode | |
| scheduleModeRaw | Number | Current Schedule mode Raw (Read Only) | 0(Disabled) 1(Enabled) |
| schedulePart | String | Current Schedule Part | |
| schedulePartRaw | Number | Schedule Part Raw (Read Only) | 0(Morning) 1(Day) 2(Evening) 3 (Night) 255 (Inactive) |


### Runtime data

The Venstar thermostat provides data about how many minutes the system has been running in each of the different modes (heat1, heat2, cool1, cool2, aux1, aux2, free cool) every day for the last 7 days.
A time stamp is provided with each runtime data set which represents the end of each day.
The binding reads the runtime data and time stamps and provides them all as separate channels.

| Channel | Type | Description | Notes |
|------------------------|----------------------|----------------------------------------------|------------------------------------------------------------|
| timestampDay0 | DateTime | Time Stamp of last runtime update | This is always the current time today |
| timestampDay1 | DateTime | Time Stamp of 00:00, end of yesterday | This represents the end of 1 day ago |
| timestampDay2 | DateTime | Time Stamp of 00:00 end of 2 days ago | This represents the end of 2 days ago |
| timestampDay3 | DateTime | Time Stamp of 00:00, end of 3 days ago | This represents the end of 3 days ago |
| timestampDay4 | DateTime | Time Stamp of 00:00, end of 4 days ago | This represents the end of 4 days ago |
| timestampDay5 | DateTime | Time Stamp of 00:00, end of 5 days ago | This represents the end of 5 days ago |
| timestampDay6 | DateTime | Time Stamp of 00:00, end of 6 days ago | This represents the end of 6 days ago |
| heat1RuntimeDay0 | Number:Dimensionless | Runtime in heat1 mode (minutes) today | This is the runtime between the Day 1 and Day 0 timestamps |
| heat1RuntimeDay1 | Number:Dimensionless | Runtime in heat1 mode (minutes) yesterday | This is the runtime between the Day 2 and Day 1 timestamps |
| heat1RuntimeDay2 | Number:Dimensionless | Runtime in heat1 mode (minutes) 2 days ago | This is the runtime between the Day 3 and Day 2 timestamps |
| heat1RuntimeDay3 | Number:Dimensionless | Runtime in heat1 mode (minutes) 3 days ago | This is the runtime between the Day 4 and Day 3 timestamps |
| heat1RuntimeDay4 | Number:Dimensionless | Runtime in heat1 mode (minutes) 4 days ago | This is the runtime between the Day 5 and Day 4 timestamps |
| heat1RuntimeDay5 | Number:Dimensionless | Runtime in heat1 mode (minutes) 5 days ago | This is the runtime between the Day 6 and Day 5 timestamps |
| heat1RuntimeDay6 | Number:Dimensionless | Runtime in heat1 mode (minutes) 6 days ago | This is the runtime in the 24hrs up to the Day 6 timestamp |
| | | | |
| heat2RuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in heat2 mode (minutes) | |
| | | | |
| cool1RuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in cool1 mode (minutes) | |
| | | | |
| cool2RuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in cool2 mode (minutes) | |
| | | | |
| aux1RuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in aux1 mode (minutes) | |
| | | | |
| aux2RuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in aux2 mode (minutes) | |
| | | | |
| freeCoolRuntimeDay0..6 | Number:Dimensionless | Similar Runtimes in free cool mode (minutes) | |

## Example

Expand All @@ -71,10 +114,22 @@ Thing venstarthermostat:colorTouchThermostat:001122334455 "Venstar Thermostat (G
Number:Temperature Guest_HVAC_Temperature "Temperature [%d °F]" {channel="venstarthermostat:colorTouchThermostat:001122334455:temperature"}
Number:Temperature Guest_HVAC_HeatSetpoint "Heat Setpoint [%d °F]" {channel="venstarthermostat:colorTouchThermostat:001122334455:heatingSetpoint"}
Number:Temperature Guest_HVAC_CoolSetpoint "Cool Setpoint [%d °F]" {channel="venstarthermostat:colorTouchThermostat:001122334455:coolingSetpoint"}
Number Guest_HVAC_Mode "Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:systemMode"}
String Guest_HVAC_Mode "System Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:systemMode"}
Number Guest_HVAC_Humidity "Humidity [%d %%]" {channel="venstarthermostat:colorTouchThermostat:001122334455:humidity"}
Number Guest_HVAC_State "State [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:systemState"}
Number Guest_Away_Mode "Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:awayMode"}
String Guest_HVAC_State "State [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:systemState"}
String Guest_Away_Mode "Away Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:awayMode"}
String Guest_Fan_Mode "Fan Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:fanMode"}
String Guest_Fan_State "Fan State [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:fanState"}
String Guest_Schedule_Mode "Schedule Mode [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:scheduleMode"}
String Guest_Schedule_Part "Schedule Part [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:schedulePart"}
DateTime Guest_timestampDay0 "Date/Time Last Update [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:timestampDay0"}
Number Guest_heat1RuntimeDay0 "Heat1 Day0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:heat1RuntimeDay0"}
Number Guest_heat2RuntimeDay0 "Heat2 Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:heat2RuntimeDay0"}
Number Guest_cool1RuntimeDay0 "Cool1 Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:cool1RuntimeDay0"}
Number Guest_cool2RuntimeDay0 "Cool2 Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:cool2RuntimeDay0"}
Number Guest_aux1RuntimeDay0 "Aux1 Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:aux1RuntimeDay0"}
Number Guest_aux2RuntimeDay0 "Aux2 Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:aux2RuntimeDay0"}
Number Guest_freeCoolRuntimeDay0 "Free Cool Day 0 Run Time [%s]" {channel="venstarthermostat:colorTouchThermostat:001122334455:freeCoolRuntimeDay0"}
```

### thermostat.sitemap
Expand All @@ -88,6 +143,19 @@ sitemap demo label="Venstar Color Thermostat Demo"
Switch item=Guest_HVAC_Mode mappings=[off=Off,heat=Heat,cool=Cool,auto=Auto]
Switch item=Guest_Away_Mode mappings=[home=Home,away=Away]
Text item=Guest_HVAC_State
Switch item=Guest_Fan_Mode mappings=[auto=Auto, on=On]
Text item=Guest_Fan_State
Switch item=Guest_Schedule_Mode mappings=[enabled=Enabled,disabled=Disabled]
Text item=Guest_Schedule_Part
Text item=Guest_timestampDay0
Text item=Guest_heat1RuntimeDay0
Text item=Guest_heat2RuntimeDay0
Text item=Guest_cool1RuntimeDay0
Text item=Guest_cool2RuntimeDay0
Text item=Guest_aux1RuntimeDay0
Text item=Guest_aux2RuntimeDay0
Text item=Guest_freeCoolRuntimeDay0
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* @author William Welliver - Initial contribution
* @author Matthew Davies - added awayMode and awayModeRaw to include thermostat away mode in binding
* @author Matthew Davies - added more binding functionality to get close to the API functionality
*/
@NonNullByDefault
public class VenstarThermostatBindingConstants {
Expand All @@ -47,6 +48,23 @@ public class VenstarThermostatBindingConstants {
public static final String CHANNEL_SYSTEM_MODE_RAW = "systemModeRaw";
public static final String CHANNEL_AWAY_MODE = "awayMode";
public static final String CHANNEL_AWAY_MODE_RAW = "awayModeRaw";
public static final String CHANNEL_FAN_MODE = "fanMode";
public static final String CHANNEL_FAN_MODE_RAW = "fanModeRaw";
public static final String CHANNEL_FAN_STATE = "fanState";
public static final String CHANNEL_FAN_STATE_RAW = "fanStateRaw";
public static final String CHANNEL_SCHEDULE_MODE = "scheduleMode";
public static final String CHANNEL_SCHEDULE_MODE_RAW = "scheduleModeRaw";
public static final String CHANNEL_SCHEDULE_PART = "schedulePart";
public static final String CHANNEL_SCHEDULE_PART_RAW = "schedulePartRaw";
public static final String CHANNEL_TIMESTAMP_RUNTIME_DAY = "timestampDay";
public static final String CHANNEL_HEAT1_RUNTIME_DAY = "heat1RuntimeDay";
public static final String CHANNEL_HEAT2_RUNTIME_DAY = "heat2RuntimeDay";
public static final String CHANNEL_COOL1_RUNTIME_DAY = "cool1RuntimeDay";
public static final String CHANNEL_COOL2_RUNTIME_DAY = "cool2RuntimeDay";
public static final String CHANNEL_AUX1_RUNTIME_DAY = "aux1RuntimeDay";
public static final String CHANNEL_AUX2_RUNTIME_DAY = "aux2RuntimeDay";
public static final String CHANNEL_FC_RUNTIME_DAY = "freeCoolRuntimeDay";
// add query/runtimes and query/alerts - these will need an additional class similar to Venstar.infodata - more work

public static final String CONFIG_USERNAME = "username";
public static final String CONFIG_PASSWORD = "password";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String friendlyName() {
return friendlyName;
}

public static VenstarAwayMode fromInt(int mode) {
public static VenstarAwayMode fromInt(int mode) throws IllegalArgumentException {
for (VenstarAwayMode am : values()) {
if (am.mode == mode) {
return am;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class VenstarAwayModeSerializer implements JsonDeserializer<VenstarAwayMo
public VenstarAwayMode deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2)
throws JsonParseException {
int key = element.getAsInt();
return VenstarAwayMode.fromInt(key);
try {
return VenstarAwayMode.fromInt(key);
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2010-2021 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.venstarthermostat.internal.dto;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link VenstarFanMode} represents the value of the fan mode returned
* from the REST API.
*
* @author Matthew Davies - Initial contribution
*/
@NonNullByDefault
public enum VenstarFanMode {
AUTO(0, "auto", "Auto"),
ON(1, "on", "On");

private int mode;
private String name;
private String friendlyName;

VenstarFanMode(int mode, String name, String friendlyName) {
this.mode = mode;
this.name = name;
this.friendlyName = friendlyName;
}

public int mode() {
return mode;
}

public String modeName() {
return name;
}

public String friendlyName() {
return friendlyName;
}

public static VenstarFanMode fromInt(int mode) throws IllegalArgumentException {
for (VenstarFanMode fm : values()) {
if (fm.mode == mode) {
return fm;
}
}

throw (new IllegalArgumentException("Invalid fan mode " + mode));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2010-2021 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.venstarthermostat.internal.dto;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

/**
* The {@link VenstarFanModeSerializer} parses fan mode values
* from the REST API JSON.
*
* @author Matthew Davies - Initial contribution
*/

public class VenstarFanModeSerializer implements JsonDeserializer<VenstarFanMode> {
@Override
public VenstarFanMode deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2)
throws JsonParseException {
int key = element.getAsInt();
try {
return VenstarFanMode.fromInt(key);
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
}
Loading

0 comments on commit 74824c7

Please sign in to comment.