Adding battery through MQTT InfluxDB to energy dashboard

I’m struggling with configuration.yaml, I can’t add an entity that will be accepted by the battery storage in energy dashboard.

I have a small off grid setup. It’s a combo inverter+charger with AC fallback unit (so when batteries run out of juice it switches to AC), so there is only 1 battery connection, no in and out and the energy dashboard requires both; will it work?

I made myself a MQTT power/energy meters, the meter sends data from the sensor via JSON to NodeRed that then sends the data into InfluxDB.

JSON Structure:
{"B-V":25.76836,"B-I":-7.645916,"B-W":-196.6761,"B-E":-0.354719,"B-S":93,"S-V":28,"S-I":7.750885,"S-W":217.6576,"S-E":0.390405,"A1-V":0,"A1-I":0,"A1-W":0,"A1-E":0,"A1-F":0,"A1-P":0,"A2-V":225.7025,"A2-I":0,"A2-W":0,"A2-E":0.224,"A2-F":49.98183,"A2-P":0,"RSSI":-70.87584}
Where B- is battery, S- are solar panels, A1- is AC in and A2 is AC out. All energy statistics reset at 00:00.

My configuration.yaml, what should I change/add?

# Sensors
sensor:
  - platform: mqtt
    name: "Solar RSSI"
    state_topic: "power/solar/den"
    unit_of_measurement: "dBm"
    state_class: "measurement"
    unique_id: "SolarRSSI"
    device_class: "signal_strength"
    value_template: "{{ value_json.RSSI }}"
    
  - platform: mqtt
    name: "Solar AC in energy"
    state_topic: "power/solar/den"
    unit_of_measurement: "kWh"
    unique_id: "SolarACInEnergy"
    device_class: "energy"
    state_class: "measurement"
    value_template: "{{ value_json['A1-E'] }}"
    
  - platform: mqtt
    name: "Solar battery energy"
    state_topic: "power/solar/den"
    unit_of_measurement: "kWh"
    unique_id: "SolarBatteryEnergy"
    device_class: "energy"
    state_class: "measurement"
    value_template: "{{ value_json['B-E'] }}"
    
  - platform: mqtt
    name: "Solar AC out energy"
    state_topic: "power/solar/den"
    unit_of_measurement: "kWh"
    unique_id: "SolarACOutEnergy"
    device_class: "energy"
    state_class: "measurement"
    value_template: "{{ value_json['A2-E'] }}"
    
  - platform: mqtt
    name: "Solar AC in voltage"
    state_topic: "power/solar/den"
    unit_of_measurement: "V"
    unique_id: "SolarACInVoltage"
    device_class: "voltage"
    state_class: "measurement"
    value_template: "{{ value_json['A1-V'] }}"
    
  - platform: mqtt
    name: "Solar Panel Energy"
    state_topic: "power/solar/den"
    unit_of_measurement: "kWh"
    unique_id: "SolarPanelEnergy"
    device_class: "energy"
    state_class: "measurement"
    value_template: "{{ value_json['S-E'] }}"
    
utility_meter:
  daily_energy_battery:
    source: sensor.solar_battery_energy
    name: Daily Energy Batetry
    cycle: daily
  daily_energy_solar:
    source: sensor.solar_panel_energy
    name: Daily Energy Solar
    cycle: daily
  daily_energy_in:
    source: sensor.solar_ac_in_energy
    name: Daily Energy In
    cycle: daily
  monthly_energy_in:
    source: sensor.solar_ac_in_energy
    name: Monthly Energy In
    cycle: monthly
  daily_energy_out:
    source: sensor.solar_ac_out_energy
    name: Daily Energy out
    cycle: daily
  monthly_energy_out:
    source: sensor.solar_ac_out_energy
    name: Monthly Energy out
    cycle: monthly

template:
  - sensor:
      - name: "solarenergybalance"
        state: "{{ states('sensor.solar_ac_out_energy')|float - states('sensor.solar_ac_in_energy')|float}}"
        unit_of_measurement: 'kWh'
        device_class: "energy"
        state_class: "measurement"
        unique_id: "SolarEnergyBalance"

Try total_increasing for energy sensors

Thanks, seems to work now.

Now I think I need to make a new template to negate the numbers of the sensor, but I’m still unsure if it will work, or some equation if number is negative then set the out energy to 0?

img

As described, Battery in should be the output of your Solar panel, so “S-E”, I guess.
Battery out should be what is consumed out of your battery. So it cannot be negative.

What is B-E here? Charging or discharging rate?