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

Powerwall on "Time-based controls" #70

Closed kodek closed 3 years ago

kodek commented 3 years ago

Hi there,

Having trouble setting things up based on the example Powerwall (in the documentation). It seems to be accurate when the Powerwall is set to "self-powered" mode. Unfortunately, I'm having issues when using time-based controls.

Recently, I changed the Powerwall to time-based controls/advanced. This causes solar to be exported directly to the grid, while the Powerwall feeds the house. Unfortunately, the Lovelace card shows extra solar power, and the house drawing the excess. Any ideas?

image

This is what it looks like in HA:

image

My Lovelace config:

type: custom:tesla-style-solar-power-card
house_entity: sensor.powerwall_load_now
grid_entity: sensor.tesla_card_grid_consumption
battery_entity: sensor.tesla_card_battery_consumption
generation_entity: sensor.powerwall_solar_now
generation_to_grid_entity: sensor.tesla_card_grid_feed_in
generation_to_house_entity: sensor.tesla_card_solar_consumption
generation_to_battery_entity: sensor.tesla_card_battery_charging
battery_to_house_entity: sensor.tesla_card_battery_consumption
grid_to_house_entity: sensor.tesla_card_grid_consumption
battery_extra_entity: sensor.powerwall_charge
hide_inactive_lines: 1
threshold_in_k: 1.5
appliance1_consumption_entity: sensor.tesla_charger_usage
appliance2_consumption_entity: sensor.always_on_usage
generation_icon: mdi:weather-sunny
appliance2_icon: mdi:ghost

My HA templates:

# Copied states from https://github.com/reptilex/tesla-style-solar-power-card/issues/68#issue-895849995
template:
  - sensor:
    - name: 'tesla_card_grid_consumption'
      unique_id: 'tesla_card_5fee6ddd5c1f42a099067ce9dd44e6d1'
      state: >-
          {% set val = states('sensor.powerwall_site_now') | float | max(0) %}
          {{ val if is_state_attr('sensor.powerwall_site_now', 'is_active', true) else 0 }}
      device_class: power
      unit_of_measurement: kW
  - sensor:
    - name: 'tesla_card_grid_feed_in'
      unique_id: 'tesla_card_52d22b847ade42c5b4526b2ff15f5aef'
      state: >-
          {% set val = states('sensor.powerwall_site_now') | float | min(0) | abs %}
          {{ val if val > 0.020 else 0 }}
      device_class: power
      unit_of_measurement: kW

  - sensor:
    - name: 'tesla_card_solar_consumption'
      unique_id: 'tesla_card_2bb67bd5264f4ec39f141f1722fea085'
      state: >-
          {% set solar = states('sensor.powerwall_solar_now') | float if is_state_attr('sensor.powerwall_solar_now', 'is_active', true) else 0 %}
          {% set house = states('sensor.powerwall_load_now') | float %}
          {{ solar if house > solar else house }}
      device_class: power
      unit_of_measurement: kW

  - sensor:
    - name: 'tesla_card_battery_consumption'
      unique_id: 'tesla_card_2b7aaa2588e8480aaba586815a84fcd7'
      state: "{{ states('sensor.powerwall_battery_now') | float | max(0) if is_state_attr('sensor.powerwall_battery_now', 'is_active', true) else 0 }}"
      device_class: power
      unit_of_measurement: kW
  - sensor:
    - name: 'tesla_card_battery_charging'
      unique_id: 'tesla_card_9c46447cf75942ba9ac4bcaca85ba6c5'
      state: "{{ states('sensor.powerwall_battery_now') | float | min(0) | abs if is_state_attr('sensor.powerwall_battery_now', 'is_active', true) else 0 }}"
      device_class: power
      unit_of_measurement: kW
reptilex commented 3 years ago

Hey, sorry was busy the last few weeks. So the error happens on your tesla_card_solar_consumption template sensor. This sensor is giving you a load of ~1.1kwh in your example and it should be 0. The question is which flag or attribute tells you that it is active but not being used for the house consumption. So first the question would be which one is it using? power_solar_now or power_load_now? If it is using powerwall_soler_now maybe the is_active attribute is not being used? Or there is another one? If it is using powerwall_load_now mabye there is an is_active flag there too? You have to check on your template:

    - name: 'tesla_card_solar_consumption'
      unique_id: 'tesla_card_2bb67bd5264f4ec39f141f1722fea085'
      state: >-
          {% set solar = states('sensor.powerwall_solar_now') | float if is_state_attr('sensor.powerwall_solar_now', 'is_active', true) else 0 %}
          {% set house = states('sensor.powerwall_load_now') | float %}
          {{ solar if house > solar else house }}
      device_class: power
      unit_of_measurement: kW

If you want more help I would need a sample with also the values of the powerwall sensors and attributes, sadly I cannot test it because the powerwall was way too expensive in my country when I got my installation.

borski commented 3 years ago

@kodek Please check out #76 and see if it fixes your issue :)

kodek commented 3 years ago

Thanks for the support, everyone! I have updated my config to reflect #76.

Unfortunately, the current power usage isn't very interesting, so I will have to wait until tomorrow. I'll report tomorrow if this is fixed. :)

kodek commented 3 years ago

image

I can confirm this is fixed. Thank you!

I see some rounding errors causing power to flow into my solar entity. I will look into it and follow up in a separate issue.