Skip to content
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

Code error for "predbat_status" sensor #1559

Open
silkit opened this issue Oct 21, 2024 · 9 comments
Open

Code error for "predbat_status" sensor #1559

silkit opened this issue Oct 21, 2024 · 9 comments
Assignees
Labels
documentation Improvements or additions to documentation fixed

Comments

@silkit
Copy link

silkit commented Oct 21, 2024

Describe the bug
In the Predbat log. In order to calculate the discharge curve. It is looking for the entity "predbat_status"
However, the entity name that exists is "predbat.status"

Predbat version
v8.5.1

Environment details

  • Fox H1 G2 & 5x EC411
  • Standard HAOS installer on RPI4

Screenshots
Log file looking for "predbat_status"

2024-10-20 21:01:37.351983: Note: Cannot find battery charge curve (no final curve), one of the required settings for predbat_status, soc_kw, battery_power and charge_rate do not have history, check apps.yaml

Entity name as it exists in HA:
image
image

Log file
PredBat Log.txt

@gcoan
Copy link
Collaborator

gcoan commented Oct 21, 2024

It looks like just a mistake in the logged message, not a code fault.

The battery charge curve is found OK:

2024-10-20 21:01:25.368438: Curve curve can be entered into apps.yaml or set to auto:
  battery_charge_power_curve:
    100 : 0.67
    99 : 0.67
    98 : 0.67
    97 : 0.84
    96 : 0.83
    95 : 0.83
    94 : 0.82
    93 : 0.99
    92 : 0.99
    91 : 0.99
    90 : 0.97
    89 : 0.97
    86 : 0.99
    85 : 0.99

2024-10-20 21:01:25.368498: Consider setting in HA: input_number.battery_rate_max_scaling: 0.99 - currently 1.0

It's the discharge curve that then fails to be found. The sensors are all correctly listed in the log:

2024-10-20 21:01:25.443057: Find discharge curve with sensors sensor.battery_soc_kwh_calculated_sensor_for_predbat and sensor.force_discharge_power_kw_to_w_calculated_sensor_for_predbat and predbat.status and sensor.inverter_battery_power_kw_to_w_calculated_sensor_for_predbat
2024-10-20 21:01:37.076696: Find discharge curve has 15.0 days of data, max days 15

But then the logged message is that the charge curve cannot be found, it should say discharge curve cannot be found, and the predbat status sensor name is wrong:

2024-10-20 21:01:37.351983: Note: Cannot find battery charge curve (no final curve), one of the required settings for predbat_status, soc_kw, battery_power and charge_rate do not have history, check apps.yaml

I'll fix these issues with the logging.

The reason for not finding the discharge curve is almost certainly that your battery has not been fully discharged in the last 15 days so predbat can't find and calculate the discharge curve from historical data

@gcoan gcoan assigned gcoan and unassigned springfall2008 Oct 21, 2024
@gcoan gcoan added the documentation Improvements or additions to documentation label Oct 21, 2024
@silkit
Copy link
Author

silkit commented Oct 21, 2024

OK that's great - Thanks for that.
Correct - no full discharge in the last 15 days + i lost some recent sensor data 4 days ago due to my own fault. But now the dark days are coming in it won't be long before it starts fully discharging!

@gcoan
Copy link
Collaborator

gcoan commented Oct 21, 2024

No problem, I have just fixed the code, all of the different logging messages from the curve calculations said "charge curve" regardless of whether it was a charge or discharge curve being calculated !

Also corrected predbat_status.

The fix will be in the next PR I issue, thanks for raising it

@gcoan gcoan added the fixed label Oct 21, 2024
@gcoan
Copy link
Collaborator

gcoan commented Oct 21, 2024

If you want to try the fixed code, copy inverter.py from my fork https://github.com/gcoan/batpred/tree/main/apps/predbat over the top of the existing inverter.py and restart Predbat, it should produce the right messages now

@silkit
Copy link
Author

silkit commented Oct 21, 2024

Oh dear....to many "curves" lol.
I can confirm it's all fixed. I copied the code over and the changes work as expected.
It displays the correct named entity and the correct error around discharge curve and doesn't go onto say that it cannot find the charge curve.
Thanks for that fix :-)

@silkit
Copy link
Author

silkit commented Oct 21, 2024

Erm. Slight issue. Just noticed a new error shown up in the logs since replacing the inverter.py file.
Whilst Predbat had restarted itself due to the change of the configuration. I noticed it came up with an new error about not being able to find the charge_stop service. But when i looked at the GUI it was not coloured red to show an error.
image
I then when into my add-ons and force restarted Predbat. At this point it comes up with this error and predbat won't load.

-----------------------------------------------------------
Bootstrap Predbat
Startup
 Add-on: Predbat
 Home Battery Prediction and Control
