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

[RFXCOM] Support all data from wind sensors #2329

Merged
merged 4 commits into from
Jun 10, 2017
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
14 changes: 13 additions & 1 deletion addons/binding/org.openhab.binding.rfxcom/ESH-INF/thing/wind.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@
<description>A Wind device.</description>

<channels>
<channel id="windSpeed" typeId="windspeed" />
<channel id="avgWindSpeed" typeId="windspeed">
<label>Average Wind Speed</label>
<description>Average wind speed in meters per second</description>
</channel>
<channel id="windSpeed" typeId="windspeed">
<label>Wind Gust</label>
<description>Wind gust in meters per second</description>
</channel>
<channel id="windDirection" typeId="winddirection" />
<channel id="temperature" typeId="temperature" />
<channel id="chillTemperature" typeId="temperature">
<label>Chill Temperature</label>
<description>Chill temperature in degree Celsius</description>
</channel>
<channel id="signalLevel" typeId="system.signal-strength" />
<channel id="batteryLevel" typeId="system.battery-level" />
<channel id="lowBattery" typeId="system.low-battery" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class RFXComBindingConstants {
public static final String CHANNEL_SIGNAL_LEVEL = "signalLevel";
public static final String CHANNEL_DIMMING_LEVEL = "dimmingLevel";
public static final String CHANNEL_TEMPERATURE = "temperature";
public static final String CHANNEL_CHILL_TEMPERATURE = "chillTemperature";
public static final String CHANNEL_HUMIDITY = "humidity";
public static final String CHANNEL_HUMIDITY_STATUS = "humidityStatus";
public static final String CHANNEL_BATTERY_LEVEL = "batteryLevel";
Expand All @@ -72,8 +73,7 @@ public class RFXComBindingConstants {
public static final String CHANNEL_RAIN_TOTAL = "rainTotal";
public static final String CHANNEL_WIND_DIRECTION = "windDirection";
public static final String CHANNEL_WIND_SPEED = "windSpeed";
public static final String CHANNEL_GUST = "gust";
public static final String CHANNEL_CHILL_FACTOR = "chillFactor";
Copy link
Member

@martinvw martinvw Jun 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these already unused and not defined somewhere else, where they also should be removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were unused. Previously the gust value was what was being returned as windSpeed so to avoid breaking existing "working" setups I elected to keep that and add averageWindSpeed.

public static final String CHANNEL_AVG_WIND_SPEED = "avgWindSpeed";
public static final String CHANNEL_INSTANT_POWER = "instantPower";
public static final String CHANNEL_TOTAL_USAGE = "totalUsage";
public static final String CHANNEL_INSTANT_AMPS = "instantAmp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public enum RFXComValueSelector {
RAIN_RATE(RFXComBindingConstants.CHANNEL_RAIN_RATE, NumberItem.class),
RAIN_TOTAL(RFXComBindingConstants.CHANNEL_RAIN_TOTAL, NumberItem.class),
WIND_DIRECTION(RFXComBindingConstants.CHANNEL_WIND_DIRECTION, NumberItem.class),
AVG_WIND_SPEED(RFXComBindingConstants.CHANNEL_AVG_WIND_SPEED, NumberItem.class),
WIND_SPEED(RFXComBindingConstants.CHANNEL_WIND_SPEED, NumberItem.class),
GUST(RFXComBindingConstants.CHANNEL_GUST, NumberItem.class),
CHILL_FACTOR(RFXComBindingConstants.CHANNEL_CHILL_FACTOR, NumberItem.class),
CHILL_TEMPERATURE(RFXComBindingConstants.CHANNEL_CHILL_TEMPERATURE, NumberItem.class),
INSTANT_POWER(RFXComBindingConstants.CHANNEL_INSTANT_POWER, NumberItem.class),
TOTAL_USAGE(RFXComBindingConstants.CHANNEL_TOTAL_USAGE, NumberItem.class),
INSTANT_AMPS(RFXComBindingConstants.CHANNEL_INSTANT_AMPS, NumberItem.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
updateState(CHANNEL_BATTERY_LEVEL, convertBatteryLevelToSystemWideLevel(
message.convertToState(valueSelector)));
break;
case CHILL_FACTOR:
updateState(CHANNEL_CHILL_FACTOR, message.convertToState(valueSelector));
break;
case CHIME_SOUND:
updateState(CHANNEL_CHIME_SOUND, message.convertToState(valueSelector));
break;
Expand All @@ -190,9 +187,6 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
case FORECAST:
updateState(CHANNEL_FORECAST, message.convertToState(valueSelector));
break;
case GUST:
updateState(CHANNEL_GUST, message.convertToState(valueSelector));
break;
case HUMIDITY:
updateState(CHANNEL_HUMIDITY, message.convertToState(valueSelector));
break;
Expand Down Expand Up @@ -247,6 +241,9 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
case TEMPERATURE:
updateState(CHANNEL_TEMPERATURE, message.convertToState(valueSelector));
break;
case CHILL_TEMPERATURE:
updateState(CHANNEL_TEMPERATURE, message.convertToState(valueSelector));
break;
case TOTAL_AMP_HOUR:
updateState(CHANNEL_TOTAL_AMP_HOUR, message.convertToState(valueSelector));
break;
Expand All @@ -259,6 +256,9 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
case WIND_DIRECTION:
updateState(CHANNEL_WIND_DIRECTION, message.convertToState(valueSelector));
break;
case AVG_WIND_SPEED:
updateState(CHANNEL_AVG_WIND_SPEED, message.convertToState(valueSelector));
break;
case WIND_SPEED:
updateState(CHANNEL_WIND_SPEED, message.convertToState(valueSelector));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
* @author Marc SAUVEUR - Initial contribution
* @author Pauli Anttila
* @author Mike Jagdis - Support all available data from sensors
*/
public class RFXComWindMessage extends RFXComBaseMessage {

Expand Down Expand Up @@ -60,14 +61,17 @@ public static SubType fromByte(int input) throws RFXComUnsupportedValueException

private static final List<RFXComValueSelector> SUPPORTED_INPUT_VALUE_SELECTORS = Arrays.asList(
RFXComValueSelector.SIGNAL_LEVEL, RFXComValueSelector.BATTERY_LEVEL, RFXComValueSelector.WIND_DIRECTION,
RFXComValueSelector.WIND_SPEED);
RFXComValueSelector.AVG_WIND_SPEED, RFXComValueSelector.WIND_SPEED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could both of us miss this 😉

The temperature fields were not added here.

See https://github.com/openhab/openhab2-addons/issues/2495#issuecomment-318463340

If you ( @mjagdis ) would have time to fix this that would be great, I have no opportunity because I m not near anything except for a tablet for at least one more week.


private static final List<RFXComValueSelector> SUPPORTED_OUTPUT_VALUE_SELECTORS = Collections.emptyList();

public SubType subType;
public int sensorId;
public double windDirection;
public double windSpeed;
public double avgWindSpeed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite some changes, should you be added as an co-author?

public double temperature;
public double chillTemperature;
public byte signalLevel;
public byte batteryLevel;

Expand All @@ -81,17 +85,16 @@ public RFXComWindMessage(byte[] data) throws RFXComException {

@Override
public String toString() {
String str = "";

str += super.toString();
str += ", Sub type = " + subType;
str += ", Device Id = " + getDeviceId();
str += ", Wind direction = " + windDirection;
str += ", Wind speed = " + windSpeed;
str += ", Signal level = " + signalLevel;
str += ", Battery level = " + batteryLevel;

return str;
return super.toString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this style better :-)

+ ", Sub type = " + subType
+ ", Device Id = " + getDeviceId()
+ ", Wind direction = " + windDirection
+ ", Wind gust = " + windSpeed
+ ", Average wind speed = " + avgWindSpeed
+ ", Temperature = " + temperature
+ ", Chill temperature = " + chillTemperature
+ ", Signal level = " + signalLevel
+ ", Battery level = " + batteryLevel;
}

@Override
Expand All @@ -103,7 +106,25 @@ public void encodeMessage(byte[] data) throws RFXComException {
sensorId = (data[4] & 0xFF) << 8 | (data[5] & 0xFF);

windDirection = (short) ((data[6] & 0xFF) << 8 | (data[7] & 0xFF));

if (subType != SubType.WIND5) {
avgWindSpeed = (short) ((data[8] & 0xFF) << 8 | (data[9] & 0xFF)) * 0.1;
}

windSpeed = (short) ((data[10] & 0xFF) << 8 | (data[11] & 0xFF)) * 0.1;

if (subType == SubType.WIND4) {
temperature = (short) ((data[12] & 0x7F) << 8 | (data[13] & 0xFF)) * 0.1;
if ((data[12] & 0x80) != 0) {
temperature = -temperature;
}

chillTemperature = (short) ((data[14] & 0x7F) << 8 | (data[15] & 0xFF)) * 0.1;
if ((data[14] & 0x80) != 0) {
chillTemperature = -chillTemperature;
}
}

signalLevel = (byte) ((data[16] & 0xF0) >> 4);
batteryLevel = (byte) (data[16] & 0x0F);
}
Expand All @@ -123,10 +144,32 @@ public byte[] decodeMessage() {
data[6] = (byte) ((absWindDirection >> 8) & 0xFF);
data[7] = (byte) (absWindDirection & 0xFF);

if (subType != SubType.WIND5) {
int absAvgWindSpeedTimesTen = (short) Math.abs(avgWindSpeed) * 10;
data[8] = (byte) ((absAvgWindSpeedTimesTen >> 8) & 0xFF);
data[9] = (byte) (absAvgWindSpeedTimesTen & 0xFF);
}

int absWindSpeedTimesTen = (short) Math.abs(windSpeed) * 10;
data[10] = (byte) ((absWindSpeedTimesTen >> 8) & 0xFF);
data[11] = (byte) (absWindSpeedTimesTen & 0xFF);

if (subType == SubType.WIND4) {
int temp = (short) Math.abs(temperature) * 10;
data[12] = (byte) ((temp >> 8) & 0x7F);
data[13] = (byte) (temp & 0xFF);
if (temperature < 0) {
data[12] |= 0x80;
}

int chill = (short) Math.abs(chillTemperature) * 10;
data[14] = (byte) ((chill >> 8) & 0x7F);
data[15] = (byte) (chill & 0xFF);
if (chillTemperature < 0) {
data[14] |= 0x80;
}
}

data[16] = (byte) (((signalLevel & 0x0F) << 4) | (batteryLevel & 0x0F));

return data;
Expand Down Expand Up @@ -155,10 +198,23 @@ public State convertToState(RFXComValueSelector valueSelector) throws RFXComExce
} else if (valueSelector == RFXComValueSelector.WIND_DIRECTION) {

state = new DecimalType(windDirection);

} else if (valueSelector == RFXComValueSelector.AVG_WIND_SPEED) {

state = new DecimalType(avgWindSpeed);

} else if (valueSelector == RFXComValueSelector.WIND_SPEED) {

state = new DecimalType(windSpeed);

} else if (valueSelector == RFXComValueSelector.TEMPERATURE) {

state = new DecimalType(temperature);

} else if (valueSelector == RFXComValueSelector.CHILL_TEMPERATURE) {

state = new DecimalType(chillTemperature);

} else {
throw new RFXComException("Can't convert " + valueSelector + " to NumberItem");
}
Expand Down