Skip to content

Commit

Permalink
Merge pull request #279 from fboundy/patch
Browse files Browse the repository at this point in the history
Patch
  • Loading branch information
fboundy authored Oct 27, 2024
2 parents 00959b3 + cdbf7a8 commit 838a2e8
Show file tree
Hide file tree
Showing 10 changed files with 914 additions and 47 deletions.
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,18 @@ cython_debug/
#.idea/

nordpool.py
brm.py
brm.py

# Ignore files specific to VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
156 changes: 148 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PV Opt: Home Assistant Solar/Battery Optimiser v3.15.5
# PV Opt: Home Assistant Solar/Battery Optimiser v3.16.1

<h2>This documentation needs updating!</h2>

Expand All @@ -9,6 +9,8 @@ The application will integrate fully with Solis inverters which are controlled u
- [Home Assistant Solax Modbus Integration](https://github.com/wills106/homeassistant-solax-modbus)
- [Home Assistant Core Modbus Integration](https://github.com/fboundy/ha_solis_modbus)
- [Home Assistant Solarman Integration](https://github.com/StephanJoubert/home_assistant_solarman)
- [Home Assistant Solis Sensor Integration](https://github.com/hultenvp/solis-sensor) (read-only mode)
- [Home Assistant Solis Control Integration](https://github.com/stevegal/solis_control) (allows inverter control via solis_cloud and HA automations)

Once installed it should require miminal configuration. Other inverters/integrations can be added if required or can be controlled indirectly using automations.

Expand Down Expand Up @@ -49,7 +51,7 @@ This app is not stand-alone it requires the following:
<h3>2. Install HACS</h3>

1. Install HACS: https://hacs.xyz/docs/setup/download
2. Enable AppDaemon in HACS: https://hacs.xyz/docs/categories/appdaemon_apps/
2. Enable AppDaemon in HACS: https://hacs.xyz/docs/use/repositories/type/appdaemon/#making-appdaemon-apps-visible-in-hacs

<h3>3. Install the Solcast PV Solar Integration (v4.0.x)</h3>

Expand All @@ -67,7 +69,9 @@ This excellent integration will pull Octopus Price data in to Home Assistant. So

<h3>5. Install the Integration to Control Your Inverter</h3>

At present this app only works directly with Solis hybrid inverters using either the Solax Modbus integration (https://github.com/wills106/homeassistant-solax-modbus) or the HA Core Modbus as described here: https://github.com/fboundy/ha_solis_modbus. Support for the Solarman integration (https://github.com/StephanJoubert/home_assistant_solarman) is in test. At the moment writing to the inverter is disabled pending further testing by Solarman users.
At present this app only works directly with Solis hybrid inverters using either the Solax Modbus integration (https://github.com/wills106/homeassistant-solax-modbus), the HA Core Modbus as described here: https://github.com/fboundy/ha_solis_modbus, or combining the [Solis-Senor](https://github.com/hultenvp/solis-sensor) and [Solis-Control](https://github.com/hultenvp/solis_control) integrations.

Support for the Solarman integration (https://github.com/StephanJoubert/home_assistant_solarman) is in test. At the moment writing to the inverter is disabled pending further testing by Solarman users.

<h4>Solax Modbus:</h4>

Expand All @@ -88,6 +92,15 @@ At present this app only works directly with Solis hybrid inverters using either

Follow the Github instructions here: https://github.com/fboundy/ha_solis_modbus

<h4>Using Solis Cloud</h4>
<h5>Solis-Sensor</h5>

Follow the Github instruction here: https://github.com/hultenvp/solis-sensor

<h5>Solis-Control</h5>

Follow the Github instruction here: https://github.com/hultenvp/solis_control

<h4>Solarman</h4>

Follow the Github instructions here: https://github.com/StephanJoubert/home_assistant_solarman
Expand All @@ -101,9 +114,7 @@ Follow the Github instructions here: https://github.com/StephanJoubert/home_assi

<h3>7. Install Mosquitto MQTT Broker</h3>

1. Click the Home Assistant My button below to open the add-on on your Home Assistant instance:

[![](https://camo.githubusercontent.com/c16bd5d7acfc6d5163636b546783e9217e27a401c1ac5bfd93a2ef5fa23e15fe/68747470733a2f2f6d792e686f6d652d617373697374616e742e696f2f6261646765732f73757065727669736f725f6164646f6e2e737667)](https://my.home-assistant.io/redirect/supervisor_addon/?addon=a0d7b954_appdaemon&repository_url=https%3A%2F%2Fgithub.com%2Fhassio-addons%2Frepository)
1. Navigate to Settings -> Addons and click "Mosquito Broker"

2. Click on Install

Expand All @@ -113,6 +124,10 @@ Follow the Github instructions here: https://github.com/StephanJoubert/home_assi

<h3>8. Install File Editor</h3>

Follow instructions here: https://github.com/home-assistant/addons/blob/master/configurator/README.md

Navigate to Settings -> Addons -> File editor -> Configuration and set "Enforce Basepath" to "off".

<h3>9. Install Samba Share and/or Studio Code Server Add-ons If Required</h3>

Both of these add-ons make it easier to edit text files on your HA Install but aren't strictly necessary. `Samba Share` also makes it easier to access the AppDaemon log files.
Expand All @@ -125,7 +140,7 @@ AppDaemon is a loosely coupled, multi-threaded, sandboxed python execution envir

1. Click the Home Assistant My button below to open the add-on on your Home Assistant instance:

[![](https://camo.githubusercontent.com/c16bd5d7acfc6d5163636b546783e9217e27a401c1ac5bfd93a2ef5fa23e15fe/68747470733a2f2f6d792e686f6d652d617373697374616e742e696f2f6261646765732f73757065727669736f725f6164646f6e2e737667)](http://homeassistant.local:8123/hassio/addon/core_mosquitto/info)
[![](https://camo.githubusercontent.com/a54868bd2c4edb2d623ab2fef3d074fe711b45c2c1cdc0fbe4dfd296faa594f8/68747470733a2f2f6d792e686f6d652d617373697374616e742e696f2f6261646765732f73757065727669736f725f6164646f6e2e737667)](https://my.home-assistant.io/redirect/supervisor_addon/?addon=a0d7b954_appdaemon&repository_url=https%3A%2F%2Fgithub.com%2Fhassio-addons%2Frepository)

2. Click on <b>Install</b>

Expand Down Expand Up @@ -166,6 +181,11 @@ AppDaemon is a loosely coupled, multi-threaded, sandboxed python execution envir
api:
hadashboard:

And add the `client_user` and `client_password` keys to `secrets.yaml` like this:

mqtt-user: some_user
mqtt-password: some_password

3. It is also recommended that you add the following entries to `appdaemon.yaml` to improve AppDaemon logging. These settings assume that you have a `/share/logs` folder setup using `Samba Share`.

logs:
Expand Down Expand Up @@ -303,6 +323,126 @@ Restarts between Home Assistant and Add-Ons are not synchronised so it is helpfu
addon: a0d7b954_appdaemon
mode: single
<h3>14. For Solis-Control: Add Automation to Control Inverter</h3>
If you're using the solis-sensor and solis_control integrations through Solis Cloud, you'll need to add the following automation which will send the messages to Solis Cloud in order to control your inverter. N.B: It's important that you've set up the solis_control integration correctly and requested API access via Solis Cloud Technical Support.
```
alias: "Solis: Use PV_Opt"
description: "Use the output of pv_opt to control your Solis inverter via Solis Cloud."
trigger:
- platform: state
entity_id:
- sensor.pvopt_status
to: Idle (Read Only)
for:
hours: 0
minutes: 0
seconds: 5
enabled: false
- platform: time_pattern
hours: /1
minutes: "00"
seconds: "05"
- platform: time_pattern
hours: /1
minutes: "30"
seconds: "05"
- platform: state
entity_id:
- sensor.pvopt_charge_start
condition: []
action:
- if:
- condition: template
value_template: >-
{{ states('sensor.pvopt_charge_start') | as_datetime | as_local <=
today_at("23:59") }}
then:
- data:
days:
- chargeCurrent: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set chargeAmps = min((max(direction, 0.0) |
round(method='floor')), 50)%} {{ chargeAmps }}
dischargeCurrent: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set dischargeAmps = min((min(direction, 0.0) | abs |
round(method='floor')), 50) %} {{ dischargeAmps }}
chargeStartTime: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set startChargeTime = '00:00' %} {% if direction >=
0.0 -%}
{% set startChargeTime = (as_local(as_datetime(states('sensor.pvopt_charge_start')))|string)[11:16] %}
{%- endif %} {{ startChargeTime }}
chargeEndTime: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set endChargeTime = '00:00' %} {% if direction >= 0.0
-%}
{% set endChargeTime = (as_local(as_datetime(states('sensor.pvopt_charge_end')))|string)[11:16] %}
{%- endif %} {{ endChargeTime }}
dischargeStartTime: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set startDischargeTime = '00:00' %} {% if direction <
0.0 -%}
{% set startDischargeTime = (as_local(as_datetime(states('sensor.pvopt_charge_start')))|string)[11:16] %}
{%- endif %} {{ startDischargeTime }}
dischargeEndTime: >-
{% set direction = float(states('sensor.pvopt_charge_current'),
0.0) %} {% set endDischargeTime = '00:00' %} {% if direction <
0.0 -%}
{% set endDischargeTime = (as_local(as_datetime(states('sensor.pvopt_charge_end')))|string)[11:16] %}
{%- endif %} {{ endDischargeTime }}
- chargeCurrent: "0"
dischargeCurrent: "0"
chargeStartTime: "00:00"
chargeEndTime: "00:00"
dischargeStartTime: "00:00"
dischargeEndTime: "00:00"
- chargeCurrent: "0"
dischargeCurrent: "0"
chargeStartTime: "00:00"
chargeEndTime: "00:00"
dischargeStartTime: "00:00"
dischargeEndTime: "00:00"
config:
secret: <<Your secret without quotes>>
key_id: "<<Your key id with quotes>>"
username: <<Your username without quotes>>
password: <<Your password without quotes>>
plantId: "<<Your plant_id with quotes>>"
action: pyscript.solis_control
else:
- data:
days:
- chargeCurrent: "0"
dischargeCurrent: "0"
chargeStartTime: "00:00"
chargeEndTime: "00:00"
dischargeStartTime: "00:00"
dischargeEndTime: "00:00"
- chargeCurrent: "0"
dischargeCurrent: "0"
chargeStartTime: "00:00"
chargeEndTime: "00:00"
dischargeStartTime: "00:00"
dischargeEndTime: "00:00"
- chargeCurrent: "0"
dischargeCurrent: "0"
chargeStartTime: "00:00"
chargeEndTime: "00:00"
dischargeStartTime: "00:00"
dischargeEndTime: "00:00"
config:
secret: <<Your secret without quotes>>
key_id: "<<Your key id with quotes>>"
username: <<Your username without quotes>>
password: <<Your password without quotes>>
plantId: "<<Your plant_id with quotes>>"
action: pyscript.solis_control
mode: single
```
<h2>Configuration</h2>
Expand Down Expand Up @@ -394,7 +534,7 @@ The app always produces a Base forecast of future battery SOC and the associated
If `Optimise Charging` is enabled, an optimsised charging plan is calculated and writtemt to `sensor.pvopt_opt_cost`. This will also include a list of forced charge and discharge windows.
The easiest way to control and visualise this is through the `pvopt_dashboard.yaml` Lovelace yaml file included in this repo. Note that you will need to manually paste this into a dashboard and edit the charts to use the correct Octopus Energy sensors:
The easiest way to control and visualise this is through the `dashboards/pvopt_dashboard.yaml` Lovelace yaml file included in this repo. If you're using the Solis Cloud integration, you can start with the `dashboards/pvopt_dashboard_solis_cloud.yaml`. Note that you will need to manually paste this into a dashboard and edit the charts to use the correct Octopus Energy sensors:
![Alt text](image-1.png)
Expand Down
104 changes: 71 additions & 33 deletions apps/pv_opt/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ pv_opt:
# If true the personal data will be redacted from the log files.
# redact_personal_data_from_log: false

#=======================================
#Logging Category Control
#=======================================
#Defines Logging subjects to add to logfile
#If commented out, everything is logged
#Ignored if "debug" is set to False above
#
# S = Startup/Initialisation Logging
# T = Tariff loading Logging
# P = Power consumption history Logging
# C = Charge algorithm Logging
# D = Discharge algorithm Logging
# W = Charge/Discharge Windows Logging
# F = Power Flows Logging
# V = Power Flows debugging (extra verbose)
# I = inverter control/commands Logging
# E = EV debugging

# Letters can be added to "debug_categories" in any order

debug_categories: W

# ========================================
# Basic parameters
# ========================================
Expand Down Expand Up @@ -71,28 +93,28 @@ pv_opt:
# Consumption forecast parameters
# ========================================
#
use_consumption_history: false
# consumption_history_days: 6
#
daily_consumption_kwh: 17
shape_consumption_profile: true
consumption_shape:
- hour: 0
consumption: 300
- hour: 0.5
consumption: 200
- hour: 6
consumption: 150
- hour: 8
consumption: 500
- hour: 15.5
consumption: 500
- hour: 17
consumption: 750
- hour: 22
consumption: 750
- hour: 24
consumption: 300
# use_consumption_history: false
# # consumption_history_days: 6
# #
# daily_consumption_kwh: 17
# shape_consumption_profile: true
# consumption_shape:
# - hour: 0
# consumption: 300
# - hour: 0.5
# consumption: 200
# - hour: 6
# consumption: 150
# - hour: 8
# consumption: 500
# - hour: 15.5
# consumption: 500
# - hour: 17
# consumption: 750
# - hour: 22
# consumption: 750
# - hour: 24
# consumption: 300

# ========================================
# Octopus account parameters
Expand All @@ -117,6 +139,22 @@ pv_opt:

# octopus_import_tariff_code: E-1R-GO-VAR-22-10-14-N
# octopus_export_tariff_code: E-1R-OUTGOING-LITE-FIX-12M-23-09-12-N

# ========================================
# EV parameters
# ========================================
#
# If you have a Zappi Charger, uncomment next line to allow Pv_opt to detect car plugin status
# for use with the Octopus Intelligent Tariff and to allow EV consumption data to be read (if needed).
#
# ev_charger: Zappi # Default = None
#
# By default, Zappi is set to seen as part of the house load to prevent house battery discharge during car charging and allow discounting of EV consumption
# from house charging calculations.
#
# If your Zappi is not seen as part of the house load, uncomment next line to set to False.
#
# ev_part_of_house_load = False # Default = True

# ===============================================================================================================
# Brand / Integration Specific Config: SOLIS_SOLAX_MODBUS: https://github.com/wills106/homeassistant-solax-modbus
Expand Down Expand Up @@ -253,15 +291,15 @@ pv_opt:
# # - sensor.{device_name}_pv_power_2
id_solar_power: sensor.{device_name}_pv_total_power

alt_tariffs:
- name: Agile_Fix
octopus_import_tariff_code: E-1R-AGILE-23-12-06-G
octopus_export_tariff_code: E-1R-OUTGOING-FIX-12M-19-05-13-G

- name: Eco7_Fix
octopus_import_tariff_code: E-2R-VAR-22-11-01-G
octopus_export_tariff_code: E-1R-OUTGOING-FIX-12M-19-05-13-G
# alt_tariffs:
# - name: Agile_Fix
# octopus_import_tariff_code: E-1R-AGILE-23-12-06-G
# octopus_export_tariff_code: E-1R-OUTGOING-FIX-12M-19-05-13-G

# - name: Eco7_Fix
# octopus_import_tariff_code: E-2R-VAR-22-11-01-G
# octopus_export_tariff_code: E-1R-OUTGOING-FIX-12M-19-05-13-G

- name: Flux
octopus_import_tariff_code: E-1R-FLUX-IMPORT-23-02-14-G
octopus_export_tariff_code: E-1R-FLUX-EXPORT-23-02-14-G
# - name: Flux
# octopus_import_tariff_code: E-1R-FLUX-IMPORT-23-02-14-G
# octopus_export_tariff_code: E-1R-FLUX-EXPORT-23-02-14-G
Loading

0 comments on commit 838a2e8

Please sign in to comment.