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

It’s that bit there that needs to go positive for it to switch on. You should see the calculations every so often for how its getting that number which looks like:

> 2023-05-05 15:27:48.758 DEBUG (MainThread) [custom_components.pyscript.file.pv_excess_control.on_time] PV Excess (PV Power - Load Power) History: [-382.1, -1567.1, -1520.1, -555.1, -43.1, 5.899999999999999, 35.9, 71.9, 120.9, 189.9, 156.9, 224.9, 249.9, 329.9, 444.9, 472.9, 752.9, 566.9, 646.9, 1350.9, 1548.9, 1657.9, 1654.9, 1659.9, 1696.9, 1705.9, 1709.9, 1712.9, 1042.9, 1719.9, 1721.9, 1681.9, 1633.9, 1627.9, 1633.9, 1653.9, 1681.9, 1714.9, 1673.9, 1797.9, 1721.9, 1693.9, 1560.0, 510.0, 730.0, 1854.0, 1486.0, 298.0, 564.0, 62.0, -10.0, -50.0, -22.0, 28.0, 53.0, 1326.0, 662.0, -124, -284, -285]

This is the exact behaviour I’m seeing with the addtion that a reboot does not fix it.

I can try to reproduce this once I have some spare time.

Are you all using the latest version of the blueprint? There was a change a few weeks ago which could maybe fix this issue, because the trigger mechanism changed from cron to datetime-based.

Hi Henrik,

Thankyou for the very welcome blueprint, which I am hoping that I can get this working.

I have setup 3 automations as follows.

Current setup ongrid with standard inverter and panels only (no batteries in this setup)

  1. Excess solar to run hot water service priority 1
  2. Excess solar to run washing machine priority 2
  3. Excess solar to feed off grid invert to charge batteries priority 3

Each of these once setup I ran the automation, but see the following in the log. Being a total newbie can you please advice, where I need to look as it does not seem to be doing anything as such at this point.

This error originated from a custom integration.

Logger: custom_components.pyscript.function
Source: custom_components/pyscript/function.py:430
Integration: Pyscript Python scripting (documentation, issues)
First occurred: 4:23:14 PM (3 occurrences)
Last logged: 4:24:16 PM

