Skip to content

2025.4.0 Shelly Integration connection problems due to script size #142190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ThomasL1973 opened this issue Apr 3, 2025 · 32 comments · Fixed by #142487
Closed

2025.4.0 Shelly Integration connection problems due to script size #142190

ThomasL1973 opened this issue Apr 3, 2025 · 32 comments · Fixed by #142487

Comments

@ThomasL1973
Copy link

The problem

Shelly 1 PM + Shelly Plus PM Mini don't work anymore with 2025.4.0

They throw communication errors

Shelly 1 Mini Gen3 is working

What version of Home Assistant Core has the issue?

core-2025.4.0

What was the last working version of Home Assistant Core?

core-2025.3.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Shelly

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

Anything in the logs that might be useful for us?

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Apr 3, 2025

Hey there @balloob, @bieniu, @thecode, @chemelli74, @bdraco, mind taking a look at this issue as it has been labeled with an integration (shelly) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of shelly can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign shelly Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


shelly documentation
shelly source
(message by IssueLinks)

@bieniu
Copy link
Member

bieniu commented Apr 3, 2025

Please enable debug logging for the Shelly integration, restart HA, wait 10 minutes, disable debug logging, and attach the log file here.

@ThomasL1973
Copy link
Author

@Filou28
Copy link

Filou28 commented Apr 4, 2025

I had the same problem with one shelly product shelly pro EM 50 with an fixed ip adress on eth.
I had a blinking connexion
I use it for grid and solar measurement and with this version I lost all my energy config.

I have restored the last version I'll wait until this problem will be fix for upgrade for the new one.

good luck, 05/04 with you

@Langnase
Copy link

Langnase commented Apr 4, 2025

I had the same issue with 2025.4.0. Only one out of seven Shellys were connected.
I have restored the last version.

@marktay

This comment has been minimized.

@bieniu
Copy link
Member

bieniu commented Apr 4, 2025

@ThomasL1973 Your devices don't respond to Script.GetCode. Could you please remove all scripts on the devices, restart HA and catch the debug log again?

@Filou28 @Langnase @marktay Debug log please.

@Filou28
Copy link

Filou28 commented Apr 4, 2025

