PV / Solar Excess Optimizer: Auto-control appliances (wallbox, dish washer, heatpump, ...) based on excess solar power

Can someone help me?

alias: Infrarotheizung Oma Bad - PV Excess Blaupause
description: ""
use_blueprint:
  path: pv_excess_control.yaml
  input:
    pv_power: sensor.helfer_solarerzeugnis_aller_wr_addieren
    import_export_power: sensor.smart_meter_ts_65a_3_wirkleistung
    automation_id: pv_excess_optimizer_infrarotheizung
    appliance_switch: switch.advanced_energy_monitoring_smartplug
    appliance_switch_interval: 2
    defined_current: 5
    actual_power: sensor.advanced_energy_monitoring_smartplug_leistung

This is my configuration.
But it wont work.

May someone can see the Problem?

I activated pyscript in my config yaml and installed it with hacs too.

The Installation of this blueprint i did like its described.

This is showing up in my log every minute

And this is what the automation trace says:

Ausgefßhrt: 24. März 2025 um 11:34:21
Ergebnis:
params:
  domain: pyscript
  service: pv_excess_control
  service_data:
    automation_id: pv_excess_optimizer_infrarotheizung
    appliance_priority: 1
    export_power: null
    pv_power: sensor.helfer_solarerzeugnis_aller_wr_addieren
    load_power: null
    home_battery_level: null
    min_home_battery_level: 100
    dynamic_current_appliance: false
    appliance_phases: 1
    min_current: 6
    max_current: 16
    appliance_switch: switch.advanced_energy_monitoring_smartplug
    appliance_switch_interval: 2
    appliance_current_set_entity: null
    actual_power: sensor.advanced_energy_monitoring_smartplug_leistung
    defined_current: 5
    appliance_on_only: false
    grid_voltage: 230
    import_export_power: sensor.smart_meter_ts_65a_3_wirkleistung
    home_battery_capacity: 0
    solar_production_forecast: null
    appliance_once_only: false
  target: {}
running_script: false

Hi @Freacly

in your Config you have to add “automation.” to your automation_id Parameter. So it should be “automation_id: automation.pv_excess_optimizer_infrarotheizung”

I had the same problem in the beginning a few days ago, now the script works but it does not exactly what i would expect it to do. It reacts very slow, so increments the current for the loads just a bit evertime it gets triggered. (Eg 0.1 A every 5 Minutes) have to take a deeper look into the code.

Regards

I’ve used this automation for years, but always found it a little tricky to re-order things and ensure that I’ve specified the grid exactly the same in all the automations etc. I’ve been working on an add-on to try replicate some of this functionality here. Thanks for the inspiration! I hope someone else finds this useful too. I plan to keep improving it for a while starting with adding support for a home battery

2 Likes

Really great work. Looking forward for the support of a home battery and maybe solcast and it will be a really great add-on to control the whole energy.

How can I make sure Dynamic Current Control only changes amps in whole numbers?

For example: change it from 3A to 4A, instead of requesting 4.1A

[14:54:42] ERROR: Got unexpected response from the API: Service not enabled

s6-rc: warning: unable to start service init-phpmyadmin: command exited 128

/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.

/run/s6/basedir/scripts/rc.init: fatal: stopping the container.

it does that already

FYI, this project has effectively been abandoned by its developer (‘Inventocasa’, @HenrikW on Github, who says he doesn’t have enough time to keep up with it), with 5 pull-requests ignored for nearly 1 year, and many bug reports and feature requests unanswered.

The good news: 2 other developers, @Nikorusti & @Kolbi on Github, have forked it and are keeping their forks mostly in-sync, and have added several popular feature requests. I’ve replaced the original with @Nikorusti’s, and it works well.

Note: For Fronius Wattpilot users, you might have difficulty with the pyscript not able to start/stop charging (although it will ramp recharge-rate up & down fine, if you manually start the Wattpilot), possibly because there’s been substantial updates to the (unofficial) Fronius Wattpilot integration recently :man_shrugging:t2:

Hello there, I am using this now for a longer time. Works fine, just abweek ago I found the “new, updated version of the blueprint”. Thx a lot for this work :+1:t5:

I even managed to get my bitcoin miner running with an HACS Integration and PV Excess with dynamic current :grin:
Now - zero costs for mining, and its adjusting the power limit up and down (made some helpers and automation).
Great👍🏾
So guys - thanks - keep on with this wonderful thing.

Regards,
Frank

