custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Python script dosen't work after 2023.6 #474

Closed djjoakim closed 1 year ago

djjoakim commented 1 year ago

Hey guys! So… i run HA on a Raspberry PI, and since i didn’t like that little fan sound, i figured out how to PWM control my fan using pyscript and pigpio, this was ~2-3 years ago, and i don’t remember where i found the codes i am using. The problem now is that since 2023.6, i dosen’t work anymore! And i figure this has something to do with Python 3.11. But since i don’t know anything about python, i am hoping someone here could help!

So - i have “Pyscript Python scripting” activated, with one script “rpi_cpu_fan_pwm.py”, and after 2023.6 it dosen't work anymore.

Can someone please have a look at my python script, and see what's wrong?

Thank you so much!

This is the py script;

https://pastebin.com/TM3vLrS0

olyashok commented 1 year ago

Same here:

I only get this in logs: 2023-06-14 20:31:22.151 WARNING (MainThread) [homeassistant.helpers.frame] Detected integration that restore_state.RestoreStateData.async_get_instance is deprecated, and not intended to be called by custom components; Pleaserefactor your code to use RestoreEntity instead; restore_state.async_get(hass) can be used in the meantime. Please report issue to the custom integration author for pyscript using this method at custom_components/pyscript/init.py, line 83: restore_data = await RestoreStateData.async_get_instance(hass)

craigbarratt commented 1 year ago

@djjoakim - do you get any errors in the log file? Are you sure pigpio works with Python 3.11 - the last release was 3 years ago?

@olyashok - I need more details; are you just reporting the warning (see #473), or do you scripts fail? You'll need to provide error messages or debug what is failing. You should create a new issue if you are reporting more than that warning.

djjoakim commented 1 year ago

@djjoakim - do you get any errors in the log file? Are you sure pigpio works with Python 3.11 - the last release was 3 years ago?

Oh yeah you are right, maybe it’s pigpio that doesn’t support it.. do you mean errors in HA log, or can I find some logging that pyscript does as well? The log in pigpio doesn’t show any errors. I will check if I can find some log errors

olyashok commented 1 year ago

@djjoakim - do you get any errors in the log file? Are you sure pigpio works with Python 3.11 - the last release was 3 years ago?

@olyashok - I need more details; are you just reporting the warning (see #473), or do you scripts fail? You'll need to provide error messages or debug what is failing. You should create a new issue if you are reporting more than that warning.

I just see the warning. pyscript stopped working after 2023.6.1 for me. i removed al the scripts and pychache. restarted HA and added scripts back and it got working again. so it works with this warning but somehow requires cleanup to run.

djjoakim commented 1 year ago

@olyashok i tried what you said, and it didn't work for me.

@craigbarratt There is no errors in pigpio logger, but that dosen't mean it's not working.. Maybe the logs below can tell you something.

I have 2 logs, one for when the script is working (HA 2023.5) and one where it isn't working (2023.6) This is the working one; https://pastebin.com/xb4Ph8bR

And this is the log output of the not working one; https://pastebin.com/PxBns1Rx

djjoakim commented 1 year ago

Heh... found the solution for this one, after checking and comparing the logs, i was able to figure out the problem. For some reason, after HA update 2023.6, the CPU temperature location has changed, so the only thing i had to do was to change where the script took the CPU temperature from, and now it works again.

Thank you all for the help anyways

craigbarratt commented 1 year ago

Great - thanks for figuring it out and thanks for updating the issue with the solution.