Hi all,
I stumbled upon this topic as I am trying to integrate the battery template sensor (charge/discharge) into my energy tab, but these two sensors are simply not showing up
template:
#Split power in and out of battery
- sensor:
- name: "Battery input power"
unit_of_measurement: "W"
state: >
{% if states('sensor.battery_power')|float >= 0 %}
{{ states('sensor.battery_power') }}
{% else %}
0
{% endif %}
- name: "Battery output power"
unit_of_measurement: "W"
state: >
{% if states('sensor.battery_power')|float < 0 %}
{{ -1 * states('sensor.battery_power')|float }}
{% else %}
0
{% endif %}
In Dev Tools, I get all the results, but no sensors are appearing
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.
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.
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
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)
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.