I’ve already tried a lot of stuff but can’t really figure out on how to do this properly.
I’m right no reading my energy values from my PV installation. It provides accumulated data for String 1 and String 2:
- name: "Growatt Solar PV1 Energy Today"
state_topic: "energy/solar"
value_template: '{{ value_json["PV1EnergyToday"] }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "kWh"
- name: "Growatt Solar PV2 Energy Today"
state_topic: "energy/solar"
value_template: '{{ value_json["PV2EnergyToday"] }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "kWh"
Those are updating fine and work like expected I’d say.
I now want to sum them up each day and get a “PV Energy Monthly” value which is permanently stored in HA, so that I can see historical data even in 2years.
I’m not sure how to do this.
I’ve tried the following but I’m not sure if that will work as I’m not able to trigger it manually (and with my luck it won’t work anyways).
template:
- trigger:
- platform: time
at: "23:00:00"
sensors:
growatt_solar_pv1_monthly_energy:
friendly_name: "Growatt Solar PV1 Monthly Energy"
unit_of_measurement: "kWh"
value_template: >
{% set value = states('sensor.growatt_solar_pv1_monthly_energy') %}
{% if value == 'unknown' %}
{{ states('sensor.growatt_solar_pv1_energy_today') | float(default=0) }}
{% else %}
{{ states('sensor.growatt_solar_pv1_monthly_energy') | float(default=0) + states('sensor.growatt_solar_pv1_energy_today') | float(default=0) }}
{% endif %}
growatt_solar_pv2_monthly_energy:
friendly_name: "Growatt Solar PV2 Monthly Energy"
unit_of_measurement: "kWh"
value_template: >
{% set value = states('sensor.growatt_solar_pv2_monthly_energy') %}
{% if value == 'unknown' %}
{{ states('sensor.growatt_solar_pv2_energy_today') | float(default=0) }}
{% else %}
{{ states('sensor.growatt_solar_pv2_monthly_energy') | float(default=0) + states('sensor.growatt_solar_pv2_energy_today') | float(default=0) }}
{% endif %}
- trigger:
- platform: time
at: "23:01:00"
sensors:
growatt_solar_combined_monthly_energy:
friendly_name: "Growatt Solar Combined Monthly Energy"
unit_of_measurement: "kWh"
value_template: >
{% set value = states('sensor.growatt_solar_combined_monthly_energy') %}
{% if value == 'unknown' %}
{{ states('sensor.growatt_solar_pv1_monthly_energy') | float(default=0) + states('sensor.growatt_solar_pv2_monthly_energy') | float(default=0) }}
{% else %}
{{ states('sensor.growatt_solar_pv1_monthly_energy') | float(default=0) + states('sensor.growatt_solar_pv2_monthly_energy') | float(default=0) }}
{% endif %}
So how can I achieve all this stuff?