]> git.basschouten.com Git - openhab-addons.git/commitdiff
[myStrom] Add energy consumption since last API call channel for MyStrom Plug (#15294)
authorTom Müller <125708464+grindfiner@users.noreply.github.com>
Mon, 31 Jul 2023 21:08:45 +0000 (23:08 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2023 21:08:45 +0000 (23:08 +0200)
* added missing Ws value for MyStrom Plug

Signed-off-by: Tom Müller <tompetermueller01@gmail.com>
bundles/org.openhab.binding.mystrom/README.md
bundles/org.openhab.binding.mystrom/src/main/java/org/openhab/binding/mystrom/internal/MyStromBindingConstants.java
bundles/org.openhab.binding.mystrom/src/main/java/org/openhab/binding/mystrom/internal/MyStromPlugHandler.java
bundles/org.openhab.binding.mystrom/src/main/resources/OH-INF/i18n/mystrom.properties
bundles/org.openhab.binding.mystrom/src/main/resources/OH-INF/thing/thing-types.xml
bundles/org.openhab.binding.mystrom/src/main/resources/OH-INF/update/instructions.xml [new file with mode: 0644]

index 7a42372fe616687df7a078b045305174f1232de6..8c8035910ac6a3b8796984b81852d0aec9476276 100644 (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 light’s 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 light’s 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
index 182ae7e6993524c1bb7ba0e0b634372b617087a5..5248a1ae9609419fd3f9ab3db3afe3d98500f4c9 100644 (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";
index f7bb0243a8bf2991ba086c7ba4f14bb0d6be3970..0d2a64e15d515615bff4ba7d9f1f34f7c70a6402 100644 (file)
  */
 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));
         }
     }
index 18a914510833fbd6a8ce3bd61588d5140352f9e0..b426e3c1cbd2d59b97b69eff40e5573019cfe37d 100644 (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 light’s 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
+
index 92998051f2e7ec892972f88ce17090f2f40293a4..301234a0448b8773d4e94e20376e1e14f10ec0f9 100644 (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>
                <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>
diff --git a/bundles/org.openhab.binding.mystrom/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.mystrom/src/main/resources/OH-INF/update/instructions.xml
new file mode 100644 (file)
index 0000000..5ccf6e5
--- /dev/null
@@ -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>