Solar battery run time till empty

Thanks for sharing this! This is going to get me to re-think my setup entirely…

However, I still think I’m missing something in regard to the home energy usage sensor.

So you use sensor.powerwall_load_now as the source for a Riemann integral to create sensor.energy_consumed_by_house. And then use that Riemann integral sensor as the source for sensor.energy_consumed?

And then what specifically is populating that information in the Energy kWh power-flow-card? I don’t see sensor.energy_consumed listed in your Energy kWh yaml above. Does the power-flow-card calculate this daily home usage automatically or am I missing something else?

Transparently, I’m trying to figure out why my daily home energy usage Utility Meter with sensor.powerwall_load_import as the source is not matching the Tesla app as I outlined in this thread. I hadn’t tried using a Riemann integral for this, so I’m wondering if that’s why it’s not working…however the difference in values in the history ofsensor.powerwall_load_import from now to the previous midnight matches up with the value in the Tesla app, but not in the Utility Meter I built off of it.

The Riemann Integral is for converting power to energy. I monitor both the power and energy in the card.

The card uses the inputs and outputs and then calculates the house load as an energy or power balance.

Unless you have all the energy configured the utility meters and the powerwall will not match. The usage will.

Hope this helps

So you only have the value for home energy usage within the power-flow-card and do not have a sensor outside of it that reports the same number? This is what I’m looking for since a Utility Meter on sensor.powerwall_load_import is not properly calculating the value and I haven’t been able to find a solution to this yet. Thanks for the info.

many thanks @ all.
this is my battery card (Huawei luna2000 - 20kWh + custom button card + custom code :slight_smile: )

charging:
card_screenshot

discharging:
Immagine 2023-04-01 154154

full charge:
100% idle

Looks great, Michele! :+1: Do you use the FusionSolar integration for the sensors? Would you mind sharing your custom code?

hi, I use this integration for huawei luna2000 & sun2000: GitHub - wlcrs/huawei_solar: Home Assistant integration for Huawei Solar inverters via Modbus
here you can find yaml code & custom button card for lovelace: mickmmm/Huawei Luna 2000 Battery Time charge at main · MicheleMercuri/mickmmm · GitHub

1 Like

Thank you very much, Michele! Your fast reply and uploadimg of your code is very much appreciated!

1 Like

Could someone assist me in understanding the sensors used. I don’t have a tesla powerwall so am trying to adapt this to my specific setup.

If I copy this code and apply my sensors, the data is incorrect. See my comments

#--------------------------------------------------------------------------------------------------

Battery Energy to Full

#--------------------------------------------------------------------------------------------------

  • sensor:
    • name: “solar_battery_energy_to_full”
      unique_id: “solar_battery_energy_to_full”
      state: >
      {% set percent = states(‘sensor.battery_state_of_charge’) | float(0) / 100.0 | float(0) %} ## IS THIS SUPPOSED TO BE THE CURRENT BATTERY’S SOC (I.E. 50%) OR THE AMOUNT OF WATTS GOING INTO THE BATTERY? ##
      {% set number = 2 %} ## I HAVE 2 BATTERIES ##
      {% set energy = 3.5 | float(0) %} ## EACH BATTERY HOLDS 3.5KWH ##
      {% set reserve = 10 %} ## I USE 10% AS A RESERVE ##
      {% set charge = ((1.0 - percent) * number * energy) | float(0) %}
      {{ charge }}

#--------------------------------------------------------------------------------------------------

Time to Charge Battery to full

#--------------------------------------------------------------------------------------------------

  • sensor:
    • name: “battery_time_to_full”
      unique_id: “battery_time_to_full”
      state: >
      {% set a = states(‘sensor.solar_battery_energy_to_full’) | float(0.0001) %}
      {% set b = states(‘sensor.battery_charging’) | float(0.0001) %} ## WATTS GOING INTO BATTERIES (I.E. 2756W)
      {% if b > 0.001 %}
      {% set decimal_hours = a / b %}
      {% else %}
      {% set decimal_hours = 0.0 %}
      {% endif %}
      {% set minutes = (decimal_hours % 1 * 60) | round(0) %}
      {% set decimal_hours = decimal_hours| int(0) %}
      {% if minutes <= 9 %}
      {% set min = ‘0’ ~ minutes | string %}
      {% else %}
      {% set min = minutes | string %}
      {% endif %}
      {{ decimal_hours ~ ‘:’ ~ min }}

** UPDATE ** I think I solved the problem. I changed the charging power from watts to kw. The time remaining looks correct.

I’ve created a new sensor off my rundown sensor to project the rundown time onto the current time. I can now estimate what time my batteries will be depleted.

1 Like

That looks great! Could you share the yaml or what you did to get those type of cars in your view?

Also @AllHailJ thanks again for sharing your yaml to create the sensors. Have you done anything so the updates don’t pollute your logbook? It seems like every minute I get a new logbook update of the change x 3 sensors. I’ve tried adding some lines to my configuration to filter those out, but they still show for me. Curious if this bothers anyone else and/or if there’s a recommended workaround.

