I’m trying to calculate the gross power consumption of my house with solar panels using the entries in configuration.yaml below. gross power consumption = net P1 meter + Solar
Works perfectly fine as long as Solar is producing, but after sunset pv_power = unavailable instead of 0, so breaks the calculation.
Can I replace unavailable by the value 0 in my calculation in some way ? I’m pretty new to YAML code
sensor:
- platform: template
sensors:
totaal_verbruik:
unit_of_measurement: W
value_template: "{{ states('sensor.p1_meter_5c2faf0578d6_active_power') | float + states('sensor.pv_power') | float }}"
device_class: energy
From this code, you are using the old, legacy templates.
First of all, I would consider to use the newer template versions…
template:
- sensor:
- name: totaal_verbruik
unique_id: totaal_verbruik
unit_of_measurement: W
device_class: energy
state_class: total // or total_increasing
state: >
{% if states('sensor.pv_power') in ['unavailable'] %}
{{ states('sensor.p1_meter_5c2faf0578d6_active_power') | float + 0 | float }}
{% else %}
{{ states('sensor.p1_meter_5c2faf0578d6_active_power') | float + states('sensor.pv_power') | float }}
{% endif %}
but I haven’t tested this template… so just a rough example how it could be done.
Anyway - the main issue I do see here is in fact that the PV_Power will become unavailable if the inverter shuts down.
Catching the unavailable state might cause issues in your calculation, when the Sensor is really unavailable due to network issues or others.
I would recommend to raise a Change Request to the devs of the integration to provide zeros, if the inverter is available but doesn’t report any specific value (due to shutdown, etc.)
Thanks!
Float(states(),0) seems to work just fine for my purpose.
@CChris: I’ll try changing template as well later on. The device is actually offline after sunset, but I’ll raise the request with the dev anyhow to return 0 in that case.