I have HASS up and running fine.
I have a Victron Energy system which I have integrated into HA using MQTT. This has enabled me to bring in most of my AC usage and the solar side of things.
I’m however struggling a little to figure out how best to integrate the battery side of things.
The battery and its JK BMS is currently connected to the Victron system via a USB-RS485 and so the Victron system is aware of the battery state, monitors voltage, current, state of charge, etc.
My issue is there’s no directly available MQTT topic that covers battery consumption. My guess is that this can be obtained by using some of the other values available and setting up an integrate function over time.
There is a “Consumedamphours” but that’s only a positive value and I guess reset as it can only track energy used (discharge) but not energy sent to the battery when charging.
There’s also a topic which publishes a string of values:
{
"value": [
{
"active_battery_service": true,
"bmsstate": 9,
"current": 0,
"id": "com.victronenergy.battery.ttyACM0__0",
"instance": 1,
"name": "SerialBattery(JKBMS)",
"power": 0,
"soc": 98,
"state": 0,
"temperature": 19.5,
"timetogo": 2069052,
"voltage": 56.22
}
]
}
where I guess the “current” value (currently 0) tracks the current going in and out (positive and negative values).
In the Energy section of HA, it does want separate values for energy in and out - I don’t think it will allow you to use the same topic value twice so we’d need to create the two distinct ones which can then be used?
Here’s what I currently have for yaml in the battery section of my configuration:
## BATTERIES
#SOC
- state_topic: "victron/N/[My VRM ID]/battery/1/Soc"
name: "Battery SoC"
unique_id: 0a614086-d623-40df-bb77-4a031513075f
icon: mdi:battery
unit_of_measurement: "%"
device_class: battery
value_template: '{{ value_json.value | float(0) | round }}'
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
#Battery Voltage
- state_topic: "victron/N/[My VRM ID]/battery/1/Dc/0/Voltage"
name: "Battery Voltage"
unique_id: 099449a2-0c57-4bac-9db7-23bb0086db19
icon: mdi:flash-triangle
unit_of_measurement: "V"
device_class: voltage
value_template: '{{ value_json.value | float(0) | round(1) }}'
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
#Battery Current
- state_topic: "victron/N/[My VRM ID]/battery/1/Dc/0/Current"
name: "Battery Current"
unique_id: 2b2971f1-6cbb-4c7c-aeef-32622fe5d809
icon: mdi:current-dc
unit_of_measurement: "A"
device_class: current
value_template: '{{ value_json.value | float(0) | round }}'
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
#Battery Power
- state_topic: "victron/N/[My VRM ID]/battery/0/Dc/0/Power"
name: "Battery Power"
unique_id: 943fcbe8-5600-40a4-bf21-c7d84f042c78
icon: mdi:generator-stationary
unit_of_measurement: "W"
device_class: power
value_template: '{{ value_json.value | float(0) | round }}'
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
#Time to go
- state_topic: "victron/N/[My VRM ID]/battery/1/TimeToGo"
name: "Time to go"
unique_id: 1cef3f50-a08c-49e2-afa6-0e83371fb059
icon: mdi:timer
value_template: >
{% if value_json.value is none %}
For Ever and Ever!
{% else %}
{% set total_seconds = value_json.value | int %}
{% set days = (total_seconds // 86400) %}
{% set hours = (total_seconds % 86400) // 3600 %}
{% set minutes = ((total_seconds % 3600) // 60) %}
{% if days >= 1 %}
{{ days }} day{{ 's' if days > 1 else '' }} {{ hours }} hour{{ 's' if hours != 1 else '' }}
{% elif hours >= 1 %}
{{ hours }} hour{{ 's' if hours != 1 else '' }} {{ minutes }} minute{{ 's' if minutes != 1 else '' }}
{% else %}
{{ minutes }} minute{{ 's' if minutes != 1 else '' }}
{% endif %}
{% endif %}
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
#Consumed battery
- state_topic: "victron/N/[My VRM ID]/system/0/Dc/Battery/ConsumedAmphours"
name: "Battery Ah consumed"
unique_id: 2f868034-9283-493a-91da-f50703b470a3
icon: mdi:battery
unit_of_measurement: "Ah"
device_class: energy_storage
state_class: total_increasing
device: {
identifiers: [
"Cerbo GX"
],
manufacturer: "Victron Energy",
model: "Cerbo GX",
name: "Cerbo GX"}
So what would be your suggested way of going about this?