It was what you said about not discharging the battery fully. I can see that would allow a bit of wiggle room to allow for the discharge starting a bit too soon.
hehe,
I've been playing around with chatgpt on a few different topics, I just asked it to write a home assistant script to check of fuel prices and then decide to run heatpump or gas boiler. Amazingly, it did it!
I asked:
"write a home assistant script to compare energy prices between gas and electricity and decide to operate heat pump or gas boiler"
"ChatGPT said:
To create a script for Home Assistant that compares energy prices between gas and electricity and decides whether to operate a heat pump or a gas boiler, you'll need to use Home Assistant's scripting and template features. Below is an example of how you might implement such a script.
Step 1: Set Up Sensors for Gas and Electricity Prices
First, ensure you have sensors that track the current prices for both gas and electricity. You might use sensors from energy providers or APIs, or you could set up manual sensors if the rates are static.
For example:
yaml
Copy code
sensor:
- platform: template
sensors:
gas_price_per_kwh:
value_template: "{{ states('input_number.gas_price_per_kwh') | float }}"
unit_of_measurement: "€/kWh"
electricity_price_per_kwh:
value_template: "{{ states('input_number.electricity_price_per_kwh') | float }}"
unit_of_measurement: "€/kWh"
heat_pump_efficiency:
value_template: "{{ states('input_number.heat_pump_efficiency') | float }}"
unit_of_measurement: "COP"
Step 2: Set Up Input Numbers for Manual Price Input
If your energy prices are variable and you want to input them manually:
yaml
Copy code
input_number:
gas_price_per_kwh:
name: Gas Price per kWh
min: 0
max: 1
step: 0.01
unit_of_measurement: "€/kWh"
electricity_price_per_kwh:
name: Electricity Price per kWh
min: 0
max: 1
step: 0.01
unit_of_measurement: "€/kWh"
heat_pump_efficiency:
name: Heat Pump Coefficient of Performance (COP)
min: 1
max: 5
step: 0.1
unit_of_measurement: "COP"
Step 3: Create an Automation Script
Now, create a script that compares the effective cost of operating the heat pump versus the gas boiler:
yaml
Copy code
script:
choose_heat_source:
alias: "Choose Heat Source"
sequence:
- variables:
gas_price: "{{ states('sensor.gas_price_per_kwh') | float }}"
electricity_price: "{{ states('sensor.electricity_price_per_kwh') | float }}"
heat_pump_efficiency: "{{ states('sensor.heat_pump_efficiency') | float }}"
electricity_cost_per_kwh_output: "{{ electricity_price / heat_pump_efficiency }}"
# If gas is cheaper than electricity considering the heat pump's efficiency
- condition: template
value_template: "{{ gas_price < electricity_cost_per_kwh_output }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.gas_boiler
- service: switch.turn_off
target:
entity_id: switch.heat_pump
- conditions:
# If electricity is cheaper
- condition: template
value_template: "{{ gas_price >= electricity_cost_per_kwh_output }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.heat_pump
- service: switch.turn_off
target:
entity_id: switch.gas_boiler
Step 4: Automation to Trigger the Script
You may want to trigger this script periodically or based on specific events (like a significant price change):
yaml
Copy code
automation:
- alias: "Check Heat Source"
trigger:
- platform: time_pattern
minutes: "/30" # every 30 minutes
- platform: state
entity_id:
- sensor.gas_price_per_kwh
- sensor.electricity_price_per_kwh
- sensor.heat_pump_efficiency
action:
- service: script.choose_heat_source
Explanation:
- Sensors: These track the prices of gas and electricity and the efficiency of the heat pump.
- Input Numbers: These allow for manual input of prices and efficiency.
- Script: The script calculates the effective cost of using the heat pump versus the gas boiler. It then decides which system to operate based on the cost comparison.
- Automation: This runs the script periodically or when a relevant sensor value changes.
You can further customize this to fit your specific setup or add more conditions if necessary."
I'm going to try a much more complex program request to include efficiencies, outside air temp, occupancy times, day of week etc and see how it goes.
AI is scary