Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Tweaking my sensors... Losses and Multiple Flows... #146

Open
C00K50N opened this issue Mar 14, 2023 · 0 comments
Open

Help Tweaking my sensors... Losses and Multiple Flows... #146

C00K50N opened this issue Mar 14, 2023 · 0 comments

Comments

@C00K50N
Copy link

C00K50N commented Mar 14, 2023

Great card! I use it a lot for a quick overview of what's going on. My query isn't an issue as such, but I wasn't sure where else to post it...

I hope someone can help me tweak my sensors, as I have some anomalies. I have a FoxESS hybrid inverter and a Zappi car charger. I've built some template sensors based on the inverter's sensors in order to create values for the various flows to work. When there's only one flow (e.g. grid to house, or battery to house, etc) everything looks as expected. But some of the values are out a bit when there's more than one flow at a time (e.g. both PV and battery to house, or PV to house and export, etc).

There are 2 things I'm sure I've done wrong but I can't work out the logic to make them work. Firstly, I'm accounting for inverter losses, which is fine when there's just one flow, but I think they're duplicated when there's more than one flow, leading to the figures in this card being out.

Secondly, I have obviously got the logic wrong for at least one circumstance when there are 3 flows (high house demand while the sun is out, so PV, Battery and Grid all flowing to House).

Below is a screenshot of an extreme example of this (sensors from inverter in gauges to the left, with this card over to the right). Then my template sensors code is below that (sorry it's quite long with a 5W buffer added into each flow too)...
Flow Diagram Anomalies 2023-03-14

- platform: template
  sensors:

# Flow Diagram Sensors

#generation_to_grid_entity
    flow_pv_to_grid:
          friendly_name: "Flow PV to Grid"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set feedin_var = states('sensor.pv_total_power')|float
                - states('sensor.load_power')|float
                - states('sensor.battery_charge')|float
                - (states('sensor.system_losses')|float ) %}
            {% if feedin_var > 0.005 %}
                {{ (states('sensor.pv_total_power')|float
                - states('sensor.load_power')|float
                - states('sensor.battery_charge')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#generation_to_battery_entity
    flow_pv_to_battery:
          friendly_name: "Flow PV to Battery"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set pv2batt_var = states('sensor.pv_total_power')|float 
                - states('sensor.load_power')|float 
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if pv2batt_var > 0.005 %}
                {{ (states('sensor.pv_total_power')|float 
                - states('sensor.load_power')|float 
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#generation_to_house_entity
    flow_pv_to_house:
          friendly_name: "Flow PV to House"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set pv2house_var = states('sensor.pv_total_power')|float
                - states('sensor.battery_charge')|float
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if pv2house_var > 0.005 %}
                {{ (states('sensor.pv_total_power')|float
                - states('sensor.battery_charge')|float
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#grid_to_battery_entity
    flow_grid_to_battery:
          friendly_name: "Flow Grid to Battery"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set grid2batt_var = states('sensor.grid_consumption')|float
                - states('sensor.load_power')|float
                - states('sensor.pv_total_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if grid2batt_var > 0.005 %}
                {{ (states('sensor.grid_consumption')|float
                - states('sensor.load_power')|float
                - states('sensor.pv_total_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#grid_to_house_entity
    flow_grid_to_house:
          friendly_name: "Flow Grid to House"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set grid2house_var = states('sensor.grid_consumption')|float
                - states('sensor.battery_charge')|float
                - states('sensor.pv_total_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if grid2house_var > 0.005 %}
                {{ (states('sensor.grid_consumption')|float
                - states('sensor.battery_charge')|float
                - states('sensor.pv_total_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#battery_to_house_entity
    flow_battery_to_house:
          friendly_name: "Flow Battery to House"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set batt2house_var = states('sensor.battery_discharge')|float
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if batt2house_var > 0.005 %}
                {{ (states('sensor.battery_discharge')|float
                - states('sensor.feed_in_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}
          
#battery_to_grid_entity
    flow_battery_to_grid:
          friendly_name: "Flow Battery to Grid"
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set batt2grid_var = states('sensor.battery_discharge')|float
                - states('sensor.load_power')|float
                - (states('sensor.system_losses')|float ) %}
            {% if batt2grid_var > 0.005 %}
                {{ (states('sensor.battery_discharge')|float
                - states('sensor.load_power')|float
                - (states('sensor.system_losses')|float )) * 1000 }}
            {% else %}
                0
            {% endif %}

If anyone could point me in the right direction with how I need to change my template sensors I would be most grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant