PVOutput yaml configuration.yaml gives me errors in template

I have copied this integration into the sensor: section of my configuration.yaml

It runs into errors in the template.

If I comment out the template

# PVOutut
#
  - platform: pvoutput
    system_id: *removed for security*
    api_key: *MY API KEY has been removed for security*
    name: HomePower
    scan_interval: 150
#  - platform: template
#    sensors:
#      power_consumption:
#        value_template: '{% if is_state_attr("sensor.pvoutput", "power_consumption", "NaN") %}0{% else %}{{ state_attr('sensor.pvoutput', 'power_consumption') }}{% endif %}'
#        friendly_name: 'Using'
#        unit_of_measurement: 'Watt'
#      energy_consumption:
#        value_template: '{{ "%0.1f"|format(state_attr('sensor.pvoutput', 'energy_consumption')|float/1000) }}'
#        friendly_name: 'Used'
#        unit_of_measurement: 'kWh'
#      power_generation:
#        value_template: '{% if is_state_attr("sensor.pvoutput", "power_generation", "NaN") %}0{% else %}{{ state_attr('sensor.pvoutput', 'power_generation') }}{% endif %}'
#        friendly_name: 'Generating'
#        unit_of_measurement: 'Watt'
#      energy_generation:
#        value_template: '{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(state_attr('sensor.pvoutput', 'energy_generation')|float/1000) }}{% endif %}'
#        friendly_name: 'Generated'
#        unit_of_measurement: 'kWh'
#

I get this so that proves my system_id and API key are OK.
image

If I remove the comments, I get this error.

Confused…
Anyone got any ideas?

Today I used this instead and it works.

  - platform: pvoutput
    system_id:
    api_key:
    scan_interval: 150
  - platform: template
    sensors:
      power_consumption:
        value_template: >
          {% set pc = state_attr('sensor.pvoutput', 'power_consumption') %}
          {{ '0' if pc == 'NaN' else pc }}
        friendly_name: 'Using'
        unit_of_measurement: 'Watt'

      energy_consumption:
        value_template: "{{ '{:.1f}'.format(state_attr('sensor.pvoutput', 'energy_consumption')|float/1000) }}"
        friendly_name: 'Used'
        unit_of_measurement: 'kWh'

      power_generation:
        value_template: >
          {% set pg = state_attr('sensor.pvoutput', 'power_generation') %}
          {{ '0' if pg == 'NaN' else pg }}
        friendly_name: 'Generating'
        unit_of_measurement: 'Watt'

      energy_generation:
        value_template: >
          {% set eg = state_attr('sensor.pvoutput', 'energy_generation') %}
          {{ '0' if eg == 'NaN' else '{:.2f}'.format(eg|float/1000) }}
        friendly_name: 'Generated'
        unit_of_measurement: 'kWh' 

1 Like

Thank you.
I now have it working too.
I have a timing issue where my generation show zero id my PVO has not queried Enphase.
That only happens every 15 minutes. So HA show zero.
I will have to fiddle with that. I might have to only query PVO every 20 mins or something?
trial and error.
Thanks again

I think it’s peculiar to my PVOutput but “power_generation” is always zero.
It shows up as NaN in my screen dump above so scripting in template is working as it should.

I was looking on an app on my phone "PV Output and power generation is shown there as NaN on the live page but does get it on the “Today Page”?
Weird.
I don’t get it???

Some hours later I decided that the Power Generated was a value I already had coming directly from my envoy integration so just commented that part of the template out.