@bieniu I apology I'm back on 2025.3.4 I can't do it for you :(

maybe an information, I have 25 shelly devices only 1 had problems on 2025.4 and this only one have scripts

@cibar
Copy link

cibar commented Apr 4, 2025

Hello

I had this very same issue as well. My Shelly pro 1 was working but it does not work anymore. Shelly firmware id is 20250318-152129/1.5.1-g01dd7ff (1.5.1)

home-assistant_shelly_2025-04-04T14-13-58.677Z.log
more_logs.txt
Image

@tag6
Copy link

tag6 commented Apr 4, 2025

Have the issue also on 4 Shellys which are connected with heating and light for a terrarium. But if I disable the scripts, the animals get wrong temperatures because the script has the purpose to keep the temperature right! If HA can't access the shellys, no harm will be done, but disabling scripts is just a bad idea.

I even checked Firmware both 1.4.4 and 1.5.1beta on the Shelly Plus2PM.

@chemelli74
Copy link
Contributor

But if I disable the scripts, the animals get wrong temperatures because the script has the purpose to keep the temperature right!

Can you please clarify which is the issue of your shelly and what the script does ?
Maybe you can post a link to it here.

@tag6
Copy link

tag6 commented Apr 4, 2025

Just have a look at https://codeberg.org/tag/Shelly-Terrariensteuerung.git

The error is device communication error. Only the 4 PlusPM which have the terrarium script show the error, the blinds Shelly devices (a lot more, mostly Plus2PM, some 2.5) and all Shellys of other type (Dimmer, 1pm, 1pm mini etc.) are working fine.

But if I stop the script, the situation does not improve. The existence of the script on the Shelly seems to cause the problem.

This was one of my considerations, why I decided not to let Home Assistant handle these critical things. The Shelly scripts do the regulation of the temperature, and it is important that they run completely independent of Home Assistant.

@DejanBukovec
Copy link

DejanBukovec commented Apr 4, 2025

I can also confirm that after update to 2025.4 Shelly integration stop working. I use Shelly Pro 1PM with FW 1.5.1
Shelly get this requests:

Image

Does integration in 2025.4 download also scripts from shelly? Is this new feature? Maybe have issue with script size?
I have 2 scripts one with name script_1 and another with name script_2.
Script_1 have 588 lines and total size 20,8kB script_2 have 91 lines and total size is 2,55kB if this help debug issue...
Looks like it stop/crash when request script_1 data(Calling Script.GetCode RPC function) ...
Maybe this is reason why for some users work(They don't have scripts) and some doesn't work(They have scripts)...

Im make some testing and delete big script_1 and integration start working...
Then Im recreate script and put some code inside and it still work(after reload integration).
Then Im put full code inside(20,8kB) and after reload it do not work anymore...

Disabling/Enabling script do not help. Only deleting big script help.

So maybe big scripts produce issues for integration in latest version...

@chemelli74
Copy link
Contributor

Just have a look at https://codeberg.org/tag/Shelly-Terrariensteuerung.git

I took a quick look at the repo readme and saw, for example, that it suggests creating a sensor to get the script state.

This is redundant, since the integration already exposes such sensors.
You should consider avoiding duplicating functions to reduce the pressure on the Shelly device's memory and CPU.

@tag6
Copy link

tag6 commented Apr 5, 2025

Just have a look at https://codeberg.org/tag/Shelly-Terrariensteuerung.git

I took a quick look at the repo readme and saw, for example, that it suggests creating a sensor to get the script state.

Thank you for the hint, will do for sure! Of course I usually try to use existing mechanisms and I wouldn't have created an extra sensor if I'd seen an existing one.

@thecode thecode marked this as a duplicate of #142355 Apr 5, 2025
@thecode thecode changed the title 2025.4.0 Shelly Integration not working for all Shelly 2025.4.0 Shelly Integration connection problems due to script size Apr 5, 2025
@thecode thecode added the bug label Apr 5, 2025
@bieniu
Copy link
Member

bieniu commented Apr 6, 2025

This issue is a side effect of #135979 and home-assistant-libs/aioshelly#800 We are working on a fix.

For those affected, please run this command (few times) for devices with large scripts installed and paste the result here.

curl -o /dev/null -s -w "Total time: %{time_total}\n" http://<DEVICE_IP>/rpc/Script.GetCode?id=1

CC: @wjtje

@tag6
Copy link

tag6 commented Apr 6, 2025

OK ... for my devices the first request takes between 3 and 4 seconds, afterwards it is fast.

[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel1/rpc/Script.GetCode?id=1
Total time: 3.004770
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel1/rpc/Script.GetCode?id=1
Total time: 0.002051
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel1/rpc/Script.GetCode?id=1
Total time: 0.002232
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel2/rpc/Script.GetCode?id=1
Total time: 3.004514
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel2/rpc/Script.GetCode?id=1
Total time: 0.001956
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel2/rpc/Script.GetCode?id=1
Total time: 0.002595
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel3/rpc/Script.GetCode?id=1
Total time: 3.004166
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel3/rpc/Script.GetCode?id=1
Total time: 0.001753
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel3/rpc/Script.GetCode?id=1
Total time: 0.002177
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel4/rpc/Script.GetCode?id=1
Total time: 3.281378
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel4/rpc/Script.GetCode?id=1
Total time: 0.001888
[core-ssh ~]$ curl -o /dev/null -s -w "Total time: %{time_total}\n" http://terrarium-regel4/rpc/Script.GetCode?id=1
Total time: 0.001512

Edit: It takes 3 seconds again if I wait about 3 seconds or more between the requests.

@bieniu
Copy link
Member

bieniu commented Apr 6, 2025

One more request, please test this as a custom components (unzip shelly folder to /config/custom_components and restart HA).

shelly_get_code_test_v1.zip

@tag6
Copy link

tag6 commented Apr 6, 2025

With this custom component the Shelly 2 PlusPM with scripts are fine, but now the Dimmer 2 give that error that they can't be initialized.

@bieniu
Copy link
Member

bieniu commented Apr 6, 2025

Dimmer 2

This change is not related to gen1 devices.

@tag6

This comment has been minimized.

@bieniu
Copy link
Member

bieniu commented Apr 6, 2025

Let's focus on the main problem. We need to gather as much information as possible whether the custom component solves the problem with large scripts for Gen2+ devices.

@wjtje
Copy link
Contributor

wjtje commented Apr 6, 2025

After some simple testing on a Shelly Plus2PM I found the following things:

  • The size of script when it's becomes a problem depends on the device
  • device.script_getcode results into a timeout because the device doesn't respond anything
  • The device does respond using a HTTP request but doesn't using a WebSocket
  • The web interface on the device is able to get the script because it reads in 1024 byte chunks

I think that the best solution is to modify how we get the script from the device by reading in 1024 byte chunks to mimic the web interface of the device.

@DejanBukovec
Copy link

Is this "reading script" new "feature" in 2025.4.0 ? Im asking this because same Shelly with same script has work without issues for around 2 years... Only changes which has been made in 2 years has been shelly firmwares and HA updates...

@thecode
Copy link
Member

thecode commented Apr 6, 2025

Is this "reading script" new "feature" in 2025.4.0 ? Im asking this because same Shelly with same script has work without issues for around 2 years... Only changes which has been made in 2 years has been shelly firmwares and HA updates...

Yes, although part of it was already at 2025.3.0, there are two places that read a script, for one of them we have a fix for not reading the script, the 2nd one is what we discuss here

@ThomasL1973
Copy link
Author

@ThomasL1973 Your devices don't respond to Script.GetCode. Could you please remove all scripts on the devices, restart HA and catch the debug log again?

@Filou28 @Langnase @marktay Debug log please.

home-assistant_shelly_2025-04-07T06-42-43.116Z.log

@ThomasL1973
Copy link
Author

ThomasL1973 commented Apr 7, 2025

This issue is a side effect of #135979 and home-assistant-libs/aioshelly#800 We are working on a fix.

For those affected, please run this command (few times) for devices with large scripts installed and paste the result here.

curl -o /dev/null -s -w "Total time: %{time_total}\n" http://<DEVICE_IP>/rpc/Script.GetCode?id=1

CC: @wjtje

Shelly 1 PM Running 3 Scripts:
root@cIoBroker:~# curl -o /dev/null -s -w "Total time: %{time_total}\n" http://192.168.179.176/rpc/Script.GetCode?id=1
Total time: 0.018581

Shelly Plus PM Mini - Running 1 Script
root@cIoBroker:# curl -o /dev/null -s -w "Total time: %{time_total}\n" http://192.168.179.178/rpc/Script.GetCode?id=1
Total time: 0.021329
root@cIoBroker:
#

@oskarfessel
Copy link

Looks to me the answer time does not matter. All devices do not work since 2025.4.0 (including 2025.4.1).

Shelly plus 1PM with two scripts, both deactivated:
Total time: 0.283913
Shelly plus 1PM with one active script
Total time: 0.015972
Shelly Blue Gateway with one active script:
Total time: 0.551820
Shelly Plus Plug S with one deactivated script:
Total time: 1.143236
Same Type with active script:
Total time: 0.040001

Plus plug S with no script at all works fine:
Total time: 0.112628

And all times vary very much, depending on when the device was last accessed...

@oskarfessel
Copy link

The custom component fixed the Shelly integration for all my tested devices. Looks good to me.

@ThomasL1973
Copy link
Author

One more request, please test this as a custom components (unzip shelly folder to /config/custom_components and restart HA).

shelly_get_code_test_v1.zip

Fixed all Probs

@DejanBukovec
Copy link

@thecode But is necessary that HA read script content? Im not sure if someone will use it to read/edit content of script...
I think only reading state(Running/stopped/enabled/disabled) will be enough and option to enable/disable and start/stop script...
This can be done by:
/rpc/Script.List - To get list of scripts and their status
/rpc/Script.Start - To start script
/rpc/Script.Stop - To stop script
/rpc/Script.SetConfig - To enable/disable script

All this RPC calls work without issues on my device with "big" script which HA 2025.4.X have problems to read them...

@bieniu
Copy link
Member

bieniu commented Apr 7, 2025

But is necessary that HA read script content?

Integration gets the script to check if it can create an event entity for its needs.

image

@bieniu bieniu marked this as a duplicate of #142686 Apr 10, 2025
@bieniu bieniu marked this as a duplicate of #142661 Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.