Skip to content

Commit b123863

Browse files
authored
[shelly] Fix initialization of BLU Motion device (openhab#17053)
* Fixes openhab#17052 (caused by inproper initialization of the profile flags for BLU devices in general and for BLU Motion another one) Signed-off-by: Markus Michels <[email protected]>
1 parent 30fa2d2 commit b123863

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

bundles/org.openhab.binding.shelly/README.md

+21-9
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ Also check out the [Shelly Manager](doc/ShellyManager.md), which
2828
The binding supports both hardware generations
2929

3030
- Generation 1: The original Shelly devices like the Shelly 1, Shelly 2.5, Shelly Flood etc.
31-
- Generation 2: Plus / Pro series of devices
31+
- Generation 2+3: Plus / Pro series of devices
3232
- Shelly Plus Mini: Shelly Plus devices in compact format (Gen 2+3)
3333
- Shelly BLU: Bluetooth based series of devices
3434

3535
The binding provides the same feature set across all devices as good as possible and depending on device specific features.
3636

37+
`Note:` Using BLU devices or the Plus/Pro Range Extender mode require some additional configuration steps.
38+
See section [Discovery](#discovery) for details.
39+
3740
### Generation 1
3841

3942
| thing-type | Model | Vendor ID |
@@ -159,12 +162,15 @@ In this case autoCoIoT should be disabled, CoIoT events will not work, because t
159162

160163
## Firmware
161164

162-
The binding requires firmware version 1.8.2 or newer for generation 1 to enable all features, version 1.9.2+ is recommended. Generation 2 devices require 0.10.2 or newer, the Plus HT at least 0.11.0.
165+
`Generation 1`: The binding requires firmware version 1.9.2 or newer to enable all features.
166+
`Generation 2+3` Those Shelly devices require firmware version 1.0.0 or newer (1.10.0+ is recommended).
167+
`Shelly BLU deries`: Use the Shelly App to update to 1.0+ version of the firmware.
168+
163169
Some of the features are enabled dynamically or are not available depending on device type and firmware release.
164170
The Web UI of the Shelly device displays the current firmware version under Settings:Firmware and shows an update option when a newer version is available.
165171

166172
The current firmware version is reported in the Thing Properties.
167-
A dedicated channel (device#updateAvailable) indicates the availability of a newer firmware.
173+
A dedicated channel indicates the availability of a newer firmware (`device#updateAvailable`, not available for BLU devices).
168174
Use the device's Web UI or the Shelly App to perform the update.
169175

170176
Check [Advanced Users](doc/AdvancedUsers.md) for information how to update your device.
@@ -183,7 +189,7 @@ They periodically announce their presence, which is used by the binding to find
183189
Sometimes you need to run the manual discovery multiple times until you see all your devices.
184190

185191
`Important for Generation 1 Devices`:
186-
It's recommended to enable CoIoT in the device settings for faster response times (event driven rather than polling).
192+
It's strongly recommended to enable CoIoT in the device settings for faster response times (event driven rather than polling).
187193
Open the device's Web UI, section "COIOT settings" and select "Enable COCIOT".
188194
It's recommended to switch the Shelly devices to CoAP peer mode if you have only your openHAB system controlling the device.
189195
This allows routing the CoIoT/CoAP messages across multiple IP subnets without special network setup required.
@@ -193,12 +199,12 @@ Keep Multicast mode if you have multiple hosts, which should receive the CoAP up
193199
### Discovery of BLU Devices
194200

195201
The BLU devices use Bluetooth Low Energy (BLE).
196-
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.
197-
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.
202+
The binding can't communicate directly with the device, so a Shelly Plus/Pro device is required with enabled Bluetooth to use those devices as a hub.
203+
The binding automatically installs a script on the Shelly Device (oh-blu-scanner.js), which forwards the BLU events to the binding.
198204

199205
Follow these steps to add the Shelly BLU Device to openHAB
200206

201-
- Make sure a Shelly is near by the BLU device, enable Bluetooh on this device (**disabling** the 'Bluetooth Gateway' mode in the Shelly app/UI is recommended)
207+
- Make sure a Shelly is near by the BLU device, enable Bluetooh on this device (**disable the 'Bluetooth Gateway' mode** in the Shelly app/UI is recommended)
202208
- Add this thing to openHAB, make sure thing gets online
203209
- Enable "BLU Gateway Support" in the thing configuration of the Shelly device acting as gateway.
204210
- Now press the button on your BLU device, this wakes up the device and the script forwards this event to the binding
@@ -207,12 +213,18 @@ Follow these steps to add the Shelly BLU Device to openHAB
207213
- Click the device button again, the binding gets another event and creates the channels and thing changes status to ONLINE
208214
- Finally link the channels to the equipment in the model
209215

210-
Note: During initialization the script 'oh-blu-scanner.js' gets installed and activated on the Shelly Gateway device.
216+
`Note`:
217+
218+
- During initialization the script 'oh-blu-scanner.js' gets installed and activated on the Shelly Gateway device.
219+
- Shelly BLU Motion: It may take some time until channels like Lux show up.
220+
221+
Try moving the device to force status updates.
211222

212223
Every time an event is received sensors#lastUpdate and channels are updated with the reported values.
213-
device#wifiSignal indicates the Bluetooth signal strength and gets updated when the device sends an event.
224+
`device#wifiSignal` indicates the Bluetooth signal strength and gets updated when the device sends an event.
214225

215226
The binding supports multiple Shelly Plus/Pro as gateway devices unless they are added as thing and are ONLINE.
227+
In this scenario the channel `device#gatewayDevice` will report the last hub device, which forwarded a status update.
216228

217229
### Password Protected Devices
218230

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ public void initFromThingType(String name) {
236236

237237
isSensor = isHT || isFlood || isDW || isSmoke || isGas || isButton || isUNI || isMotion || isSense || isTRV
238238
|| isWall;
239-
hasBattery = isHT || isFlood || isDW || isSmoke || isButton || isMotion || isTRV;
240-
alwaysOn = !hasBattery || isMotion || isSense; // true means: device is reachable all the time (no sleep mode)
239+
hasBattery = isHT || isFlood || isDW || isSmoke || isButton || isMotion || isTRV || isBlu;
240+
alwaysOn = !hasBattery || (isMotion && !isBlu) || isSense; // true means: device is reachable all the time (no
241+
// sleep mode)
241242
}
242243

243244
public void updateFromStatus(ShellySettingsStatus status) {

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ public boolean initializeThing() throws ShellyApiException {
293293
cache.clear();
294294
resetStats();
295295

296-
logger.debug("{}: Start initializing for thing {}, type {}, IP address {}, Gen2: {}, CoIoT: {}", thingName,
297-
getThing().getLabel(), thingType, config.deviceAddress, gen2, config.eventsCoIoT);
296+
profile.initFromThingType(thingType);
297+
logger.debug(
298+
"{}: Start initializing for thing {}, type {}, Device address {}, Gen2: {}, isBlu: {}, alwaysOn: {}, hasBattery: {}, CoIoT: {}",
299+
thingName, getThing().getLabel(), thingType, config.deviceAddress.toUpperCase(), gen2, profile.isBlu,
300+
profile.alwaysOn, profile.hasBattery, config.eventsCoIoT);
298301
if (config.deviceAddress.isEmpty()) {
299302
setThingOffline(ThingStatusDetail.CONFIGURATION_ERROR, "config-status.error.missing-device-address");
300303
return false;
@@ -308,7 +311,6 @@ public boolean initializeThing() throws ShellyApiException {
308311
// Gen 1 only: Setup CoAP listener to we get the CoAP message, which triggers initialization even the thing
309312
// could not be fully initialized here. In this case the CoAP messages triggers auto-initialization (like the
310313
// Action URL does when enabled)
311-
profile.initFromThingType(thingType);
312314
if (coap != null && config.eventsCoIoT && !profile.alwaysOn) {
313315
coap.start(thingName, config);
314316
}

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,14 @@ public static Map<String, Channel> createDeviceChannels(final Thing thing, final
339339
addChannel(thing, add,
340340
profile.status.uptime != null && (!profile.hasBattery || profile.isMotion || profile.isTRV), CHGR_DEVST,
341341
CHANNEL_DEVST_UPTIME);
342-
addChannel(thing, add, true, CHGR_DEVST, CHANNEL_DEVST_UPDATE);
343342
addChannel(thing, add, true, CHGR_DEVST, CHANNEL_DEVST_HEARTBEAT);
344343
addChannel(thing, add, profile.settings.ledPowerDisable != null, CHGR_DEVST, CHANNEL_LED_POWER_DISABLE);
345344
addChannel(thing, add, profile.settings.ledStatusDisable != null, CHGR_DEVST, CHANNEL_LED_STATUS_DISABLE); // WiFi
346345
addChannel(thing, add, profile.settings.calibrated != null, CHGR_DEVST, CHANNEL_DEVST_CALIBRATED);
347346

347+
if (!profile.isBlu) { // currently not supported for BLU devices
348+
addChannel(thing, add, true, CHGR_DEVST, CHANNEL_DEVST_UPDATE);
349+
}
348350
return add;
349351
}
350352

0 commit comments

Comments
 (0)