Thank you Alex, really appreciated!
On to the reading I go
My pleasure Bobby.
Ok, now I’m a bit confused
template:
#Split power in and out of battery
- sensor:
- name: "Battery input power"
unit_of_measurement: "W"
device_class: energy
state_class: total_increasing
state: >
{% if states('sensor.battery_power_victron')|float >= 0 %}
{{ states('sensor.battery_power_victron') }}
{% else %}
0
{% endif %}
- name: "Battery output power"
unit_of_measurement: "W"
device_class: energy
state_class: total_increasing
state: >
{% if states('sensor.battery_power_victron')|float < 0 %}
{{ -1 * states('sensor.battery_power_victron')|float }}
{% else %}
0
{% endif %}
Its still now showing up
What am I doing wrong?
First of all, I think also for batteries the integration needs ENERGY not POWER sensors. I don’t have a battery so I never tested this. So the device_class you used is wrong.
Second: those sensors are not total_increasing like you configured them, they are a measurement.
I guess you read too quickly…
Ok, I think I get it
My battery sensor gives +x W when charging and -x W when discharging…
So first I need to create a template sensor to convert from W to Wh
Only after can I use it in the above mentioned sensor…
I woke up at 3am here where I am and an going deeper down the rabbit hole (HA hole)
Thanks one more
It’s 4.56am here. I live in Italy. Don’t do this stuff if you’re not totally awake.
Energy Integration needs energy sensors. If you have power sensors, you need to calculate the energy. You can use the Riemann sum integral integration to do that.
If you need an example, here’s the configuration of the sensors for a Tesla PowerWall system (link) made by @briancmoses
Brian made a nice configuration to adapt/rename the existing power sensors using template sensors and also defined the corresponding energy sensors using the integral platform. You can learn a lot from his configuration.
sensor:
- platform: template
sensors:
grid_return_kw:
friendly_name: "Grid Return (kW)"
device_class: power
unit_of_measurement: kW
value_template: "{{ states('sensor.powerwall_site_now') | float | min(0) | abs | round(4) }}"
grid_consumption_kw:
friendly_name: "Grid Consumption (kW)"
device_class: power
unit_of_measurement: kW
value_template: "{{ states('sensor.powerwall_site_now') | float | max(0) | round(4) }}"
powerwall_charging_kw:
friendly_name: "Powerwall Charging (kW)"
device_class: power
unit_of_measurement: kW
value_template: "{{ states('sensor.powerwall_battery_now') | float | min(0) | abs | round(4) }}"
powerwall_discharging_kw:
friendly_name: "Powerwall Discharging (kW)"
device_class: power
unit_of_measurement: kW
value_template: "{{ states('sensor.powerwall_battery_now') | float | max(0) | round(4) }}"
- platform: integration
source: sensor.powerwall_solar_now
name: energy_solar
- platform: integration
name: energy_totalConsumption
source: sensor.powerwall_load_now
- platform: integration
name: energy_grid_consumption
source: sensor.grid_consumption_kw
- platform: integration
name: energy_grid_return
source: sensor.grid_return_kw
- platform: integration
source: sensor.powerwall_charging_kw
name: energy_powerwall_charging
- platform: integration
source: sensor.powerwall_discharging_kw
name: energy_powerwall_discharging
Grazie
I will dig into it during today
Thank you Alex
I got a hang of it and figured it out…you were right - I was reading way to fast
You have to be like a sniper: “slow is smooth…smooth is fast.”
Hi, work well this your method? The date is simolar Shelly App?
Hi, yes it works well now since I installed it. Statistics are accurate
I did not understand how to create the sensors for the storage battery
Fist you need to have a sensor that will measure the battery (in my case that is “sensor.battery_power_victron”)
Assuming you have that, then you need to create 4 new sensors.
- battery_input_power.yaml
- platform: template
sensors:
battery_input_power:
friendly_name: "Battery Input Power"
device_class: power
unit_of_measurement: "W"
value_template: "{{ max(0, states('sensor.battery_power_victron') | float) }}"
- battery_output_power.yaml
- platform: template
sensors:
battery_output_power:
friendly_name: "Battery Output Power"
device_class: power
unit_of_measurement: "W"
value_template: "{{ max(0, 0 - states('sensor.battery_power_victron') | float) }}"
The above two (1 and 2) will measure amount of power coming IN and going OUT of the battery.
Then you need to setup the Battery kWh meter IN and OUT of the battery. Those are the two below sensors (3 and 4).
- battery_charge.yaml
- platform: integration
source: sensor.battery_input_power
name: Battery Charge
unit_prefix: k
method: left
#or right or trapezoidal for methods
round: 3
- battery_discharge.yaml
- platform: integration
source: sensor.battery_output_power
name: Battery Discharge
unit_prefix: k
method: left
#or right or trapezoidal for methods
round: 3
Then you can integrate this into the Energy tab.
Final result:
Hi thank you. What do you measure the battery with?
It it a Pylontech US3000 (lithium iron phosphate) battery and it is connected to the Victron system with BMS coms cable. That is how Victron system sees and knows if the battery is charging or discharging.
Victron system is integrated into Home Assistant either via Modbus or MQTT (I use mod bus)
Thank you…
I could not find anything about entity requirements in the Home Assistant documentation up to now. Wouldn’t it make sense to document the entity requirement on the Home Assistant documentation?
I just figured out the I explicitly had to define these attributes for my MQTT sensor:
- state_class: measurement
- device_class: energy
I also noticed that it worked without defining last_reset value.
Cheers, red
At the bottom of that page, and every page in the docs, are links to provide feedback, or submit edits.
thanks for the quick feedback! I will provide the feedback as you proposed. Thanks & kind regards, red
In this thread I have personally linked the right document many times, last time was this: Home Energy Management in 2021.8 - #205 by alexdelprete