Comments (16)
Already got it.
from sungrow-shx-inverter-modbus-home-assistant.
hi Louis,
good timing, I was just about to code something. Can you share and spare us some work?
Martin
from sungrow-shx-inverter-modbus-home-assistant.
This template uses the binary sensors uses the binary sensors for Battery Charging and Battery Discharging and the sensor Battery Power.
- name: "Battery Charging and Discharging Power" # Positive if charging and negative if discharging unit_of_measurement: W device_class: power state: > {% if is_state('binary_sensor.battery_charging', 'on') %} {{ (states('sensor.battery_power') | float * 1 | float) |int }} {% elif is_state('binary_sensor.battery_discharging', 'on') %} {{ (states('sensor.battery_power') | float * -1 | float) |int }} {% else %} {{ (states('sensor.battery_power') | float * 1 | float) |int }} {% endif %}
from sungrow-shx-inverter-modbus-home-assistant.
This is my first time creating a template in Home Assistant. I hope it's reliable and works with every inverter.
from sungrow-shx-inverter-modbus-home-assistant.
I would love to have a single entity with battery power, either positive (charging) or negative (discharging). Those flags charging/discharging are not very useful in my case.
from sungrow-shx-inverter-modbus-home-assistant.
That‘s exactly what my template does. It‘s positive if the battery is charging and negative if it‘s discharging.
from sungrow-shx-inverter-modbus-home-assistant.
Would love to see this in the integration!
from sungrow-shx-inverter-modbus-home-assistant.
If you want to, you can already add it to your configuration.
from sungrow-shx-inverter-modbus-home-assistant.
I just re-discovered a post from bjeanes in this integration's home assistant community thread:
https://community.home-assistant.io/t/sungrow-sh10-rt-modbus-integration/361356/29
There is some more "exception handling" involved, when the sensor did not yet delivered some valid data:
inverter_battery_power:
unique_id: inverter_battery_powerfriendly_name: Inverter battery power value_template: >- {% set current = states('sensor.inverter_battery_current') %} {% set power = states('sensor.inverter_battery_power_raw') %} {% if 'unavailable' in [current, power] %} unavailable {% elif current|float < 0.0 and power|float > 0.0 %} {{ -1 * power | float }} {% else %} {{ power | float }} {% endif %} unit_of_measurement: W device_class: power
one thing still bothers me about the naming.
When you look at the new sensor "Battery Charging and Discharging Power", it is a bit ambiguous, in which direction the energy flows. It is very subjective if the battery charging is interpreted as "good / positive value" or "bad / negative value" (or the other way round with discharging)
I did not come up with a better name, yet to describe this template sensor for the battery charge, so thinking loud here....
The grid sensor for "export power", is a bit more distingt: If it is positive, you are exporting power, if negative you can deviate that you are importing power.
Maybe rename the sensor based on your suggestion to
"Battery Charging Power", # Positive if charging and negative if discharging
and add a second sensor
"Battery Discharging Power" # Positive if discharging and negative if charging
The "Export Power" would get the mirrored "Import Power"
What do you think?
from sungrow-shx-inverter-modbus-home-assistant.
That‘s a good idea. I‘m gonna do that today. I‘m gonna post the code in this Issue.
from sungrow-shx-inverter-modbus-home-assistant.
Done. Hope it works for you.
` - name: "Battery Charging Power" # Positive if Charging and negative if Discharging
unit_of_measurement: W
device_class: power
state: >
{% if is_state('binary_sensor.battery_charging', 'on') %}
{{ (states('sensor.battery_power') | float * 1 | float) |int }}
{% elif is_state('binary_sensor.battery_discharging', 'on') %}
{{ (states('sensor.battery_power') | float * -1 | float) |int }}
{% else %}
{{ (states('sensor.battery_power') | float * 1 | float) |int }}
{% endif %}
- name: "Battery Discharging Power" # Positive if Discharging and negative if Charging
unit_of_measurement: W
device_class: power
state: >
{% if is_state('binary_sensor.battery_charging', 'on') %}
{{ (states('sensor.battery_power') | float * -1 | float) |int }}
{% elif is_state('binary_sensor.battery_discharging', 'on') %}
{{ (states('sensor.battery_power') | float * 1 | float) |int }}
{% else %}
{{ (states('sensor.battery_power') | float * 1 | float) |int }}
{% endif %}
`
from sungrow-shx-inverter-modbus-home-assistant.
made a testing branch for that, because there is no sun and I am in a rush
https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/tree/testing
Can you test? I also adapted the PV Info dashboard
Grüße aus Bielefeld!
from sungrow-shx-inverter-modbus-home-assistant.
I'm gonna test it today.
Grüße aus der Nähe von Minden.
from sungrow-shx-inverter-modbus-home-assistant.
Schreibe ich mal auf Deutsch weiter.
Wie du auf den Bildern siehst, funktioniert es soweit ganz gut. Deine Ergänzung, dass es als "Unavailable" angezeigt wird, wenn etwas nicht passt, finde ich sehr gut. Auch mit dem Power Flow Card Addon funktioniert es super.
from sungrow-shx-inverter-modbus-home-assistant.
the power flow card addon is really nice - thanks for the tip.
My configuration is
views:
- theme: Backend-selected
title: PV Power
icon: mdi:solar-power
badges: []
cards:
- type: custom:power-flow-card
kw_decimals: 2
entities:
grid: sensor.import_power
battery: sensor.battery_discharging_power
battery_charge: sensor.battery_level
solar: sensor.total_dc_power
from sungrow-shx-inverter-modbus-home-assistant.
I've also added the Tesla Style Power Flow Card, because I think that it looks quite nice. I had to create some new templates. If you want to check it out, I've put them below.
- name: "Inverter loss"
unit_of_measurement: W
device_class: power
state: >
{{ states('sensor.total_dc_power')|int(default=0) - states('sensor.battery_charging_power')|int(default=0) - states('sensor.load_power')|int(default=0) - states('sensor.export_power')|int(default=0) }}
- name: "Real load" # includes house power and inverter loss
unit_of_measurement: W
device_class: power
state: >
{{ states('sensor.load_power')|int(default=0) + states('sensor.inverter_loss')|int(default=0) }}
- name: "Import Power" # only positive
unit_of_measurement: W
device_class: power
state: >
{% if ((states('sensor.export_power') |int(default=0)) < 0 ) %}
{{ states('sensor.export_power')|int(default=0)|abs }}
{% else %}
0
{% endif %}
- name: "Grid to House" # only positive
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.import_power')|float(default=0) > states('sensor.real_load')|float(default=0) %}
{{ states('sensor.load_power')|float(default=0) }}
{% else %}
{{ states('sensor.import_power')|float(default=0) }}
{% endif %}
- name: "Grid to Battery"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.import_power')|int(default=0) > states('sensor.real_load')|int(default=0) %}
{{ states('sensor.import_power')|int(default=0) - states('sensor.real_load')|int(default=0) }}
{% else %}
0
{% endif %}
- name: "Battery to House"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.battery_charging_power')|int(default=0) < 0 %}
{% if states('sensor.battery_charging_power')|int(default=0)|abs > states('sensor.real_load')|int(default=0) %}
{{ states('sensor.real_load')|int(default=0) }}
{% else %}
{{ states('sensor.battery_charging_power')|int(default=0)|abs }}
{% endif %}
{% else %}
0
{% endif %}
- name: "Battery to Grid"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.battery_charging_power')|int(default=0) < 0 %}
{% if states('sensor.battery_charging_power')|int(default=0)|abs > states('sensor.real_load')|int(default=0) %}
{{ states('sensor.battery_charging_power')|int(default=0)|abs - states('sensor.real_load')|int(default=0) }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
- name: "Solar to Grid"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.export_power')|int(default=0) > states('sensor.battery_to_grid')|int(default=0) %}
{{ states('sensor.export_power')|int(default=0) - states('sensor.battery_to_grid')|int(default=0) }}
{% else %}
0
{% endif %}
- name: "Solar to House"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.total_dc_power')|int(default=0) > 0 and states('sensor.real_load')|int(default=0) > states('sensor.battery_to_house')|int(default=0) + states('sensor.import_power')|int(default=0) %}
{% if states('sensor.total_dc_power')|int(default=0) > states('sensor.real_load')|int(default=0) - states('sensor.battery_to_house')|int(default=0) - states('sensor.grid_to_house')|int(default=0) %}
{{ states('sensor.real_load')|int(default=0) - states('sensor.battery_to_house')|int(default=0) - states('sensor.grid_to_house')|int(default=0) }}
{% else %}
{{ states('sensor.total_dc_power')|int(default=0) }}
{% endif %}
{% else %}
0
{% endif %}
- name: "Solar to Battery"
unit_of_measurement: W
device_class: power
state: >
{% if states('sensor.total_dc_power')|int(default=0) > 0 and states('sensor.battery_charging_power')|int(default=0) > 0 %}
{% if states('sensor.battery_charging_power')|int(default=0) > states('sensor.grid_to_battery')|int(default=0) %}
{% if states('sensor.total_dc_power')|int(default=0) - states('sensor.solar_to_house')|int(default=0) > states('sensor.battery_charging_power')|int(default=0) - states('sensor.grid_to_battery')|int(default=0) %}
{{ states('sensor.battery_charging_power')|int(default=0) - states('sensor.grid_to_battery')|int(default=0) }}
{% else %}
{{ states('sensor.total_dc_power')|int(default=0) - states('sensor.solar_to_house')|int(default=0) - states('sensor.solar_to_grid')|int(default=0) }}
{% endif %}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
from sungrow-shx-inverter-modbus-home-assistant.
Related Issues (20)
- Extremely high values distort the statistics HOT 2
- Next version to extend support: Help needed to create a Python-based yaml-generator HOT 6
- Battery temp from Battery HOT 4
- 2024.1 HOT 4
- Error: device: 1 address: 13050 -> Modbus Error: [Input/Output] [Errno 32] Broken pipe HOT 2
- upgrade HA to Home Assistant core 2024.1.0 many errors HOT 2
- retries` configuration key is being removed HOT 7
- SH10RT with 14.2KWh Pylontech HOT 2
- Battery Capacity is "0.00kWh" HOT 7
- rapid reading of grid power HOT 5
- SH5k-30 issues HOT 5
- Add information of EV charger (for car) to available values
- MAC Adress instead IP HOT 6
- please delete
- Some Entities are not available HOT 10
- 2 sensors not available in the tesla dashbaord by louis HOT 1
- Zwei Wechselrichter. Daten unterschiedlich in HA und iSolarCloud | Two inverters. Different data in HA and iSolarCloud HOT 18
- Strange outage HOT 1
- Force charge and all other modbus write registers don't work HOT 1
- Retrieved data through modbus not containing data of both inverters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sungrow-shx-inverter-modbus-home-assistant.