@ziptbm, I used a combination of Mushroom Cards with the Room Card (GitHub - marcokreeft87/room-card: Show multiple entity states, attributes and icons in a single card in Home Assistant's Lovelace UI). I typically use the Mushroom-Template Card as it allows flexibility with the data that can be shown as well as varying icons / colours based on states etc.

1 Like

I have not had any problem like you have described here. I have upgraded many times and it just happens. Sorry I can be of no help.

To clarify, I was referring to updates in the logbook (literally every time expected remaining changes, it adds an entry to the logbook), not updates to Home Assistant. Sorry for the lack of clarity.

An example here’s a screenshot of my logbook. If you notice the PW + Reserve @ Current Power sensor that updated twice in 30 seconds. I was curious if you did anything to filter these types of events from the logbook since the utility of the update frequency is minimal.

My understanding is that this happens for all sensors, real or virtual. It’s part of the core system. If I have this behavior wrong, I hope someone will correct me. I do not filter the log book in any manner. My understanding is also that anytime an input to a sensor changes, the sensor changes and that is causing the sensor recalculation. Again if I have this wrong…

Sorry not much help!

I read in the logbook documentation that you can exclude an entity from being recorded. Maybe that’s what you are looking for so it doesn’t flood your logbook?

Thank you both. Yes, I tried to add a logbook exclude section to my configuration, but it didn’t seem to work for me as the items would still populate. That’s why I was wondering if anyone else had tried to address this.

Hi
What is the visualisation you use right now for your Alpha ESS system? I also have an AlphaESS inverter with storage and have all those values in my home assistant. But for now only the values, no visual effects, no history.
I would like to see yours to get some good ideas and maybe also import some existing work to have a smooth start.

Currently Im using apexcharts-card for the graphs:

type: custom:apexcharts-card
apex_config:
  yaxis:
    forceNiceScale: true
  chart:
    height: 550px
  stroke:
    width: 1.5
    curve: smooth
graph_span: 24h
all_series_config:
  stroke_width: 1.5
  opacity: 0.4
  type: area
  curve: smooth
now:
  show: true
  color: red
span:
  start: day
header:
  show: false
  title: Battery
  show_states: true
  colorize_states: true
series:
  - entity: sensor.const_solar_battery_soc
    name: BAT
    transform: return x;
    yaxis_id: battery
    type: area
    color: '#A0C770'
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.6
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.const_solar_load_total
    float_precision: 2
    name: Load
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#6FB6C6'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.6
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.const_solar_generation
    float_precision: 2
    name: PV
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#FABF00'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.5
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.const_ppv1
    float_precision: 2
    name: PV1
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#FFFF7F'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.3
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.const_ppv2
    float_precision: 2
    name: PV2
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#FFF2CC'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.3
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.const_grid_i_o
    float_precision: 2
    name: Feed-In
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#DF681F'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.3
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
  - entity: sensor.alpha_grid_power_importing
    float_precision: 2
    name: Grid Consumption
    transform: return x / 1000;
    yaxis_id: power
    type: area
    color: '#C18349'
    unit: kW
    extend_to: now
    curve: smooth
    fill_raw: last
    opacity: 0.3
    group_by:
      func: avg
      duration: 5min
    show:
      legend_value: false
yaxis:
  - id: power
    min: 0
    decimals: 2
    apex_config:
      forceNiceScale: true
      title:
        text: pw
      labels:
        formatter: |
          EVAL:function(value) {
            return value.toFixed(2).toString() + " kW";
          }
  - id: battery
    min: 0
    max: 100
    decimals: 0
    opposite: true
    apex_config:
      tickAmount: 5
      title:
        text: bat
      labels:
        formatter: |
          EVAL:function(value) {
            return value.toFixed(0).toString() + " %";
          }

If you arent using the HA energy page, you can use power-flow-card and sankey-card for these visualizations

Hi I adapted the code from @SpookyAwol and added it to my configuration.yaml file (separating them out is on my todo list) but the sensor isn’t appearing in my list on Home Assistant. Can anyone spot any glaring issues? It worked in developer, without the extra templates above it, still new to the yaml syntax. Ignore the indenting issure at the top, that’s happened as copying and pasting

template
  - name: "solar_battery_life"
    state: >
        {% set percent = states('sensor.foxess_bat_soc') | float(0) / 100.0 %}
        {% set energy = 8.6 | float(0) %}
        {% set reserve = 0.11 | float(0) %}
        {% set charge = (percent - reserve) * energy | float(0) %}
        {% set a = states('sensor.foxess_pv_power') | float(0) %}
        {% set b = states('sensor.foxess_load_power') | float(0) %}
        {% set c = states('sensor.foxess_bat_discharge_power') | float(0) %}
        {% set d = states('sensor.foxess_bat_charge_power') | float(0) %}
        {% if float(percent) == 100 %}
          Battery is full/Not charging. Current House load {{ b }}
        {% elif float(c) > 0  %}
          Battery is discharging
          {% set current_power = a + b + c %}
        {% elif float(d) > 0 %}
          Battery is charging
          {% set current_power = a + b + d %}
        {% endif %}
        {% set decimal_hours = charge / current_power %}
        {% set minutes = (decimal_hours % 1 * 60) | round(0) %}
        {% if minutes <= 9 %}
          {% set min = '0' ~ minutes | string %}
        {% else %}
          {% set min = minutes | string %}
        {% endif %}}
        {% if float(c) > 0 %}
          {{ "SOC: " ~ percent ~ "%, Empty in:" ~ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }} 
        {% elif float(d) > 0 %}
          {{ "SOC: " ~ percent * 100 ~ "%, Full in: " ~ decimal_hours | int(0) ~ ':' ~ min }} 
        {% endif %}
1 Like

Missing sensor in template

template:
  - sensor:
      - name: