[fineoffsetweatherstation] Add channel for the sensors battery voltage (#13284)
* [fineoffsetweatherstation] add channel for the sensors battery voltage Signed-off-by: Andreas Berger <andreas@berger-freelancer.com>pull/13291/head
parent
4fb528901f
commit
e49cde0cce
|
@ -258,9 +258,10 @@ Valid sensors:
|
||||||
### `sensor` Channels
|
### `sensor` Channels
|
||||||
|
|
||||||
| Channel | Type | Read/Write | Description |
|
| Channel | Type | Read/Write | Description |
|
||||||
|--------------|--------|------------|-----------------------------|
|
|----------------|--------------------------|------------|-----------------------------|
|
||||||
| signal | Number | R | The sensors signal strenght |
|
| signal | Number | R | The sensors signal strength |
|
||||||
| batteryLevel | Number | R | The sensors battery level |
|
| batteryLevel | Number | R | The sensors battery level |
|
||||||
|
| batteryVoltage | Number:ElectricPotential | R | The sensors battery voltage |
|
||||||
| lowBattery | Switch | R | The sensors battery status |
|
| lowBattery | Switch | R | The sensors battery status |
|
||||||
|
|
||||||
## Full Example
|
## Full Example
|
||||||
|
|
|
@ -58,5 +58,7 @@ public class FineOffsetWeatherStationBindingConstants {
|
||||||
|
|
||||||
public static final String SENSOR_CHANNEL_SIGNAL = "signal";
|
public static final String SENSOR_CHANNEL_SIGNAL = "signal";
|
||||||
public static final String SENSOR_CHANNEL_BATTERY_LEVEL = "batteryLevel";
|
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";
|
public static final String SENSOR_CHANNEL_LOW_BATTERY = "lowBattery";
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,11 @@ import java.math.BigDecimal;
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants;
|
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.binding.fineoffsetweatherstation.internal.domain.response.SensorDevice;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
import org.openhab.core.library.types.DecimalType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
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.Channel;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
|
@ -29,6 +31,8 @@ import org.openhab.core.thing.binding.BaseThingHandler;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.UnDefType;
|
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.
|
* The {@link FineOffsetSensorHandler} keeps track of the signal and battery of the sensor attached to the gateway.
|
||||||
*
|
*
|
||||||
|
@ -75,9 +79,11 @@ public class FineOffsetSensorHandler extends BaseThingHandler {
|
||||||
}
|
}
|
||||||
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_SIGNAL,
|
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_SIGNAL,
|
||||||
new DecimalType(sensorDevice.getSignal()));
|
new DecimalType(sensorDevice.getSignal()));
|
||||||
|
BatteryStatus batteryStatus = sensorDevice.getBatteryStatus();
|
||||||
|
|
||||||
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_LOW_BATTERY,
|
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_LOW_BATTERY,
|
||||||
sensorDevice.getBatteryStatus().isLow() ? OnOffType.ON : OnOffType.OFF);
|
batteryStatus.isLow() ? OnOffType.ON : OnOffType.OFF);
|
||||||
Integer percentage = sensorDevice.getBatteryStatus().getPercentage();
|
Integer percentage = batteryStatus.getPercentage();
|
||||||
if (percentage != null) {
|
if (percentage != null) {
|
||||||
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_LEVEL,
|
updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_LEVEL,
|
||||||
new DecimalType(new BigDecimal(percentage)));
|
new DecimalType(new BigDecimal(percentage)));
|
||||||
|
@ -88,5 +94,16 @@ public class FineOffsetSensorHandler extends BaseThingHandler {
|
||||||
updateThing(editThing().withoutChannels(channel).build());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,10 @@ thing-type.config.fineoffsetweatherstation.sensor.sensor.label = Sensor
|
||||||
|
|
||||||
# channel types
|
# 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.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.humidity.label = Humidity
|
||||||
channel-type.fineoffsetweatherstation.illumination.label = Illumination
|
channel-type.fineoffsetweatherstation.illumination.label = Illumination
|
||||||
channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
|
channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
|
||||||
|
@ -45,6 +47,8 @@ channel-type.fineoffsetweatherstation.uv-index.label = UV-Index
|
||||||
channel-type.fineoffsetweatherstation.uv-radiation.label = UV-Irradiation
|
channel-type.fineoffsetweatherstation.uv-radiation.label = UV-Irradiation
|
||||||
channel-type.fineoffsetweatherstation.water-leak-detection.label = Water Leak Detection
|
channel-type.fineoffsetweatherstation.water-leak-detection.label = Water Leak Detection
|
||||||
|
|
||||||
|
# channel types
|
||||||
|
|
||||||
channel = Channel
|
channel = Channel
|
||||||
thing.gateway.label = Weather Station
|
thing.gateway.label = Weather Station
|
||||||
thing.sensor.WH24.label = Weather Station - Outdoor Unit
|
thing.sensor.WH24.label = Weather Station - Outdoor Unit
|
||||||
|
@ -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-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-7.label = Leaf Moisture Channel 7
|
||||||
thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-8.label = Leaf Moisture Channel 8
|
thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-8.label = Leaf Moisture Channel 8
|
||||||
|
thing-type.fineoffsetweatherstation.sensor.channel.batteryVoltage.label = Battery Voltage
|
||||||
|
|
|
@ -143,7 +143,7 @@
|
||||||
<channel-type id="co2">
|
<channel-type id="co2">
|
||||||
<item-type>Number:Dimensionless</item-type>
|
<item-type>Number:Dimensionless</item-type>
|
||||||
<label>CO₂</label>
|
<label>CO₂</label>
|
||||||
<description>Air quality indicator</description>
|
<description>Air Quality Indicator</description>
|
||||||
<category>CarbonDioxide</category>
|
<category>CarbonDioxide</category>
|
||||||
<tags>
|
<tags>
|
||||||
<tag>Measurement</tag>
|
<tag>Measurement</tag>
|
||||||
|
|
|
@ -4,6 +4,18 @@
|
||||||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
|
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">
|
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">
|
<thing-type id="sensor" listed="false">
|
||||||
<supported-bridge-type-refs>
|
<supported-bridge-type-refs>
|
||||||
<bridge-type-ref id="gateway"/>
|
<bridge-type-ref id="gateway"/>
|
||||||
|
@ -16,6 +28,7 @@
|
||||||
<channels>
|
<channels>
|
||||||
<channel id="signal" typeId="system.signal-strength"/>
|
<channel id="signal" typeId="system.signal-strength"/>
|
||||||
<channel id="batteryLevel" typeId="system.battery-level"/>
|
<channel id="batteryLevel" typeId="system.battery-level"/>
|
||||||
|
<channel id="batteryVoltage" typeId="battery-voltage"/>
|
||||||
<channel id="lowBattery" typeId="system.low-battery"/>
|
<channel id="lowBattery" typeId="system.low-battery"/>
|
||||||
</channels>
|
</channels>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue