reptilex / tesla-style-solar-power-card

Home assistant power card mimicking the one tesla provides for the powerwall app.
221 stars 59 forks source link

Why do the Recommended APF Sensors Show Impossible Transfers Compared to the Older "Tesla Card Sensors" ? #154

Open ziptbm opened 1 year ago

ziptbm commented 1 year ago

This Tesla Style Solar Power Card is the best, hands down, HACS add-in for Home Assistant.

I've been using it for a while now and started out with some template sensors that came from one of the forums (yaml below), which I've referred to as "Tesla Card xyz." After the documentation was updated with the Actual Powerflow (APF) sensors, I added those as well to see the differences side by side. While the APF sensors appear to make everything "add up" I still find odd readings that make no sense for my setup. e.g. as I'm writing this message at this moment, the APF version is showing 2W from my solar to battery, but the sun has already set. And it's showing 10W from my grid to my battery (I only charge from grid during storm watch events).

Could anyone help me understand why the recommended APF sensors from the readme are superior to the "Tesla Card" sensors I had before? Or what's wrong with the "Tesla Card" sensors?

And is anyone else seeing impossible energy transfers from the APF sensors? Thanks.

- sensor:
  - name: "Tesla Card Grid Consumption"
    unique_id: 'tesla_card_grid_consumption'
    state: "{{ [ ((states('sensor.powerwall_site_now') | float(0)) - ([(([states('sensor.powerwall_site_now') | float(0) , 0] | max | abs ) - (states('sensor.powerwall_load_now') | float(0))) | float(0) , 0] | max | abs)) | float(0) , 0 ] | max | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Grid Feed In"
    unique_id: 'tesla_card_grid_feed_in'
    state: "{{ [ states('sensor.powerwall_site_now') | float(0) , 0 ] | min | abs | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Solar Consumption"
    unique_id: 'tesla_card_solar_consumption'
    state: "{{ [ (states('sensor.powerwall_solar_now') | float(0)) - (states('sensor.tesla_card_grid_feed_in') | float(0) ) - (states('sensor.tesla_card_battery_charging_inside') | float(0)) | float(0) , 0 ] | max | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Battery Consumption"
    unique_id: 'tesla_card_battery_consumption'
    state: "{{ [ states('sensor.powerwall_battery_now') | float(0) , 0 ] | max | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Battery Export"
    unique_id: 'tesla_card_battery_export'
    state: "{{ [ (( [ states('sensor.powerwall_battery_now') | float(0) , 0 ] | max ) - ( [ states('sensor.powerwall_load_now') | float(0) , 0 ] | max )) | float(0) , 0 ] | max | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Battery Charging Inside"
    unique_id: 'tesla_card_battery_charging_inside'
    state: "{{ [ (([ states('sensor.powerwall_battery_now') | float(0) , 0 ] | min | abs) - ([(([ states('sensor.powerwall_site_now') | float(0) , 0 ] | max | abs ) - (states('sensor.powerwall_load_now') | float(0))) | float(0) , 0 ] |  max |abs)) | float(0) , 0 ] | max | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  - name: "Tesla Card Battery Charging Outside"
    unique_id: 'tesla_card_battery_charging_outside'
    state: "{{ [ (([states('sensor.powerwall_site_now') | float(0) , 0 ] | max | abs ) - (states('sensor.powerwall_load_now') | float(0))) | float(0) , 0 ] | max | abs | round(1) }}"
    device_class: power
    unit_of_measurement: kW
NathanReus commented 1 year ago

I'm in the same boat as you here. Was using the old "Tesla Card" template sensors. Have now seen these APF ones, and compared the two. Seeing a few watts import or export from/to solar, battery, or grid when that shouldn't be the case.

mkanet commented 11 months ago

I'm in the same boat as you here. Was using the old "Tesla Card" template sensors. Have now seen these APF ones, and compared the two. Seeing a few watts import or export from/to solar, battery, or grid when that shouldn't be the case.

Below is the reason. I found the comments below in the APF Template sensor code that we're supposed to use. However, I don't know how/why it was working correctly using the old "Telsa Card" I'd like to know how to old Tesla card handled this differently. @reptilex do you know why it used to work correctly before and not now?

Inverter consumption and power losses due to Inverter transfers and power conversions (AC/DC) excludes rounding errors made worst by the fact that some inverters round all sensors readings to INT Occasionally this might be negative probably due to cumulative errors in not so accurate power readings.