Utility Meter - Counting UP & DOWN values

I got a battery connected to a solar system. The BMS reports remaining kWh.
As the battery is charged and discharged all the time, this value goes up and down all the time.
I’d like to know how many kWh go INTO the battery per day/month and how many kWh go out.
How would I “make” that sensor?

Do you have any type of sensor that indicates if the battery is charging (or discharging)?

Not just binary sensors (though that would be best), a sensor that shows negative power or current when discharging and positive power or current when charging would do.

What are the entity ids of these sensors and the capacity sensor?

Yes. I got the current in AMPS sensor.solarakku.current. A negative value indicates discharge and vice versa.
The sensor for Wh is called sensor.solarakku.wh

utility_meter:
  battery_energy_daily:
    name: "Battery Energy Daily"
    source: sensor.solarakku.wh
    cycle: daily
    tariffs:
      - "charge"
      - "discharge"
  battery_energy_monthly:
    name: "Battery Energy Monthly"
    source: sensor.solarakku.wh
    cycle: monthly
    tariffs:
      - "charge"
      - "discharge"

automation: (to select the required tariff)

- trigger:
    - platform: state
      entity_id: sensor.solarakku.current
  action:
    - service: select.select_option
      target:
        entity_id:
          - select.battery_energy_monthly
          - select.battery_energy_daily
      data:
        option: "{{ 'discharge' if states('sensor.solarakku.current')|float(0) < 0 else 'charge' }}"

This will create four sensors:

sensor.battery_energy_daily_charge
sensor.battery_energy_daily_discharge
sensor.battery_energy_monthly_charge
sensor.battery_energy_monthly_discharge
1 Like

Excellent. Thanks a lot. Much appreciated. We’ll test, and tomorrow I’ll see if everything works.
One more question: How would it build TOTALS? So total Wh dis/charged?

The four sensors from the utility meters keep track of the daily/monthly totals.

If you want one that never resets you can use:

utility_meter:
  battery_energy_total:
    name: "Battery Energy Total"
    source: sensor.solarakku.wh
    tariffs:
      - "charge"
      - "discharge"

No cycle option means it will never reset. You have to add it to the automation too:

 action:
    - service: select.select_option
      target:
        entity_id:
          - select.battery_energy_monthly
          - select.battery_energy_daily
          - select.battery_energy_total
      data:
        option: "{{ 'discharge' if states('sensor.solarakku.current')|float(0) < 0 else 'charge' }}"

:heartpulse:

Thanks a lot!!

@tom_l Unfortunately it’s not working as expected. It’s counting the Wh charged, but not those discharged. Checked for two days now.

image

Could it be that the correct data option should be (note the “<=”) ??

{{ 'discharge' if states('sensor.solarakku_a')|float(0) <= 0 else 'charge' }}

No. Still not working. Any idea what could be wrong?

Check the template in Developer Tools > Templates

The template is working. It changes from charge to discharge and vice versa depending on “sensor.solarakku_a” being positive or negative.

What I’m missing is the correlation between state of “sensor.solarakku_a” (or .current in your code, was a typo in my first post) and the utlilty_meter counting up and down?!
It’s got two tariffs, but how are they connected to the automation?

The automation triggers on any change of current.

If the current is negative (less than zero) it changes the tariff to discharging. If the current is positive,(zero or grater, in my template) it changes the tariff to charging.

This will (should) make the utility meter switch between counting on the two sensors …_discharge and …_charge.

I suspect the reason it is not counting the discharge is because utility meters only count up by default. We need to add the following to the utility meter configs for it to count down as well:

utility_meter:
  battery_energy_daily:
    name: "Battery Energy Daily"
    source: sensor.solarakku.wh
    cycle: daily
    net_consumption : true   ###  <-------- Add this ###
    tariffs:
      - "charge"
      - "discharge"
  battery_energy_monthly:
    name: "Battery Energy Monthly"
    source: sensor.solarakku.wh
    cycle: monthly
    net_consumption : true   ###  <-------- Add this ###
    tariffs:
      - "charge"
      - "discharge"
1 Like

@tom_l Thanks. Seems that was the issue. I guess now it’s counting correctly.

image