Shelly Binding

Here is the error when the script stops:

shelly_bluetooth_rel:91 ADV b0:c7:de:32:b9:90: mfd={“0ba9”:“AQEACwIACpC5Mt7HsA==”}, svc={“fcd2”:“RADIAWQFhAMALQA/AADwAgLxAAkAAQ==”}

12:13:00

Uncaught Error: Cannot read property ‘t’ of undefined

12:13:00

at _value = this.getBufValue(_bth.t, buffer);

12:13:00

^

12:13:00

in function “unpack” called from …ice_data[BTHOME_SVC_ID_STR]);

12:13:00

^

12:13:01

in function “getData” called from …ShellyBLUParser.getData(res); // skip if parsing failed

12:13:01

^

12:13:01

in function called from system

12:13:01

12:13:01

shelly_user_script.:397 error: Error in EjsCall

12:13:01

shelly_notification:163 Status change of script:1: {“id”:1,“errors”:[“error”],“running”:false}

Here’s mine (I have a more elaborate file in case there’s previous stuff important, but it looks like attachments are impossible):

shelly_notification:163 Status change of switch:0: {"id":0,"aenergy":{"by_minute":[0.000,0.000,0.000],"minute_ts":1706558939,"total":49589.837}}
21:09:00
shos_rpc_inst.c:355 0x3ffe2b00: duplicate id 'shellyplus1pm-d4d4da7df89c'
21:09:32
shos_rpc_inst.c:230 Shelly.GetStatus via HTTP_in POST 192.168.1.9:52218
21:09:32
shelly_bluetooth_rel:91 ADV 3c:2e:f5:69:4b:59: mfd={"0ba9":"AQEACwIACllLafUuPA=="}, svc={"fcd2":"RAAuAWQFAAAALQA/AADwAgLxAAkAAQ=="}
21:09:33
Uncaught Error: Cannot read property 't' of undefined
21:09:33
at _value = this.getBufValue(_bth.t, buffer);
21:09:33
^
21:09:33
in function "unpack" called from ...ice_data[BTHOME_SVC_ID_STR]);
21:09:33
^
21:09:33
in function "getData" called from ...ShellyBLUParser.getData(res); // skip if parsing failed
21:09:33
^
21:09:33
in function called from system
21:09:33
21:09:33
shelly_user_script.:397 error: Error in EjsCall
21:09:33
shelly_notification:163 Status change of script:1: {"id":1,"errors":["error"],"running":false}
21:09:34

Is there a bug in the shelly binding or another Problems with Shelly BLU Sensors? There are some problems, because the status is not updatet. For much details, have a look at: Problems with Shelly BLU Door/Window Sensor - Add-ons / Bindings - openHAB Community

Thanks Sebastian

See above :wink:

I took an (uneducated) guess and changed line 97 of the script from

if (_bth === "undefined") {

to:

if (typeof _bth === "undefined") {

I would expect there to be either “typeof”, or no quotation marks. But I could be wrong, of course.

Let’s see if this new code stays alive. @MiniOh, can you try this as well?

I tried in the meantime. For me is running for more than 6 hours until know.

Unfortunatelly it stopped again.

Same Error?

Do you mean you encountered the same error? The question mark is throwing me off. :slight_smile:

My code is still running since I altered it.

I now for two days had an issue with a Shelly Plus 1 not being reachable from OpenHAB.

The Thing showed “ERROR:COMM”, and in the log file I can see this error:

2024-01-31 09:46:04.636 [WARN ] [y.internal.handler.ShellyBaseHandler] - shellyplus1-7c87ce64f858: ERROR: Unable to process command ON for channel shelly:shellyplus1:4cbd683cd4:relay#output - API Timeout for POST http://192.168.0.27/rpc

During the time this error was shown, a ping to the IP address worked and I could control the Shelly via the Shelly app. After I restarted OH, also OH showed the Thing as “ONLINE” again and could control it. Any idea what could cause such a timeout, when the device is actually reachable?

With this change the script definitely runs longer. But it was finished last night and again this morning.
But I don’t have an error message about it yet.
The log only seems to be written when the browser is open and you are still logged in.

Indeed. Makes logging more difficult, of course…

Too bad it broke again… Mine is still alive, but I shouldn’t get my hopes up, apparently.

I now see that this solution was already thought of a day earlier: [shelly] Script oh-blu-scanner.js crashes in Shelly Plus when receiving buffer contains data of "undefined" type · Issue #16344 · openhab/openhab-addons · GitHub

My script is still alive, by the way.

I change line 97 on the Gateway Shelly.
But this is always “overwritten”.
Where does it come from?

I have the same.

Deactivate “BLU Gateway Support” in your openhab thing configuration of your shelly plus device, after you modified the script. This option keeps overwriting your changes.
Your shelly BLU things will still work in openhab as long as the modified script is running.

Mmm why hasn’t it overwritten my script yet?

the binding checks the current script during thing initialization, if it differs it gets updated
once you have something stable I could update the script and build a new jar

I think adding ‘typeof’ is the solution.

I tried creating a pull request, but I have another pull request (on another matter), and haven’t yet figured out how to have two parallel pull requests… :slight_smile:

I managed to add blumotion according to documentation with autodiscovery (a lot of button pressing on device was required). Thing appeared in inbox, I was able to add channels.

And now, channels are updating without problem (if you additionally modify oh-blu-scanner script on shelly gateway as mentioned above) but blumotion thing is in state: "ERROR:COMM).

The events.log look as follows:

2024-02-03 07:41:00.967 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'shelly:shellyblumotion:e8e07e944880' changed from OFFLINE (COMMUNICATION_ERROR): Unable to connect to device - BLU Device not yet connected(class org.openhab.binding.shelly.internal.api.ShellyApiException) to UNKNOWN (CONFIGURATION_PENDING): Initializing or device in sleep mode.
2024-02-03 07:41:00.969 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'shelly:shellyblumotion:e8e07e944880' changed from UNKNOWN (CONFIGURATION_PENDING): Initializing or device in sleep mode. to OFFLINE (COMMUNICATION_ERROR): Unable to connect to device - BLU Device not yet connected(class org.openhab.binding.shelly.internal.api.ShellyApiException)
2024-02-03 07:42:00.973 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'shelly:shellyblumotion:e8e07e944880' changed from OFFLINE (COMMUNICATION_ERROR): Unable to connect to device - BLU Device not yet connected(class org.openhab.binding.shelly.internal.api.ShellyApiException) to UNKNOWN (CONFIGURATION_PENDING): Initializing or device in sleep mode.
2024-02-03 07:42:00.974 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'shelly:shellyblumotion:e8e07e944880' changed from UNKNOWN (CONFIGURATION_PENDING): Initializing or device in sleep mode. to OFFLINE (COMMUNICATION_ERROR): Unable to connect to device - BLU Device not yet connected(class org.openhab.binding.shelly.internal.api.ShellyApiException)

But if I manually add blumotion as blubutton everything seems to work ok nad the thing status is ONLINE not ERROR:COMM