Not succeeding in setting up pvoutput sensor

Hi there,

Coming from Domoticz I am now running Home assistant on my Proxmox server. I have one nagging problem though and that is setting up the pvoutput sensor to be utilized for creating automations for blinds etc. When I put the sensor in the configuration.yaml and after subsequent reboot of HA (0.109.6), a persistent error occurs every 5 mins (my API request frequency):

2020-05-08 14:21:25 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.pvoutput is taking over 10 seconds
2020-05-08 14:21:25 ERROR (SyncWorker_3) [homeassistant.components.rest.sensor] Error fetching data: http://pvoutput.org/service/r2/getstatus.jsp failed with HTTPConnectionPool(host='pvoutput.org', port=80): Max retries exceeded with url: /service/r2/getstatus.jsp (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f6caca046d0>, 'Connection to pvoutput.org timed out. (connect timeout=10)'))
2020-05-08 14:21:25 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.pvoutput fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/pvoutput/sensor.py", line 119, in update
    self.pvcoutput = self.status._make(self.rest.data.split(","))
AttributeError: 'NoneType' object has no attribute 'split'

I have no clue what is going on, I am on the 300 API calls Pvoutput subscription. My pvoutput sensor in configuration.yaml is as follows:

sensor:
  - platform: pvoutput
    
    system_id: xxxxx
    api_key: xxxxxxxxxxxx
    scan_interval: 300
  - 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'

Any help is greatly appreciated.

Jaap

i have pvoutput like this for my solar system:

  - platform: pvoutput
    system_id: xxx
    api_key: xxx
    scan_interval: 180
  - 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'    

Thank you. Looks like quotation in my yaml is wrong. I’ll have a go at it tonight and let you know.

Tried it last night but to no avail. I still get:

2020-05-08 22:08:48 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform pvoutput is taking over 10 seconds.
2020-05-08 22:08:49 ERROR (SyncWorker_2) [homeassistant.components.rest.sensor] Error fetching data: http://pvoutput.org/service/r2/getstatus.jsp failed with HTTPConnectionPool(host='pvoutput.org', port=80): Max retries exceeded with url: /service/r2/getstatus.jsp (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f357558bcd0>, 'Connection to pvoutput.org timed out. (connect timeout=10)'))
2020-05-08 22:08:49 ERROR (SyncWorker_2) [homeassistant.components.pvoutput.sensor] Unable to fetch data from PVOutput

This is what I put in my config yaml:

sensor:
  - platform: pvoutput
    system_id: xxxxx
    api_key: xxxxx
    scan_interval: 300
  - 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'    

As opposed to the first version of the config no reading is taken and show zero or “None” instead of one first reading and then stop.
Hope someone steers me in the right direction.
Thanks and stay safe.

Jaap

Just tried again and after reboot now the error in the logging is again:

2020-05-09 09:36:47 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform pvoutput is taking over 10 seconds.
2020-05-09 09:36:49 ERROR (SyncWorker_0) [homeassistant.components.rest.sensor] Error fetching data: http://pvoutput.org/service/r2/getstatus.jsp failed with HTTPConnectionPool(host='pvoutput.org', port=80): Max retries exceeded with url: /service/r2/getstatus.jsp (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7fb4fffb7fd0>, 'Connection to pvoutput.org timed out. (connect timeout=10)'))
2020-05-09 09:36:49 ERROR (MainThread) [homeassistant.components.sensor] pvoutput: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 322, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/pvoutput/sensor.py", line 119, in update
    self.pvcoutput = self.status._make(self.rest.data.split(","))
AttributeError: 'NoneType' object has no attribute 'split'

Clueless

Jaap

it’s not configuration the problem, maybe you are doing too much requests to pvoutput?

The service only allows 60 requests per hour but the sensor’s default is 30 seconds.

Check here: https://pvoutput.org/help.html and https://pvoutput.org/help.html#api-ratelimit

HTTP Headers

Rate limit information can be obtained by setting the HTTP header X-Rate-Limit to:

curl -v -H "X-Rate-Limit: 1" -H "X-Pvoutput-Apikey: Your-API-Key" -H "X-Pvoutput-SystemId: Your-System-Id" https://pvoutput.org/service/r2/getstatus.jsp

The HTTP response will be returned with the additional headers -

  • X-Rate-Limit-Remaining - The number of requests remaining for the hour
  • X-Rate-Limit-Limit - The total request limit for the hour
  • X-Rate-Limit-Reset - Unix time in UTC when the limit is reset

If you are within limits, try to do a query https://pvoutput.org/help.html#api-spec to ensure you are not blocking something.

Thank you, you are really helpfull. This is what i retrieved:

Seems I have 285 requests left.
I am going to check firewall now
Thanks again.
Jaap

So, after some deep diving I found my Pfsense box running Snort to block PVoutput. Taming that beast now. Not a Home Assistant issue after all.
Thank you for the HTTP headers tip it got me to this solution in the end also by giving me the IP of PVoutput so I could go through the Pfsense logs.

Jaap

I’m glad to helped you address your issue :smiley: :+1: