From: Markus Michels Date: Mon, 26 Jun 2023 14:37:50 +0000 (+0200) Subject: [shelly] Add support for Shelly BLU series of devices (#15031) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=631148320ff85bbc42c9b2ee24e5b0583034975b;p=openhab-addons.git [shelly] Add support for Shelly BLU series of devices (#15031) * support for Pro 3EM (WIP) * Support for Plug-S and Smoke added * new channel resetTotals for emeters, new channel sensor#mute for Smoke * Validate Temp reported by CoAP before updating channel, ignore 999 * Add support for Shelly BLU Button and Door/Window Signed-off-by: Markus Michels --- diff --git a/bundles/org.openhab.binding.shelly/README.md b/bundles/org.openhab.binding.shelly/README.md index b00cb97aa3..07d6e97edd 100644 --- a/bundles/org.openhab.binding.shelly/README.md +++ b/bundles/org.openhab.binding.shelly/README.md @@ -76,20 +76,20 @@ The binding provides the same feature set across all devices as good as possible ### Generation 2 Plus series -| thing-type | Model | Vendor ID | -| -------------------- | -------------------------------------------------------- | --------------------------------------------- | -| shellyplus1 | Shelly Plus 1 with 1x relay | SNSW-001X16EU | -| shellyplus1pm | Shelly Plus 1PM with 1x relay + power meter | SNSW-001P16EU | -| shellyplus2pm-relay | Shelly Plus 2PM with 2x relay + power meter, relay mode | SNSW-002P16EU, SNSW-102P16EU | -| shellyplus2pm-roller | Shelly Plus 2PM with 2x relay + power meter, roller mode | SNSW-002P16EU, SNSW-102P16EU | -| shellyplusplug | Shelly Plug-S | SNPL-00112EU | -| shellyplusplug | Shelly Plug-IT | SNPL-00110IT | -| shellyplusplug | Shelly Plug-UK | SNPL-00112UK | -| shellyplusplug | Shelly Plug-US | SNPL-00116US | -| shellyplusi4 | Shelly Plus i4 with 4x AC input | SNSN-0024X | -| shellyplusi4dc | Shelly Plus i4 with 4x DC input | SNSN-0D24X | -| shellyplusht | Shelly Plus HT with temperature + humidity sensor | SNSN-0013A | -| shellyplussmoke | Shelly Plus Smoke sensor | SNSN-0031Z | +| thing-type | Model | Vendor ID | +| -------------------- | -------------------------------------------------------- | ---------------------------- | +| shellyplus1 | Shelly Plus 1 with 1x relay | SNSW-001X16EU | +| shellyplus1pm | Shelly Plus 1PM with 1x relay + power meter | SNSW-001P16EU | +| shellyplus2pm-relay | Shelly Plus 2PM with 2x relay + power meter, relay mode | SNSW-002P16EU, SNSW-102P16EU | +| shellyplus2pm-roller | Shelly Plus 2PM with 2x relay + power meter, roller mode | SNSW-002P16EU, SNSW-102P16EU | +| shellyplusplug | Shelly Plug-S | SNPL-00112EU | +| shellyplusplug | Shelly Plug-IT | SNPL-00110IT | +| shellyplusplug | Shelly Plug-UK | SNPL-00112UK | +| shellyplusplug | Shelly Plug-US | SNPL-00116US | +| shellyplusi4 | Shelly Plus i4 with 4x AC input | SNSN-0024X | +| shellyplusi4dc | Shelly Plus i4 with 4x DC input | SNSN-0D24X | +| shellyplusht | Shelly Plus HT with temperature + humidity sensor | SNSN-0013A | +| shellyplussmoke | Shelly Plus Smoke sensor | SNSN-0031Z | ### Generation 2 Pro series @@ -104,6 +104,14 @@ The binding provides the same feature set across all devices as good as possible | shellypro3em | Shelly Pro 3 with 3 integrated power meters | SPEM-003CEBEU | | shellypro4pm | Shelly Pro 4 PM with 4x relay + power meter | SPSW-004PE16EU, SPSW-104PE16EU | +### Shelly BLU + +| thing-type | Model | Vendor ID | +| ----------------- | ------------------------------------------------------ | --------- | +| shellyblubutton | Shelly BLU Button 1 | SBBT | +| shellybludw | Shelly BLU Door/Windows | SBDW | + + ## Binding Configuration The binding has the following configuration options: @@ -160,6 +168,29 @@ This allows routing the CoIoT/CoAP messages across multiple IP subnets without s You could use Shelly Manager (doc/ShellyManager.md) to easily do the setup (configuring the openHAB host as CoAP peer address). Keep Multicast mode if you have multiple hosts, which should receive the CoAP updates. +### Discovery of BLU Devices + +The BLU devices use Bluetooth Low Energy (BLE). +The binding can't communicate directly with the device, but the Plus/Pro series with firmware 0.14.1 or newer could be used as a gateway. +The binding automatically installs a script on the Shelly Device (oh-blu-scanner), which forwards the BLU events to the binding using the WebSocket channel. + +Follow these steps to add the Shelly BLU Device to openHAB +- Make sure a Shelly is near by the BLU device, enable Bluetooh on this device (the Bluetooth Gateway mode is not required) +- Add this thing to openHAB, make sure thing gets online +- Enable "BLU Gateway Support" in the thing configuration of the Shelly device acting as gateway. +- Now press the button on your BLU device, this wakes up the device and the script forwards this event to the binding +- As a result the corresponding thing should show up in the Inbox +- Add the thing (at this point no channels are created), the new thing will show status CONFIG_PENDING +- Click the device button again, the binding gets another event and creates the channels and thing changes status to ONLINE +- Finally link the channels to the equipment in the model + +Note: During initialization the script 'oh-blu-scanner.js' gets installed and activated on the Shelly Gateway device. + +Every time an event is received sensors#lastUpdate and channels are updated with the reported values. +device#wifiSignal indicates the Bluetooth signal strength and gets updated when the device sends an event. + +The binding supports multiple Shelly Plus/Pro as gateway devices unless they are added as thing and are ONLINE. + ### Password Protected Devices The Shelly devices can be configured to require authorization through a user id and password. @@ -251,6 +282,7 @@ You could also create a rule to catch those status changes or device alarms (see | eventsRoller | true: register event "trigger" when the roller updates status | no | true for roller devices | | favoriteUP | 0-4: Favorite id for UP (see Roller Favorites) | no | 0 = no favorite id | | favoriteDOWN | 0-4: Favorite id for DOWN (see Roller Favorites) | no | 0 = no favorite id | +| enableBluGateway | true: Active BLU gateway support (install script) | no | false ] ### General Notes @@ -380,7 +412,7 @@ A new alarm will be triggered on a new condition or every 5 minutes if the condi | TEMP_OVER | Above "temperature over" threshold | | VIBRATION | A vibration/tamper was detected (DW2 only) | -Refer to section [Full Example](#full-example) for examples how to catch alarm triggers in openHAB rules +Refer to section [Full Example](#full-example) for examples how to catch alarm triggers in openHAB rules. ## Channels @@ -1341,6 +1373,38 @@ Channels lastEvent and eventCount are only available if input type is set to mom | | timerActive | Switch | yes | Relay #1: ON: An auto-on/off timer is active | | | button | Trigger | yes | Event trigger, see section Button Events | +## Shelly BLU Devices + +### Shelly BLU Button 1 (thing-type: shellyblubutton) + +See notes on discovery of Shelly BLU devices above. + +| Group | Channel | Type | read-only | Description | +| ------- | ------------- | -------- | --------- | ----------------------------------------------------------------------------------- | +| status | lastEvent | String | yes | Last event type (S/SS/SSS/L) | +| | eventCount | Number | yes | Counter gets incremented every time the device issues a button event. | +| | button | Trigger | yes | Event trigger with payload, see SHORT_PRESSED or LONG_PRESSED | +| | lastUpdate | DateTime | yes | Timestamp of the last measurement | +| battery | batteryLevel | Number | yes | Battery Level in % | +| | lowBattery | Switch | yes | Low battery alert (< 20%) | +| device | gatewayDevice | String | yes | Shelly forwarded last status update (BLU gateway), could vary from packet to packet | + + + +### Shelly BLU Door/Window Sensor (thing-type: shellybludw) + +See notes on discovery of Shelly BLU devices above. + +| Group | Channel | Type | read-only | Description | +| ------- | ------------- | -------- | --------- | ----------------------------------------------------------------------------------- | +| sensors | state | Contact | yes | OPEN: Contact is open, CLOSED: Contact is closed | +| | lux | Number | yes | Brightness in Lux | +| | tilt | Number | yes | Tilt in ° (angle), -1 indicates that the sensor is not calibrated | +| | lastUpdate | DateTime | yes | Timestamp of the last update (any sensor value changed) | +| battery | batteryLevel | Number | yes | Battery Level in % | +| | lowBattery | Switch | yes | Low battery alert (< 20%) | +| device | gatewayDevice | String | yes | Shelly forwarded last status update (BLU gateway), could vary from packet to packet | + ## Full Example ### shelly.things @@ -1582,4 +1646,3 @@ sitemap demo label="Home" Number item=Shelly_Power } } -``` diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java index 57d68c6884..6ef2c453f5 100755 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java @@ -85,11 +85,14 @@ public class ShellyBindingConstants { THING_TYPE_SHELLYPLUSSMOKE, // THING_TYPE_SHELLYPLUSPLUGS, // THING_TYPE_SHELLYPLUSPLUGUS, // + THING_TYPE_SHELLYBLUBUTTON, // + THING_TYPE_SHELLYBLUDW, // THING_TYPE_SHELLYPROTECTED, // THING_TYPE_SHELLYUNKNOWN); // Thing Configuration Properties public static final String CONFIG_DEVICEIP = "deviceIp"; + public static final String CONFIG_DEVICEADDRESS = "deviceAddress"; public static final String CONFIG_HTTP_USERID = "userId"; public static final String CONFIG_HTTP_PASSWORD = "password"; public static final String CONFIG_UPDATE_INTERVAL = "updateInterval"; @@ -99,6 +102,7 @@ public class ShellyBindingConstants { public static final String PROPERTY_DEV_TYPE = "deviceType"; public static final String PROPERTY_DEV_MODE = "deviceMode"; public static final String PROPERTY_DEV_GEN = "deviceGeneration"; + public static final String PROPERTY_GW_DEVICE = "gatewayDevice"; public static final String PROPERTY_HWREV = "deviceHwRev"; public static final String PROPERTY_HWBATCH = "deviceHwBatch"; public static final String PROPERTY_UPDATE_PERIOD = "devUpdatePeriod"; @@ -230,6 +234,7 @@ public class ShellyBindingConstants { // Device Status public static final String CHANNEL_GROUP_DEV_STATUS = "device"; public static final String CHANNEL_DEVST_NAME = "deviceName"; + public static final String CHANNEL_DEVST_GATEWAY = "gatewayDevice"; public static final String CHANNEL_DEVST_UPTIME = "uptime"; public static final String CHANNEL_DEVST_HEARTBEAT = "heartBeat"; public static final String CHANNEL_DEVST_RSSI = "wifiSignal"; @@ -311,4 +316,7 @@ public class ShellyBindingConstants { public static final int UPDATE_SETTINGS_INTERVAL_SECONDS = 60; // check for updates every x sec public static final int HEALTH_CHECK_INTERVAL_SEC = 300; // Health check interval, 5min public static final int VIBRATION_FILTER_SEC = 5; // Absore duplicate vibration events for xx sec + + public static final String BUNDLE_RESOURCE_SNIPLETS = "sniplets"; // where to find code sniplets in the bundle + public static final String BUNDLE_RESOURCE_SCRIPTS = "scripts"; // where to find scrips in the bundle } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java index d5c4e32900..08e00e2028 100755 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java @@ -24,6 +24,7 @@ import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.shelly.internal.api1.Shelly1CoapServer; import org.openhab.binding.shelly.internal.config.ShellyBindingConfiguration; import org.openhab.binding.shelly.internal.handler.ShellyBaseHandler; +import org.openhab.binding.shelly.internal.handler.ShellyBluSensorHandler; import org.openhab.binding.shelly.internal.handler.ShellyLightHandler; import org.openhab.binding.shelly.internal.handler.ShellyManagerInterface; import org.openhab.binding.shelly.internal.handler.ShellyProtectedHandler; @@ -103,6 +104,11 @@ public class ShellyHandlerFactory extends BaseThingHandlerFactory { this.coapServer = new Shelly1CoapServer(); } + @Activate + void activate() { + thingTable.startDiscoveryService(bundleContext); + } + @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); @@ -123,11 +129,15 @@ public class ShellyHandlerFactory extends BaseThingHandlerFactory { || thingType.equals(THING_TYPE_SHELLYRGBW2_WHITE_STR) || thingType.equals(THING_TYPE_SHELLYRGBW2_WHITE_STR) || thingType.equals(THING_TYPE_SHELLYDUORGBW_STR) || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR)) { - logger.debug("{}: Create new thing of type {} using ShellyLightHandler", thing.getLabel(), + logger.debug("{}: Create new thing of type {} using ShellyLightHandler", thing.getLabel(), thingTypeUID.toString()); handler = new ShellyLightHandler(thing, messages, bindingConfig, thingTable, coapServer, httpClient); + } else if (thingType.startsWith("shellyblu")) { + logger.debug("{}: Create new thing of type {} using ShellyBluSensorHandler", thing.getLabel(), + thingTypeUID.toString()); + handler = new ShellyBluSensorHandler(thing, messages, bindingConfig, thingTable, coapServer, httpClient); } else if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { - logger.debug("{}: Create new thing of type {} using ShellyRelayHandler", thing.getLabel(), + logger.debug("{}: Create new thing of type {} using ShellyRelayHandler", thing.getLabel(), thingTypeUID.toString()); handler = new ShellyRelayHandler(thing, messages, bindingConfig, thingTable, coapServer, httpClient); } @@ -143,20 +153,13 @@ public class ShellyHandlerFactory extends BaseThingHandlerFactory { return null; } - public Map getThingHandlers() { - Map table = new HashMap<>(); - for (Map.Entry entry : thingTable.getTable().entrySet()) { - table.put(entry.getKey(), (ShellyManagerInterface) entry.getValue()); - } - return table; - } - /** * Remove handler of things. */ @Override protected synchronized void removeHandler(@NonNull ThingHandler thingHandler) { if (thingHandler instanceof ShellyBaseHandler) { + ((ShellyBaseHandler) thingHandler).stop(); String uid = thingHandler.getThing().getUID().getAsString(); thingTable.removeThing(uid); } @@ -185,4 +188,12 @@ public class ShellyHandlerFactory extends BaseThingHandlerFactory { public ShellyBindingConfiguration getBindingConfig() { return bindingConfig; } + + public Map getThingHandlers() { + Map table = new HashMap<>(); + for (Map.Entry entry : thingTable.getTable().entrySet()) { + table.put(entry.getKey(), (ShellyManagerInterface) entry.getValue()); + } + return table; + } } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiException.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiException.java index 5fc4f5ad4c..c562c7fdc1 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiException.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiException.java @@ -83,6 +83,8 @@ public class ShellyApiException extends Exception { string[1]); } else if (isMalformedURL()) { message = "Invalid URL: " + url; + } else if (isJsonError()) { + message = getString(getMessage()); } else if (isTimeout()) { message = "API Timeout for " + url; } else if (!isConnectionError()) { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java index f238ba5019..8b7716007d 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java @@ -46,7 +46,7 @@ public interface ShellyApiInterface { ShellySettingsStatus getStatus() throws ShellyApiException; - void setLedStatus(String ledName, Boolean value) throws ShellyApiException; + void setLedStatus(String ledName, boolean value) throws ShellyApiException; void setSleepTime(int value) throws ShellyApiException; @@ -54,9 +54,9 @@ public interface ShellyApiInterface { void setRelayTurn(int id, String turnMode) throws ShellyApiException; - public void resetMeterTotal(int id) throws ShellyApiException; + void resetMeterTotal(int id) throws ShellyApiException; - public ShellyRollerStatus getRollerStatus(int rollerIndex) throws ShellyApiException; + ShellyRollerStatus getRollerStatus(int rollerIndex) throws ShellyApiException; void setRollerTurn(int relayIndex, String turnMode) throws ShellyApiException; @@ -80,7 +80,6 @@ public interface ShellyApiInterface { void setBrightness(int id, int brightness, boolean autoOn) throws ShellyApiException; - // Valve void setValveMode(int id, boolean auto) throws ShellyApiException; void setValveTemperature(int valveId, int value) throws ShellyApiException; @@ -137,5 +136,9 @@ public interface ShellyApiInterface { void sendIRKey(String keyCode) throws ShellyApiException, IllegalArgumentException; + void postEvent(String device, String index, String event, Map parms) throws ShellyApiException; + void close(); + + void startScan(); } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java index 5f96c5280e..6230bbeb03 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java @@ -67,6 +67,8 @@ public class ShellyDeviceProfile { public boolean auth = false; public boolean alwaysOn = true; public boolean isGen2 = false; + public boolean isBlu = false; + public String gateway = ""; public String hwRev = ""; public String hwBatchId = ""; @@ -125,6 +127,10 @@ public class ShellyDeviceProfile { // Shelly UNI uses ext_temperature array, reformat to avoid GSON exception json = json.replace("ext_temperature", "ext_temperature_array"); } + if (json.contains("\"ext_humidity\":{\"0\":[{")) { + // Shelly UNI uses ext_humidity array, reformat to avoid GSON exception + json = json.replace("ext_humidity", "ext_humidity_array"); + } settingsJson = json; settings = fromJson(gson, json, ShellySettingsGlobal.class); @@ -185,6 +191,8 @@ public class ShellyDeviceProfile { return; } + isBlu = thingType.startsWith("shellyblu"); // e.g. SBBT for BU Button + isDimmer = deviceType.equalsIgnoreCase(SHELLYDT_DIMMER) || deviceType.equalsIgnoreCase(SHELLYDT_DIMMER2); isBulb = thingType.equals(THING_TYPE_SHELLYBULB_STR); isDuo = thingType.equals(THING_TYPE_SHELLYDUO_STR) || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR) @@ -201,12 +209,14 @@ public class ShellyDeviceProfile { boolean isGas = thingType.equals(THING_TYPE_SHELLYGAS_STR); boolean isUNI = thingType.equals(THING_TYPE_SHELLYUNI_STR); isHT = thingType.equals(THING_TYPE_SHELLYHT_STR) || thingType.equals(THING_TYPE_SHELLYPLUSHT_STR); - isDW = thingType.equals(THING_TYPE_SHELLYDOORWIN_STR) || thingType.equals(THING_TYPE_SHELLYDOORWIN2_STR); + isDW = thingType.equals(THING_TYPE_SHELLYDOORWIN_STR) || thingType.equals(THING_TYPE_SHELLYDOORWIN2_STR) + || thingType.equals(THING_TYPE_SHELLYBLUDW_STR); isMotion = thingType.startsWith(THING_TYPE_SHELLYMOTION_STR); isSense = thingType.equals(THING_TYPE_SHELLYSENSE_STR); isIX = thingType.equals(THING_TYPE_SHELLYIX3_STR) || thingType.equals(THING_TYPE_SHELLYPLUSI4_STR) || thingType.equals(THING_TYPE_SHELLYPLUSI4DC_STR); - isButton = thingType.equals(THING_TYPE_SHELLYBUTTON1_STR) || thingType.equals(THING_TYPE_SHELLYBUTTON2_STR); + isButton = thingType.equals(THING_TYPE_SHELLYBUTTON1_STR) || thingType.equals(THING_TYPE_SHELLYBUTTON2_STR) + || thingType.equals(THING_TYPE_SHELLYBLUBUTTON_STR); isSensor = isHT || isFlood || isDW || isSmoke || isGas || isButton || isUNI || isMotion || isSense || isTRV; hasBattery = isHT || isFlood || isDW || isSmoke || isButton || isMotion || isTRV; isTRV = thingType.equals(THING_TYPE_SHELLYTRV_STR); @@ -241,7 +251,8 @@ public class ShellyDeviceProfile { } else if (hasRelays) { return numRelays <= 1 ? CHANNEL_GROUP_RELAY_CONTROL : CHANNEL_GROUP_RELAY_CONTROL + idx; } else if (isRGBW2) { - return settings.lights == null || settings.lights.size() <= 1 ? CHANNEL_GROUP_LIGHT_CONTROL + return settings.lights == null || settings.lights != null && settings.lights.size() <= 1 + ? CHANNEL_GROUP_LIGHT_CONTROL : CHANNEL_GROUP_LIGHT_CHANNEL + idx; } else if (isLight) { return CHANNEL_GROUP_LIGHT_CONTROL; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyHttpClient.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyHttpClient.java index e9a34a4f0b..8b97f9ae36 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyHttpClient.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyHttpClient.java @@ -146,14 +146,15 @@ public class ShellyHttpClient { HTTP_AUTH_TYPE_BASIC + " " + Base64.getEncoder().encodeToString(value.getBytes())); } fillPostData(request, data); - logger.trace("{}: HTTP {} for {} {}", thingName, method, url, data); + logger.trace("{}: HTTP {} for {} {}\n{}", thingName, method, url, data, request.getHeaders()); // Do request and get response ContentResponse contentResponse = request.send(); apiResult = new ShellyApiResult(contentResponse); apiResult.httpCode = contentResponse.getStatus(); String response = contentResponse.getContentAsString().replace("\t", "").replace("\r\n", "").trim(); - logger.trace("{}: HTTP Response {}: {}", thingName, contentResponse.getStatus(), response); + logger.trace("{}: HTTP Response {}: {}\n{}", thingName, contentResponse.getStatus(), response, + contentResponse.getHeaders()); if (response.contains("\"error\":{")) { // Gen2 Shelly2RpcBaseMessage message = gson.fromJson(response, Shelly2RpcBaseMessage.class); @@ -204,7 +205,7 @@ public class ShellyHttpClient { StringContentProvider postData; postData = new StringContentProvider(type, data, StandardCharsets.UTF_8); request.content(postData); - request.header(HttpHeader.CONTENT_LENGTH, Long.toString(postData.getLength())); + // request.header(HttpHeader.CONTENT_LENGTH, Long.toString(postData.getLength())); } } @@ -253,4 +254,8 @@ public class ShellyHttpClient { public int getTimeoutsRecovered() { return timeoutsRecovered; } + + public void postEvent(String device, String index, String event, Map parms) + throws ShellyApiException { + } } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java index 6c1f1ff8cd..44f87beb04 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java @@ -739,7 +739,12 @@ public class Shelly1ApiJsonDTO { public ArrayList rollers; public ArrayList lights; public ArrayList meters; + public ArrayList emeters; + public Double totalCurrent; + public Double totalPower; + public Double totalReturned; + @SerializedName("ext_temperature") public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values @SerializedName("ext_humidity") diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTInterface.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTInterface.java index b8a2e5c441..e3bdab3e38 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTInterface.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTInterface.java @@ -30,14 +30,14 @@ import org.openhab.core.types.State; */ @NonNullByDefault public interface Shelly1CoIoTInterface { - int getVersion(); + public int getVersion(); - CoIotDescrSen fixDescription(@Nullable CoIotDescrSen sen, Map blkMap); + public CoIotDescrSen fixDescription(@Nullable CoIotDescrSen sen, Map blkMap); - void completeMissingSensorDefinition(Map sensorMap); + public void completeMissingSensorDefinition(Map sensorMap); - boolean handleStatusUpdate(List sensorUpdates, CoIotDescrSen sen, int serial, CoIotSensor s, + public boolean handleStatusUpdate(List sensorUpdates, CoIotDescrSen sen, int serial, CoIotSensor s, Map updates, ShellyColorUtils col); - String getLastWakeup(); + public String getLastWakeup(); } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTProtocol.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTProtocol.java index 50f614ce7a..9603212172 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTProtocol.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTProtocol.java @@ -210,8 +210,8 @@ public class Shelly1CoIoTProtocol { "{}: Check button[{}] for event trigger (inButtonMode={}, isButton={}, hasBattery={}, serial={}, count={}, lastEventCount[{}]={}", thingName, idx, profile.inButtonMode(idx), profile.isButton, profile.hasBattery, serial, count, idx, lastEventCount[idx]); - if (profile.inButtonMode(idx) && ((profile.hasBattery && count == 1) - || (lastEventCount[idx] != -1 && count != lastEventCount[idx]))) { + if (profile.inButtonMode(idx) && ((profile.hasBattery && count == 1) || lastEventCount[idx] == -1 + || count != lastEventCount[idx])) { if (!profile.isButton || (profile.isButton && (serial != 0x200))) { // skip duplicate on wake-up logger.debug("{}: Trigger event {}", thingName, inputEvent[idx]); thingHandler.triggerButton(group, idx, inputEvent[idx]); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java index 68a4e9262f..af71ad8449 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java @@ -176,7 +176,7 @@ public class Shelly1CoapHandler implements Shelly1CoapListener { List