[myStrom] Add energy consumption since last API call channel for MyStrom Plug (#15294)

* added missing Ws value for MyStrom Plug

Signed-off-by: Tom Müller <tompetermueller01@gmail.com>
This commit is contained in:
Tom Müller 2023-07-31 23:08:45 +02:00 committed by GitHub
parent edc7761cd6
commit 27d784a4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 16 deletions

View File

@ -50,18 +50,19 @@ Disabling/enabling the thing can be used to update the properties.
## Channels
| Channel ID | Item Type | Read only | Description | Thing types supporting this channel |
| ---------------- | -------------------- | --------- | --------------------------------------------------------------------- |-------------------------------------|
| switch | Switch | false | Turn the device on or off | mystromplug, mystrombulb |
| power | Number:Power | true | The currently delivered power | mystromplug, mystrombulb |
| temperature | Number:Temperature | true | The temperature at the plug | mystromplug, mystrompir |
| color | Color | false | The color we set the bulb to (mode 'hsv') | mystrombulb |
| colorTemperature | Dimmer | false | The color temperature of the bulb in mode 'mono' (percentage) | mystrombulb |
| brightness | Dimmer | false | The brightness of the bulb in mode 'mono' | mystrombulb |
| ramp | Number:Time | false | Transition time from the lights current state to the new state. [ms] | mystrombulb |
| mode | String | false | The color mode we want the Bulb to set to (rgb, hsv or mono) | mystrombulb |
| light | Dimmer | true | The brightness of the Room. | mystrompir |
| motion | Switch | true | Motionstatus of the sensor | mystrompir |
| Channel ID | Item Type | Read only | Description | Thing types supporting this channel |
|---------------------------------|--------------------|-----------|---------------------------------------------------------------------------------------------------|------------------------------------|
| switch | Switch | false | Turn the device on or off | mystromplug, mystrombulb |
| power | Number:Power | true | The currently delivered power | mystromplug, mystrombulb |
| energy-consumed-since-last-call | Number:Energy | true | The watt seconds / Energy consumed since last call. Useful for accurate data logging and analysis | mystromplug |
| temperature | Number:Temperature | true | The temperature at the plug | mystromplug, mystrompir |
| color | Color | false | The color we set the bulb to (mode 'hsv') | mystrombulb |
| colorTemperature | Dimmer | false | The color temperature of the bulb in mode 'mono' (percentage) | mystrombulb |
| brightness | Dimmer | false | The brightness of the bulb in mode 'mono' | mystrombulb |
| ramp | Number:Time | false | Transition time from the lights current state to the new state. [ms] | mystrombulb |
| mode | String | false | The color mode we want the Bulb to set to (rgb, hsv or mono) | mystrombulb |
| light | Dimmer | true | The brightness of the Room. | mystrompir |
| motion | Switch | true | Motionstatus of the sensor | mystrompir |
## Full Example
@ -74,12 +75,13 @@ Thing mystrom:mystromplug:d6217a31 "Plug" [hostname="hostname|ip"]
### Item Configuration
```java
Switch PlugSwitch "Plug" {channel="mystrom:mystromplug:d6217a31:switch"}
Number:Temperature PlugTemperature "Temperature: [%.1f °C]" {channel="mystrom:mystromplug:d6217a31:temperature"}
Number:Power PlugPower "Power: [%.1f W]" {channel="mystrom:mystromplug:d6217a31:power"}
Switch PlugSwitch "Plug" {channel="mystrom:mystromplug:d6217a31:switch"}
Number:Temperature PlugTemperature "Temperature: [%.1f °C]" {channel="mystrom:mystromplug:d6217a31:temperature"}
Number:Power PlugPower "Power: [%.1f W]" {channel="mystrom:mystromplug:d6217a31:power"}
Number:Energy PlugEnergyConsumedSinceLastCall "Ws: [%.1f Ws]" {channel="mystrom:mystromplug:d6217a31:energy-consumed-since-last-call"}
```
### Sitemap Configuration
```perl

View File

@ -38,6 +38,7 @@ public class MyStromBindingConstants {
// List of all Channel ids
public static final String CHANNEL_SWITCH = "switch";
public static final String CHANNEL_POWER = "power";
public static final String CHANNEL_ENERGY_CONSUMED_SINCE_LAST_CALL = "energy-consumed-since-last-call";
public static final String CHANNEL_TEMPERATURE = "temperature";
public static final String CHANNEL_COLOR = "color";
public static final String CHANNEL_RAMP = "ramp";

View File

@ -12,11 +12,13 @@
*/
package org.openhab.binding.mystrom.internal;
import static org.openhab.binding.mystrom.internal.MyStromBindingConstants.CHANNEL_ENERGY_CONSUMED_SINCE_LAST_CALL;
import static org.openhab.binding.mystrom.internal.MyStromBindingConstants.CHANNEL_POWER;
import static org.openhab.binding.mystrom.internal.MyStromBindingConstants.CHANNEL_SWITCH;
import static org.openhab.binding.mystrom.internal.MyStromBindingConstants.CHANNEL_TEMPERATURE;
import static org.openhab.core.library.unit.SIUnits.CELSIUS;
import static org.openhab.core.library.unit.Units.WATT;
import static org.openhab.core.library.unit.Units.WATT_SECOND;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
@ -50,6 +52,7 @@ public class MyStromPlugHandler extends AbstractMyStromHandler {
private static class MyStromReport {
public float power;
public float Ws;
public boolean relay;
public float temperature;
}
@ -96,6 +99,7 @@ public class MyStromPlugHandler extends AbstractMyStromHandler {
if (report != null) {
updateState(CHANNEL_SWITCH, report.relay ? OnOffType.ON : OnOffType.OFF);
updateState(CHANNEL_POWER, QuantityType.valueOf(report.power, WATT));
updateState(CHANNEL_ENERGY_CONSUMED_SINCE_LAST_CALL, QuantityType.valueOf(report.Ws, WATT_SECOND));
updateState(CHANNEL_TEMPERATURE, QuantityType.valueOf(report.temperature, CELSIUS));
}
}

View File

@ -38,6 +38,8 @@ thing-type.config.mystrom.mystromplug.refresh.description = Specifies the refres
# channel types
channel-type.mystrom.energy-consumed-since-last-call-channel.label = Energy Consumption
channel-type.mystrom.energy-consumed-since-last-call-channel.description = Energy consumed since last API call
channel-type.mystrom.mode-channel.label = Mode
channel-type.mystrom.mode-channel.description = The color mode we want the Bulb to set to
channel-type.mystrom.mode-channel.command.option.rgb = RGB
@ -49,3 +51,4 @@ channel-type.mystrom.ramp-channel.label = Ramp
channel-type.mystrom.ramp-channel.description = Transition time from the lights current state to the new state.
channel-type.mystrom.temperature-channel.label = Temperature
channel-type.mystrom.temperature-channel.description = The current temperature at the plug

View File

@ -11,6 +11,7 @@
<channels>
<channel id="switch" typeId="system.power"/>
<channel id="power" typeId="power-channel"/>
<channel id="energy-consumed-since-last-call" typeId="energy-consumed-since-last-call-channel"/>
<channel id="temperature" typeId="temperature-channel"/>
</channels>
@ -25,6 +26,7 @@
<property name="dns"/>
<property name="static"/>
<property name="connected"/>
<property name="thingTypeVersion">1</property>
</properties>
<representation-property>mac</representation-property>
@ -157,6 +159,14 @@
<state pattern="%.3f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="energy-consumed-since-last-call-channel">
<item-type>Number:Energy</item-type>
<label>Energy Consumption</label>
<description>Energy consumed since last API call</description>
<state pattern="%.2f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="temperature-channel">
<item-type>Number:Temperature</item-type>
<label>Temperature</label>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
<thing-type uid="mystrom:mystromplug">
<instruction-set targetVersion="1">
<add-channel id="energy-consumed-since-last-call">
<type>mystrom:energy-consumed-since-last-call-channel</type>
<label>Energy Consumption</label>
</add-channel>
</instruction-set>
</thing-type>
</update:update-descriptions>