openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.59k forks source link

[shelly] Support for Shelly 2PM Gen3 device #17575

Open weyto opened 1 month ago

weyto commented 1 month ago

Feature Request

Description
Currently, Shelly 2PM Gen3 devices are being incorrectly discovered as shelly:shellyunknown in openHAB 4.2.2. This leads to a non functional device in openHAB.

I request an update to the Shelly binding in openHAB to correctly identify and support Shelly 2PM Gen3 devices.

Environment:

Expected Behavior

The system should properly recognize the Shelly 2PM Gen3 devices and expose all supported features such as power monitoring, relay controls, and any other relevant functionalities.

Actual Behavior

Shelly 2PM Gen3 devices are currently discovered as shelly:shellyunknown, resulting in the device not functioning as intended within openHAB.

3DJupp commented 2 weeks ago

Hey - I have the same experience: Unfortunately an old shelly 2.5 (3y+) was broken (faulty PSU) - so i would love to use it again with the replacement / Shelly 2 PM / Gen 3

lsiepel commented 2 weeks ago

Not sure, but I guess the exact name should be logged at debug level. Can you provide it?

weyto commented 2 weeks ago

@lsiepel Is this what you searching for?

2024-11-07 08:07:18.137 [DEBUG] [discovery.ShellyDiscoveryParticipant] - shelly2pmg3-34cdb07721d8: Shelly device discovered: IP-Adress=192.168.2.43, type=shelly2pmg3
2024-11-07 08:07:18.185 [DEBUG] [g.shelly.internal.api2.Shelly2ApiRpc] - shelly2pmg3-34cdb07721d8: Connect Rpc Socket (discovery = true)
2024-11-07 08:07:18.188 [DEBUG] [helly.internal.api2.Shelly2RpcSocket] - shelly2pmg3-34cdb07721d8: Connect WebSocket, URI=ws://192.168.2.43/rpc
2024-11-07 08:07:18.366 [DEBUG] [helly.internal.api2.Shelly2RpcSocket] - shelly2pmg3-34cdb07721d8: WebSocket connected /192.168.2.100:36672<-/192.168.2.43:80, Idle Timeout=2147483647
2024-11-07 08:07:18.372 [DEBUG] [g.shelly.internal.api2.Shelly2ApiRpc] - shelly2pmg3-34cdb07721d8: Closing Rpc API (socket is connected, discovery=true)
2024-11-07 08:07:18.382 [DEBUG] [g.shelly.internal.api2.Shelly2ApiRpc] - shelly2pmg3-34cdb07721d8: Disconnect Rpc Socket
2024-11-07 08:07:18.386 [DEBUG] [helly.internal.api2.Shelly2RpcSocket] - shelly2pmg3-34cdb07721d8: Disconnecting WebSocket (/192.168.2.100:36672 -> /192.168.2.43:80)
2024-11-07 08:07:18.391 [DEBUG] [g.shelly.internal.api2.Shelly2ApiRpc] - shelly2pmg3-34cdb07721d8: WebSocket connection closed, status = 1006/Disconnected
lsiepel commented 2 weeks ago

Briefly looking at the code and it seems like there is more that needs to be done and i lack knowledge of this specific binding devices to provide a good solution in a reasonable time. With the provided information it should be doable.

weyto commented 2 weeks ago

@lsiepel : I looked into the history and found the commit fe0b1f8a201c03b4bca7b4f20121a140764b29cb by @markus7017. Is it not enought to extend ShellyThingCreator.java with the following changes?

line 74 adding 2 new lines
public static final String SHELLYDT_PLUS2PMG3_RELAY = "S3SW-002P16EU-relay";
public static final String SHELLYDT_PLUS2PMG3_ROLLER = "S3SW-002P16EU-roller";
line 385 add 2 new lines
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMG3_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMG3_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
lsiepel commented 1 week ago

Please try this jar: (openHAB 4.2.0+ compatible) https://1drv.ms/u/s!AnMcxmvEeupwj4t06zw2TX4AzbuxWQ?e=CJL6FA

Are you sure? As looking at the codes they seem a good fit to:

| shellyplus2pm-relay  | Shelly Plus 2PM with 2x relay + power meter, relay mode  | SNSW-002P16EU, SNSW-102P16EU, **S3SW-002P16EU** |
| shellyplus2pm-roller | Shelly Plus 2PM with 2x relay + power meter, roller mode | SNSW-002P16EU, SNSW-102P16EU, **S3SW-002P16EU** |

But the naming suggestu the Plus Mini gen 3 : https://www.openhab.org/addons/bindings/shelly/#generation-2-plus-mini-series-incl-gen-3

(I always get lost in the shelly naming convention.....)

weyto commented 1 week ago

I tried in a dev environment on my site. The Problem is, that the automatic discovery is not working in this environment. (I don't know why.) But what i can say is, that the device works if, i add it manually and select shellyplus2pm-roller.

lsiepel commented 1 week ago

It is pretty safe to use in your production enviroment. If you uninstall the current binding and drop this jar into your addon folder, it won't affect things, channels and other settings.

weyto commented 4 days ago

The discovery is not working with the described changes above. It is more work to do. In the ShellyThingCreator.java i found the getThingType method and there is a handling of the mode implemented. I'm not aware of all the things to do including all the dependencies. Sorry