-----------------------------------------------------------
 Add-on version: 1.2.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 13.2  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2024.10.3
Predbat files are installed correctly for version v8.5.1
 Home Assistant Supervisor: 2024.10.2
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
Traceback (most recent call last):
  File "/config/hass.py", line 5, in <module>
    import predbat
  File "/config/predbat.py", line 76, in <module>
    from inverter import Inverter
ImportError: cannot import name 'Inverter' from 'inverter' (/config/inverter.py)
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-timezone: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
[11:29:22] INFO: Configuring timezone (Europe/London)...
Shutdown, sleeping 20 seconds before restarting
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service base-addon-timezone successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[11:29:44] INFO: Predbat init script running
Running Predbat inside Add-on
Your API key is: b6449471b3a67b601b3a23534a50c7c50d52db91dfa100157fd81095611809ca680f8f0c2e609deb8effb5886facfd71398bc9dc15c2f81d
Bootstrap Predbat
Startup
Predbat files are installed correctly for version v8.5.1
Traceback (most recent call last):
  File "/config/hass.py", line 5, in <module>
    import predbat
  File "/config/predbat.py", line 76, in <module>
    from inverter import Inverter
ImportError: cannot import name 'Inverter' from 'inverter' (/config/inverter.py)
Shutdown, sleeping 20 seconds before restarting

I have copied back the original Inverter.py from the main fork and Predbat restarts fine. Tried again your revised .py and a force restart of Predbat and it won't start again. Original file copied back and Predbat starts fine again.

@gcoan
Copy link
Collaborator

gcoan commented Oct 21, 2024

I think the problem is that my code fork is of Predbat 8.4.11 and you're running 8.5.1. Almost certainly there's something been changed by Trefor between the two versions that means running just inverter.py from 8.4.11 alongside the rest of Predbat 8.5.1 doesn't work. I know there has been rewriting and more unit testing added to the freeze discharge logic so this might be it.

If you want to try copying the entire of my code fork across and restart the add-on, then it should work OK although you'll be downgraded to 8.4.11.

Once I PR this in to the core codebase it should be OK as most of my changes are to the documentation, only a couple of minor code changes (of which this is one)

@silkit
Copy link
Author

silkit commented Oct 21, 2024

Ok yep i understand then. That makes sense.
I'm not too sure how to copy the whole fork across (i'm ok with doing single copy & pastes but other than that, i'm not experienced enough as to how to change the forks in the settings)
I'll go back to leaving it with the error for the time being noting if doesn't affect anything and that the test reflects the changes work and wait until the main fork gets updated with the details.
Thanks again

@gcoan
Copy link
Collaborator

gcoan commented Oct 21, 2024

Yeah you don't want to change the fork in the settings, bad things might happen! You could manually copy each of the six python files across, and in fact it might just be predbat.py you need, but as you say, we've proven the messages are now correct in my fix and we know that it's just a log message issue.

I'll PR it before the end of the week, just want to finish some other documentation changes off first

springfall2008 pushed a commit that referenced this issue Oct 27, 2024
* added inverter_limit_charge/discharge to GivTCP template, tweak descriptions

* typo in github bug_report template

* Suppress discharge limit (99) from status when Freeze Discharging

* Predbat error monitor changes when upgrading from Appdaemon to Predbat addon

* Correct currency_symbols indentation in apps.yaml

* Add Predbat Web Console link to predbat dashboard

* inverter_limit - add multi-AIO note

* multi-AIO set charge/discharge limits

* Output data: add missing Predbat PV forecasts

* Review & expand best entity list in output data

* Completed review & expanding 'best' entity descriptions

* Remove duplicated and redundant predbat.soc_min_kwh entity

* Review & expand baseline entity list in output data

* Prediction window and in-day load adjustment sensors

* update automation scripts to HA 2024.10 notation

* Typo high rate entity names

* Update templates for new Octopus Intelligent sensor names in Octopus Integration v13

* Explain load scaling more clearly in apps.yaml

* Advice about setting losses correctly

* #1548 Check 'car ready to charge' sensor value is configured in apps.yaml

* #1559 Add correct curve type to curve calculation messages

* Update nordpool energy rates URL for Predbat 8.5.1

* highlight that manual car SoC must be in kWh not SoC %

* Corrected YAML indentation for rates override

* Documented h0 sensors

* energy rate overrides

* Energy saving data sensors, remove references to appdaemon-predbat install method

* Carbon and export trigger sensors

* Revert predbat.soc_min_kwh and correct friendly name

* [pre-commit.ci lite] apply automatic fixes

* Correct octopus sensor id's in apps.yaml templates

* Inverter setup capitalisation

* Simplify and resolve naming issues in sample EV setup

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation fixed
Projects
None yet
Development

No branches or pull requests

3 participants