run_coro: got exception Traceback (most recent call last): File “/config/custom_components/pyscript/eval.py”, line 695, in call raise TypeError( TypeError: pv_excess_control() missing 14 required positional arguments

Such an error will pop up when you execute the python script without passing the needed variables.

How exactly did you set up the automation?
You should first set all needed blueprint fields, then save the automation, and then execute it by clicking on the three dots in the top of the automation editor.

Thanks Henrik for the prompt reply.

  1. I setup the automation from the blueprint.
  2. The blueprint fields I setup was as follows.

a. Automation name: Excess Solar Hot water priority one (same name for the automation)
b. Appliance priority: 1
c. Mains Voltage: 230
d. PV Power: Shelly EM Grid channel 2 power (Solar)
e. Combined Import/Export Power: sensor.shelly_em_channel_1_power (Grid)
f. Remaining solar production forecast (Solcast): Solcast Forecast Remaining Today
g. Appliance Entity: Heat Pump Hot Water
h. Appliance On/Off switch interval: 5min
i. Only-On-Appliance: On
j. Appliance typical current draw: 9A
k. Appliance actual power sensor: Hot Water Power

4 Saved automation with the save button
5. Then executed it by clicking the 3 dots and selecting run

Under Step Details this is what I see.

Executed: May 7, 2023 at 4:23:57 PM
Result:
params:
domain: pyscript
service: pv_excess_control
service_data:
automation_id: Excess Solar Hot water priority one
appliance_priority: 1
export_power: null
pv_power: sensor.shelly_em_channel_2_power
load_power: null
home_battery_level: null
min_home_battery_level: 0
dynamic_current_appliance: false
three_phase_appliance: false
min_current: 0.1
max_current: 0.1
appliance_switch: switch.heat_pump_hot_water
appliance_switch_interval: 5
appliance_current_set_entity: null
actual_power: sensor.heat_pump_hot_water_power
defined_current: 9
appliance_on_only: true
grid_voltage: 230
import_export_power: sensor.shelly_em_channel_1_power
home_battery_capacity: 0
solar_production_forecast: sensor.solcast_forecast_remaining_today
target: {}
running_script: false
limit: 10

Under step config tab this is what is there
service: pyscript.pv_excess_control
data:
automation_id: Excess Solar Hot water priority one
appliance_priority: 1
export_power: null
pv_power: sensor.shelly_em_channel_2_power
load_power: null
home_battery_level: null
min_home_battery_level: 0
dynamic_current_appliance: false
three_phase_appliance: false
min_current: 0.1
max_current: 0.1
appliance_switch: switch.heat_pump_hot_water
appliance_switch_interval: 5
appliance_current_set_entity: null
actual_power: sensor.heat_pump_hot_water_power
defined_current: 9
appliance_on_only: true
grid_voltage: 230
import_export_power: sensor.shelly_em_channel_1_power
home_battery_capacity: 0
solar_production_forecast: sensor.solcast_forecast_remaining_today

Under Trace timeline tab

Triggered manually at May 7, 2023 at 4:23:57 PM

Pyscript Python scripting:

Finished at May 7, 2023 at 4:23:57 PM (runtime: 0.02 seconds)

Under related logbook entries
Excess Solar Hot water priority one triggered

4:23:57 PM - 1 hour ago

Under Automation config

mode: single
trigger:

  • platform: homeassistant
    event: start
    action:
  • service: pyscript.pv_excess_control
    data:
    automation_id: Excess Solar Hot water priority one
    appliance_priority: 1
    export_power: null
    pv_power: sensor.shelly_em_channel_2_power
    load_power: null
    home_battery_level: null
    min_home_battery_level: 0
    dynamic_current_appliance: false
    three_phase_appliance: false
    min_current: 0.1
    max_current: 0.1
    appliance_switch: switch.heat_pump_hot_water
    appliance_switch_interval: 5
    appliance_current_set_entity: null
    actual_power: sensor.heat_pump_hot_water_power
    defined_current: 9
    appliance_on_only: true
    grid_voltage: 230
    import_export_power: sensor.shelly_em_channel_1_power
    home_battery_capacity: 0
    solar_production_forecast: sensor.solcast_forecast_remaining_today
    id: ‘1683362449740’
    alias: Excess Solar Hot water priority one
    description: Excess Solar Hot water priority one

Now the Blueprint works. I’ve forgotten to set the “ Appliance typical current draw” value.

Maybe someone has a tip for me on how to solve the following.
I would like my pool pump to switch on when more electricity is produced than consumed. I don’t want the pump to be switched on and off all the time and I also want to limit the maximum time per day to 3 hours. Is that possible somehow?

@pks150781 I hope you mean pool pump :smile:

Such a feature (min/max runtime per day) is already in development, however I do not have much time to work on it at the moment.

You can help yourself by creating another automation, which switches your pool pump off and also turns the excess automation off once your desired runtime is reached. Create another automation, to turn the excess automation back on at midnight, so that the pump will start again on the next day.

UPDATE: I have deleted the automation and recreated it just now get the same error when running it.

This error originated from a custom integration.

Logger: custom_components.pyscript.function
Source: custom_components/pyscript/function.py:430
Integration: Pyscript Python scripting (documentation, issues)
First occurred: 5:37:08 PM (2 occurrences)
Last logged: 11:00:18 PM

run_coro: got exception Traceback (most recent call last): File “/config/custom_components/pyscript/eval.py”, line 695, in call raise TypeError( TypeError: pv_excess_control() missing 14 required positional arguments

@redbak Please share a complete excerpt from your home assistant logfile. At least 5-10 minutes long. You can also do that via private message.

Hi Henrik,

Just sent it to you.

Thanks

Yes I am using the most up-to-date version of the blueprint

Question - I have a Tesla T-Smart smart immersion element which very obviously shows up as a thermostat, will this blueprint be able to turn it on?

I know I can set it up in the blueprint but I don’t know if the logic will know how to turn on a thermostat (i.e. go from ‘off’ to ‘heat’.

Thanks in advance.

@Neil_Brownlee yes, it will also work with thermostat entities.

Thank you so much, that’s one more step closer to getting rid of my gas boiler :slight_smile:

Hello,
I have a SMA Energy Meter that I use as a Combined Import/Export Power-Sensor.
It gives me positive values (Watt) when I export PV excess to the grid and negative values when we need power from the grid.
This is the opposite behavior that the blueprint requires.
Any workaround? - I must note that I am not very familiar with coding :wink:
Thanks in advance

Set your own sensor template so that it swaps them around. I believe something such as

state: "{{ (0 - states('sensor.original_sensor_name')|float(0)*1000)|int(0) }}"

should turn +0.5 into -500 and -2 into +2000 so you can drop the 1000 bit if you’re already in watts and just need the positive/negative change

Hi all

Would anyone know how i could use this blueprint to pulse a switch?

My pool pump responds to bridging 4 contacts with ground to set 3 speeds + off. I have wired them with 4 on/off switchs that i can control in home assistant (through KNX).

I would need to find a way to basically turn the switch on for 1 second when the automation determines there is enough excess power.

Any ideas?

Thanks!

I think it would work with a “status toggle” automation of sorts.

In the blueprint put a custom toggle switch (not the actual switch) then have another automation that layers with it on trigger to turn the actual switches on for 1 second then off again. Then the excess blueprint will still see it as “on”, but you’ll want to consider how to turn it off. If it reacts same way, just set the custom automation so that when the custom toggle switch goes off it does it again?