reptilex / tesla-style-solar-power-card

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

Understanding sum of flows #97

Closed mdoliver closed 2 years ago

mdoliver commented 2 years ago

Hi,

I'm trying to understand how the sum of flows work for certain bubbles (in my case the solar generation bubble). I have a setup which is working absolutely fine until excess power starts flowing back to the grid.

My issue: The amount of excess flow to the grid is being added back onto the solar generation bubble.

Flow as I understand it (see screenshot):

image

Here's my setup:

  - type: custom:tesla-style-solar-power-card
    name: Solar Flow
    show_w_not_kw: 0
    threshold_in_k: null
    change_house_bubble_color_with_flow: 1
    energy_flow_diagramm: null
    energy_flow_diagramm_line_factor: 2

    generation_to_grid_entity: sensor.myenergi_eddi_hub_power_export
    generation_to_battery_entity: null
    generation_to_house_entity: sensor.myenergi_eddi_hub_power_generation
    grid_to_battery_entity: null
    grid_to_house_entity: sensor.myenergi_eddi_hub_power_import
    battery_to_grid_entity: null
    battery_to_house_entity: null

    battery_extra_entity: null
    house_extra_entity: sensor.myenergi_eddi_hub_home_consumption
    generation_extra_entity: sensor.myenergi_eddi_hub_power_generation
    grid_extra_entity: null

    appliance1_consumption_entity: sensor.myenergi_eddi_hub_power_charging
    appliance1_extra_entity: sensor.myenergi_eddi_energy_diverter_status
    appliance2_consumption_entity: null
    appliance2_extra_entity: null
    grid_icon: mdi:transmission-tower
    generation_icon: mdi:solar-panel-large
    house_icon: mdi:home
    battery_icon: mdi:battery
    appliance1_icon: mdi:shower-head
    appliance2_icon: mdi:car-sports

Any help would be greatly appreciated!

reptilex commented 2 years ago

The card expects the flows it gets fed to be independent from each other. You are using the same sensors everywhere. You need to divide those sensors and use them as sensor templates. My configuration:

type: custom:tesla-style-solar-power-card
name: Powercard
generation_icon: mdi:solar-power
grid_entity: sensor.grid_consumption
house_entity: sensor.house_consumption
battery_entity: sensor.battery_consumption
generation_entity: sensor.solar_yield
battery_to_house_entity: sensor.battery_consumption
generation_to_house_entity: sensor.solar_consumption
generation_to_grid_entity: sensor.grid_feed_in
generation_to_battery_entity: sensor.battery_charging
grid_to_house_entity: sensor.grid_consumption
battery_extra_entity: sensor.battery_charge
appliance1_consumption_entity: sensor.marvin_current_charging
appliance1_extra_entity: sensor.marvin_battery_sensor
appliance2_consumption_entity: sensor.heating_power_hour_s0
appliance2_extra_entity: sensor.heating_operation
change_house_bubble_color_with_flow: 1
hide_inactive_lines: 1

My flow templates:

- platform: template
    sensors:
      solar_yield:
        value_template: '{{ ((states.sensor.solarsensors.attributes["power_dc1"] | int + states.sensor.solarsensors.attributes["power_dc2"] | int)) }}'
        device_class: power
        unit_of_measurement: W
      battery_charge:
        value_template: '{{ states.sensor.solarsensors.attributes["act_state_of_charge"] }}'
        unit_of_measurement: '%'
      battery_consumption:
        value_template: '{% set batter_cons = states.sensor.solarsensors.attributes["total_dc_power"] - states.sensor.solarsensors.attributes["power_dc1"] - states.sensor.solarsensors.attributes["power_dc2"] | int %}
                        {% if batter_cons > 0 %}
                            {{ batter_cons | int }}
                        {% else %}
                            0
                        {% endif %}'
        device_class: power
        unit_of_measurement: W
      battery_charging:
        value_template: '{% set batter_cons = (states.sensor.solarsensors.attributes["total_dc_power"] - states.sensor.solarsensors.attributes["power_dc1"] - states.sensor.solarsensors.attributes["power_dc2"]) | int %}
                        {% if batter_cons < 0 %}
                            {{ (batter_cons * -1) | int }}
                        {% else %}
                            0
                        {% endif %}'
        device_class: power
        unit_of_measurement: W      
      grid_consumption:
        value_template: '{{ states.sensor.solarsensors.attributes["home_own_consumption_from_grid"] | int }}'
        device_class: power
        unit_of_measurement: W
      grid_feed_in:
        value_template: '{% set feed_in = states.sensor.solarsensors.attributes["inverter_generation_power_actual"] | int - states.sensor.solarsensors.attributes["total_active_power_powermeter_home_consumption"] | int %}
                         {% if feed_in < 9000 and feed_in > 0 %}
                            {{ feed_in | int }}
                        {% else %}
                            0
                        {% endif %} '
        device_class: power
        unit_of_measurement: W
      solar_consumption:
        value_template: '{{ states.sensor.solarsensors.attributes["home_own_consumption_from_pv"] | int }}'
        device_class: power
        unit_of_measurement: W
      house_consumption:
        value_template: '{{ states.sensor.solarsensors.attributes["total_active_power_powermeter_home_consumption"]  | int }}'
        device_class: power
        unit_of_measurement: W
      house_energy:
        value_template: "{% set phase1 =  state_attr('sensor.solarsensors', 'active_power_phase_1_powermeter') %}
                        {% set phase2 =  state_attr('sensor.solarsensors', 'active_power_phase_2_powermeter') %}
                        {% set phase3 =  state_attr('sensor.solarsensors', 'active_power_phase_3_powermeter') %}
                        {{ (phase1 + phase2 + phase3) | int }}"
        device_class: power
        unit_of_measurement: W