That’s exactly what I’ve been trying to do, but can’t nail the logic. Whenever I make a template sensor that works correctly for the current scenario, I look at it later that day or the next day and it’s broken. It’s a game of whack-a-mole and I’m not winning…
What makes my installation more complex is the batteries and TOU offsetting I use. Before 12 I run the house on the grid and send all PV to charge the batteries, after 12 it stops using the grid and uses a combination of solar and battery to support the house until 9.
Here’s an example of my sensor:
- name: "Powerflow Solar to House"
state: >-
{% set solar = states('sensor.solark_pv1_input_power') | int(0) %}
{% set grid = states('sensor.solark_grid_external_total_power') | int(0) %}
{% set house = states('sensor.solark_load_power') | int(0) %}
{% set battery = states('sensor.solark_battery_power') | int(0) %}
{% set battery_charging = states('sensor.powerflow_battery_charge') | int(0) %}
{% set battery_discharging = states('sensor.powerflow_battery_discharge') | int(0) %}
{% if solar > 10 %}
{% if ( solar - battery_charging ) / solar < 0.1 and grid > 20 %}
{{ grid }}
{% elif grid < 50 %}
{{ solar - battery_charging }}
{% else %}
{{ solar }}
{% endif %}
{% else %}
0
{% endif %}
device_class: power
unit_of_measurement: W
Hi Andrew, did you have any luck with the stock powerwall templates on the github and ‘grid to battery’ and ‘battery to grid’ sensors? any help would be appreciated.
These are the templates I am using for my system (without battery). Let me know if you are able to use them in your setup.
Explanation:
The grid consumption must be multiplied by -1 because the active_power_2 sensor from the huawei_solar integration is negative when importing and positive when exporting, whereas for the solar power card you need it the other way around.
the grid_feed_in sensor represents the PV output to grid, so it is equal to active_power_2 when exporting, but needs to be set to 0 when importing from grid.
the solar_consumption sensor is
equal to the output power of the inverter when active_power_2 is positive (you are importing, so you consume all the PV power)
the difference between the inverter output power and the export value (your are exporting, so you consume less then the production)
grid_consumption:
friendly_name: Power imported from grid
device_class: power
unit_of_measurement: W
value_template: >-
{{ states('sensor.active_power_2') |multiply (-1) }}
grid_feed_in:
friendly_name: PV output to grid
device_class: power
unit_of_measurement: W
value_template: >-
{% if states('sensor.active_power_2')|float > 0 %}
{{ states('sensor.active_power_2') |float }}
{% else %}
{{ 0 }}
{% endif %}
solar_consumption:
friendly_name: PV power self consumption
device_class: power
unit_of_measurement: W
value_template: >-
{% if states('sensor.active_power_2')|float < 0 %}
{{ states('sensor.active_power')|float }}
{% else %}
{% set self_consumption = states('sensor.active_power') |float - states('sensor.active_power_2') |float %}
{{ self_consumption }}
{% endif %}
maybe this is ok for who use charge Luna2000 from grid?
# sensor grid to battery
- platform: template
sensors:
grid_to_battery:
friendly_name: "Grid to Battery"
unit_of_measurement: "W"
value_template: >-
{% set ap2 = states('sensor.active_power_2') | int %}
{% set bdd = states('sensor.charge_discharge_power') | int %}
{% set ip = states('sensor.input_power') | int %}
{% set ap1 = states('sensor.active_power') | int %}
{% if ap2 < 0 and bdd > 0 and ip <= 0 and ap1 > 0 %}
{{ (-1 * ap) | int }}
{% else %}
{{ (0) }}
{% endif %}
# extra values to show as text above icons
#battery_extra_entity: sensor.solax_x1h_batpower
#house_extra_entity: sensor.kitchen_thermostat_current_temperature
generation_extra_entity: sensor.openweathermap_cloud_coverage
#grid_extra_entity: sensor.smart_meter_electricity_import_today
# optional appliances with consumption and extra values
appliance1_consumption_entity: sensor.psl_247045_current_energy_2
appliance1_extra_entity: sensor.i3_120_charging_status
#appliance2_consumption_entity: sensor.heating_consumption
#appliance2_extra_entity: sensor.heating_operation
‘’’
My solar (yellow sun icon value) uses the sesnor “sensor.solax_pv_total_power_2” this is the total my PV is producing in real time, that works fine.
However it then messes with the blue House icon value. The blue house icon should be showing the load of what the house is using in real time. This should use the sensor “sensor.solax_house_load” but there is no where to put that sensor in the above code?
Happy to buy someone a beer who can help/program.
Presume the blue house icon is just taking the solar now reading and not the actual “house load”
As you can see the realtime House load read house is different from the blue icon
I think the calc its doing is SOLAR GEN + GRID IN = blue house logo value, but the house load is way higher but its not aware of that because no sensor for it used in the above code. How can i code in the house load sensor??
Is there a way to resize this card? I have tried using CardMod to size the card, but that doesn’t make the text/graphics scale, and so they just run off the sides of the card.
For this card all values need to be positve. But my battery uses the same sensor ( [sensor.battery_charge_discharge_power] ) for battery discharging and charging. The valua gets positive when charging and negative when discharging.