Hi there,

Could you share your miner integration?
Thanx.

FYI: GitHub - nicorusti/ha-advanced-blueprints: Advanced Blueprints combined with pyscript for extra useful automations

Can you descripe your bug in a new ticket GitHub ¡ Where software is built ? :slight_smile:

A lot of new features have been implemented…

Hello,
Thanks for the information, im now using the nicorusti fork and works as working the original.

But i have a question. recently I installed a battery in my setup.
I use this automation for start the pool pump.

now, the pump never start until the battery charge at 100%, i think is because the export power is so low until the battery is chaged.
exist the way that the pump start and the battery charge more slow?

thanks

EDIT: i use a fronius gen24 primo with the “fronius modbus” integration.
I someone have this hybrid inverter can share how he setup this blueprint?
with combined “export power and load power” or with “combined import/export power”

thanks again

1 Like

I I have been using the InventoCasa script/blueprint for years without any hassle – it has been running very reliably for my setup. However, after reading about the recent improvements and optimizations in the new fork by Nicorusti, I am considering switching to this actively maintained fork.

Has anyone here already made the switch?

What are your experiences regarding stability, new features, and migration effort?

Would you recommend moving to Nicorusti, or are there any caveats I should be aware of?

Thanks in advance for your feedback!

How are your settings for the values: min_home_battery_level and solar_production_forecast?

Please feel free to open an issue on Github. With all settings and logs.

You can upgrade to nicorusti’s version without any change. Just update the two files and restart HA. Also downgrading should be an easy option if necessary just replace the two files again, restart HA and maybe save the automations again to be sure.

Hello.
the min home battery level (end of day) is 90%.
The min home battery level (to start) is disable. (maybe this is the problem???)

the solar_production_forecast (remaining) its a sensor that show the remaing. example: now is 34kw/h. and now the battery is charging at 60% with a charge of 2kw/h and the automation not launch the pool pump.

the solar production forecast for the current hour is empty

I think this is not a issue and maybe its may fault in this setup. Its correct to open a issue in my case?

thanks a lot!!!

Yeah please open an issue.

Goal SOC: 90%
Current SOC: 60%

So gthe current goal is to charge the battery… but beside the 2kw/h charging I think you still have enough excess? Otherwise 34kw couldn’t be achieved I guess.

I’m not sure how the logic currently is handling it, because charging maybe is limited to 2kw?

It should charge the battery with full power and if still excess allow other automations to start.

But please also add a debug log file with the lines from the “custom_components.pyscript” lines.

Edit:

I would expect a line like this in the debug:

                log.debug(
                    f"{inst.log_prefix} Home battery charge is sufficient ({home_battery_level}/{PvExcessControl.min_home_battery_level} %)"
                    f" OR remaining solar forecast is higher than remaining capacity of home battery. "
                    f"Calculated average excess power based on >> solar power - load power <<: {avg_excess_power} W"
                )

Or:

                log.debug(
                    f"{inst.log_prefix} Home battery charge is not sufficient ({home_battery_level}/{PvExcessControl.min_home_battery_level} %), "
                    f"OR remaining solar forecast is lower than remaining capacity of home battery. "
                    f"Calculated average excess power based on >> export power <<: {avg_excess_power} W"
                )

Hello.
When i write the other post. its 9:00am hours in spain. so its to early. the battery charged at 90% aprox 3 hours later.
At 9:00 the production its low (2kw/h) but it will increase during the day. because the battery allow more that 2kw/h of charge.

so i think the problem is easy, and you resolve my doubt.
“It should charge the battery with full power and if still excess allow other automations to start”

I thought it worked another way.
I thought that knowing there was an estimated production of 3kw during the day, even if there were no excesses because the battery was charging, it would still run the pool pump, because I would have the assurance that there would be time to charge the battery.

Two examples:
Example 1: how it works right now: first it charges the entire battery (it takes 2 hours to charge) and then it turns on the pool pump.
Example 2: what I wrongly believed: while it charges the battery, it also turns on the pump (the battery takes 4 hours to charge).

So my question is resolved!. THANKS A LOT!!! you reply was very usseful!!!

@zlakes01 , @Garfield2108 and @markusmazurczak how did you guys solve the topic of setting current? I see that Markus used a helper as a number, but how did you combined everything?

Are you using the latest version GitHub - nicorusti/ha-advanced-blueprints: Advanced Blueprints combined with pyscript for extra useful automations ? There you have various options for setting current.