Skip to content

Commit

Permalink
[fineoffsetweatherstation] Add channel for the sensors battery voltage (
Browse files Browse the repository at this point in the history
openhab#13284)

* [fineoffsetweatherstation] add channel for the sensors battery voltage

Signed-off-by: Andreas Berger <andreas@berger-freelancer.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
  • Loading branch information
Andy2003 authored and andrasU committed Nov 12, 2022
1 parent a4be5ff commit e640b23
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
11 changes: 6 additions & 5 deletions bundles/org.openhab.binding.fineoffsetweatherstation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,12 @@ Valid sensors:

### `sensor` Channels

| Channel | Type | Read/Write | Description |
|--------------|--------|------------|-----------------------------|
| signal | Number | R | The sensors signal strenght |
| batteryLevel | Number | R | The sensors battery level |
| lowBattery | Switch | R | The sensors battery status |
| Channel | Type | Read/Write | Description |
|----------------|--------------------------|------------|-----------------------------|
| signal | Number | R | The sensors signal strength |
| batteryLevel | Number | R | The sensors battery level |
| batteryVoltage | Number:ElectricPotential | R | The sensors battery voltage |
| lowBattery | Switch | R | The sensors battery status |

## Full Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ public class FineOffsetWeatherStationBindingConstants {

public static final String SENSOR_CHANNEL_SIGNAL = "signal";
public static final String SENSOR_CHANNEL_BATTERY_LEVEL = "batteryLevel";

public static final String SENSOR_CHANNEL_BATTERY_VOLTAGE = "batteryVoltage";
public static final String SENSOR_CHANNEL_LOW_BATTERY = "lowBattery";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants;
import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.BatteryStatus;
import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SensorDevice;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
Expand All @@ -29,6 +31,8 @@
import org.openhab.core.types.Command;
import org.openhab.core.types.UnDefType;

import tech.units.indriya.unit.Units;

/**
* The {@link FineOffsetSensorHandler} keeps track of the signal and battery of the sensor attached to the gateway.
*
Expand Down Expand Up @@ -75,9 +79,11 @@ public void updateSensorState(@Nullable SensorDevice sensorDevice) {
}
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_SIGNAL,
new DecimalType(sensorDevice.getSignal()));
BatteryStatus batteryStatus = sensorDevice.getBatteryStatus();

updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_LOW_BATTERY,
sensorDevice.getBatteryStatus().isLow() ? OnOffType.ON : OnOffType.OFF);
Integer percentage = sensorDevice.getBatteryStatus().getPercentage();
batteryStatus.isLow() ? OnOffType.ON : OnOffType.OFF);
Integer percentage = batteryStatus.getPercentage();
if (percentage != null) {
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_LEVEL,
new DecimalType(new BigDecimal(percentage)));
Expand All @@ -88,5 +94,16 @@ public void updateSensorState(@Nullable SensorDevice sensorDevice) {
updateThing(editThing().withoutChannels(channel).build());
}
}
Double voltage = batteryStatus.getVoltage();
if (voltage != null) {
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_VOLTAGE,
new QuantityType<>(voltage, Units.VOLT));
} else {
@Nullable
Channel channel = thing.getChannel(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_VOLTAGE);
if (channel != null) {
updateThing(editThing().withoutChannels(channel).build());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ thing-type.config.fineoffsetweatherstation.sensor.sensor.label = Sensor

# channel types

channel-type.fineoffsetweatherstation.battery-voltage.label = Battery Voltage
channel-type.fineoffsetweatherstation.battery-voltage.description = The voltage of the battery
channel-type.fineoffsetweatherstation.co2.label = CO₂
channel-type.fineoffsetweatherstation.co2.description = Air quality indicator
channel-type.fineoffsetweatherstation.co2.description = Air Quality Indicator
channel-type.fineoffsetweatherstation.humidity.label = Humidity
channel-type.fineoffsetweatherstation.illumination.label = Illumination
channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
Expand All @@ -45,6 +47,8 @@ channel-type.fineoffsetweatherstation.uv-index.label = UV-Index
channel-type.fineoffsetweatherstation.uv-radiation.label = UV-Irradiation
channel-type.fineoffsetweatherstation.water-leak-detection.label = Water Leak Detection

# channel types

channel = Channel
thing.gateway.label = Weather Station
thing.sensor.WH24.label = Weather Station - Outdoor Unit
Expand Down Expand Up @@ -187,3 +191,4 @@ thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-5.label
thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-6.label = Leaf Moisture Channel 6
thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-7.label = Leaf Moisture Channel 7
thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-8.label = Leaf Moisture Channel 8
thing-type.fineoffsetweatherstation.sensor.channel.batteryVoltage.label = Battery Voltage
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<channel-type id="co2">
<item-type>Number:Dimensionless</item-type>
<label>CO₂</label>
<description>Air quality indicator</description>
<description>Air Quality Indicator</description>
<category>CarbonDioxide</category>
<tags>
<tag>Measurement</tag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<channel-type id="battery-voltage">
<item-type>Number:ElectricPotential</item-type>
<label>Battery Voltage</label>
<description>The voltage of the battery</description>
<category>Energy</category>
<tags>
<tag>Measurement</tag>
<tag>Voltage</tag>
</tags>
<state pattern="%.1f %unit%" readOnly="true"/>
</channel-type>

<thing-type id="sensor" listed="false">
<supported-bridge-type-refs>
<bridge-type-ref id="gateway"/>
Expand All @@ -16,6 +28,7 @@
<channels>
<channel id="signal" typeId="system.signal-strength"/>
<channel id="batteryLevel" typeId="system.battery-level"/>
<channel id="batteryVoltage" typeId="battery-voltage"/>
<channel id="lowBattery" typeId="system.low-battery"/>
</channels>

Expand Down

0 comments on commit e640b23

Please sign in to comment.