PVoutput plugin for HASS

I have solar panels at home. It would be nice to see the actual status of these panels in the HASS overview screen.

This is information like:

  • actual output (watts)
  • generated today (kWh)
  • generated this week (kWh)
  • generated this month (kWh)
  • generated this year (kWh)
  • total generated (kWh)
  • max power output today (watts)
  • panel temperature

I upload this information from my solar system to pvoutput.org. It would be usefull to have a plugin which connects to pvoutput.org. The pvoutput site offers the possibility to connect by an api to get the desired information. With the collected information it is possible to create nice charts in the HASS overview screen. You can connect to pvoutput with api key and account number.

My wishes ;-):

  1. I have multiple pv setups Iā€™d like to monitor, so I should be able to make multiple simultanious connections to pvoutput.org
  2. the above points with an asterisk are the minimal functions you should be able to see, the others are nice to have

With a REST sensor you should be able access those details.

sensor:
  - platform: rest
    resource: http://pvoutput.org/service/r2/getstatus.jsp
    value_template: '{{ value_json.total }}'
    headers:
      X-Pvoutput-Apikey: Your-API-Key
      X-Pvoutput-SystemId: Your-System-Id

The issue here is that with this approach your 60 requests per hour will gone quickly if you use multiple sensors. Indeed would the right way be to create a pvoutput sensor platform.

Can you make a request with curl and post the response?

I happened to give the REST sensor a try for this earlier today.

http://pvoutput.org/service/r2/getstatus.jsp?key=yourkey&sid=yoursid

returns:

20161103,17:10,33600,292,NaN,NaN,0.047,26.6,NaN

The NaNs are because I donā€™t record consumption. Alternatively:

http://pvoutput.org/service/r2/getoutput.jsp?sid=yoursid&key=yourkey&df=20161101

returns

20161103,33600,5.385,33600,0,5341,NaN,Fine,18,28,0,0,0,0;20161102,41200,6.603,41200,0,5053,NaN,Fine,13,29,0,0,0,0;20161101,7881,1.263,7881,0,4328,12:40,Cloudy,21,26,0,0,0,0

This setup works for me to extract energy generated today so far (but a sensor platform would be better):

> sensor 4:
>   - platform: rest
>     resource: http://pvoutput.org/service/r2/getstatus.jsp?key=yourkey&sid=yoursid
>     name: PVOutput Energy Today
>     value_template: '{% set list = value.split( "," ) %} {{ float(list[2])/1000 }}'
>     unit_of_measurement: kWh
1 Like

https://github.com/home-assistant/home-assistant/pull/4203

1 Like

Awesome - that was quick! Looking forward to giving it a try.

Thank you! Thatā€™s been a very useful post.

I was struggling with the output of the API before but with your example got it working. Iā€™m looking for some help at for 2 things:

  • Number formatting (current filter is adding a decimal and I would like a . in stead of a ,)
  • Less API callā€™s (assume my code below is doing 4 api calls)
  - platform: rest
    resource: http://pvoutput.org/service/r2/getstatus.jsp?key=xxx&sid=26803
    name: Current power generated
    value_template: '{% set list = value.split( "," ) %} {{ "{0:,}".format(float(list[3])) }}'
    unit_of_measurement: Watt
  - platform: rest
    resource: http://pvoutput.org/service/r2/getstatus.jsp?key=xxx&sid=26803
    name: Energy generated today
    value_template: '{% set list = value.split( "," ) %} {{ float(list[2])/1000 | round(1) }}'
    unit_of_measurement: kWh
  - platform: rest
    resource: http://pvoutput.org/service/r2/getstatus.jsp?key=xxx&sid=26803
    name: Current power used
    value_template: '{% set list = value.split( "," ) %} {{ "{0:,}".format(float(list[5])) }}'
    unit_of_measurement: Watt
  - platform: rest
    resource: http://pvoutput.org/service/r2/getstatus.jsp?key=xxx&sid=26803
    name: Energy used today
    value_template: '{% set list = value.split( "," ) %} {{ (float(list[4])/1000) | round(1) }}'
    unit_of_measurement: kWh

Does this do what you need?:

value_template: '{% set list = value.split( "," ) %} {{ "%0.3f"|format(list[3]|float/1000)  }}' 

I found that with 3 sensors I exceeded the allowable api calls - 1 was OK - testing with 2 now.
It would be good if the frequency of API calls by the REST sensor was customisable.
fabaffā€™s new PVOutput Sensor should solve this.

1 Like

It does help but I would like to replace the . with a , as we, in the Netherlands, use . as a decimal mark.

Iā€™ve installed nl_NL.UTF-8 on my pi. Do I need to set the locale for Python?

I think that is mandatory to have this sensor work properly. My data is update every 5 minutes.

Iā€™m curious to find out when this will be released :slight_smile:

You can easily test this by enabling the sensor as a custom-component. Iā€™m using it right now this way. There are a few details to sort out, but overall it works nice.

1 Like

Realy great to see PVoutput as a component! I also pv output with the rest platform and hat the issue with too much requests. I tried to used scan_interval:300 but did not work.
Iā€™m just starting with HASS - so how can I enable this sensor as a custom-component?
Is it enough just to add the pvoutput.py to ~/.homeassistant/custon_components/sensor and add
- platform: pvoutput
system_id: 1234
api_key: xyz
scan_interval: 120
Doing this I get:
16-11-07 00:28:07 homeassistant.util.yaml: mapping values are not allowed here
in ā€œ/home/pi/.homeassistant/sensor.yamlā€, line 161, column 14
Thx,
Daniel

Thanks for the tip @joostman. Great work!

I installed the custom sensor.

  - platform: pvoutput
    name: "Zonnepanelen"
    system_id: 26803
    api_key: aed33cd37ad773ab2d43e16fb0a46eb460a49fcd
    scan_interval: 180
    unit_of_measurement: Wh

My feedback:
- unit_of_measurement does not show in the sensor badge

  • is it posible to set the data which is displayed? (some people might like ā€˜currentā€™ and others ā€˜day totalā€™.

Generic question:
- Can I use a single sensor to occupy my Power Panel tile (from my previous post)?

Found out that a lot can be done using the sensor.template!

  - platform: pvoutput
    system_id: 26803
    api_key: xxx
    scan_interval: 150
  - platform: template
    sensors:
      power_consumption:
        value_template: '{{ states.sensor.pvoutput.attributes.power_consumption }}'
        friendly_name: 'Using'
        unit_of_measurement: 'Watt'
      energy_consumption:
        value_template: '{{ "%0.1f"|format(states.sensor.pvoutput.attributes.energy_consumption|float/1000) }}'
        friendly_name: 'Used'
        unit_of_measurement: 'kWh'
      power_generation:
        value_template: '{{ states.sensor.pvoutput.attributes.power_generation }}'
        friendly_name: 'Generating'
        unit_of_measurement: 'Watt'
      energy_generation:
        value_template: '{{ "%0.2f"|format(states.sensor.pvoutput.attributes.energy_generation|float/1000) }}'
        friendly_name: 'Generated'
        unit_of_measurement: 'kWh'

There is one thing that I canā€™t get to work. The sensor widget shows 'energy_generation) but in my tile it shows unknown. Do I use the wrong name? (using states.sensor.pvoutput.attributes.energy_generation)

Output should have been: 0.31

This is the answer from the PVoutput service:
20161107,23:15,310,NaN,14081,288,NaN,NaN,NaN

My latest configuration, could be usefull for the documentation altough Iā€™m not able to solve the last sensor template.

What value should I use to display energy_generation?

  - platform: pvoutput
    system_id: 26803
    api_key: xxxx
    scan_interval: 150
    unit_of_measurement: 'Wh'
  - platform: template
    sensors:
      power_consumption:
        value_template: '{{ states.sensor.pvoutput.attributes.power_consumption }}'
        friendly_name: 'Using'
        unit_of_measurement: 'Watt'
      energy_consumption:
        value_template: '{{ "%0.1f"|format(states.sensor.pvoutput.attributes.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 %}{{ states.sensor.pvoutput.attributes.power_generation }}{% endif %}'
        # value_template: '{{ states.sensor.pvoutput.attributes.power_generation }}'
        friendly_name: 'Generating'
        unit_of_measurement: 'Watt'
      energy_generation:
        value_template: '{{ "%0.1f"|format(sensor.pvoutput|float/1000) }}'
        friendly_name: 'Generated'
        unit_of_measurement: 'kWh'

Tried:

  • sensor.pvoutput
  • states.sensor.pvoutput
  • states.sensor.pvoutput.attributes.energy_generation

Any tips @joostman @arch?

Last weekend I followed some tips from @fabaff to use template sensors for splitting up the collected information into readable information. In the end Iā€™d a solution like @Marcel030nl posted above.

For now Iā€™ve two things to sort out:

  • I canā€™t get the ā€œEnergy Generatedā€ data in my template sensor (same problem as @Marcel030nl)
  • Iā€™d like to add multiple solar installations to monitor. One possibility is to duplicate the script and use other variables, but thats not the most ā€œrobustā€ solution

@joostman fixed it!

I added this line to the custom_sensor pvoutput.py of @fabaff, line 106
ATTR_ENERGY_GENERATION: self.pvcoutput.energy_generation,
(hope this gets merged into the final sensor code)

My dashboard is now complete :slight_smile:

Great stuff - your configuration should definitely go in the docs.

I think the only permutation you didnā€™t try was ā€œstates.sensor.pvoutput.stateā€ .

The template below works - but I think your change to the code has merit.

value_template: '{{ "%0.2f"|format(states.sensor.pvoutput.state|float/1000) }}'

I think for multiple installations its just a matter of adding additional sensors, each with a unique name.

Then in your sensor templates you refer to them by name instead of by platform.
Unfortunately I donā€™t have two systems to test this on:

sensor 6:    
  - platform: pvoutput
    system_id: yourid1
    name: pv1
    api_key: xxxxx
    scan_interval: 180
  - platform: template
    sensors:
      energy_generation:
        value_template: '{{ "%0.2f"|format(states.sensor.pv1.state|float/1000) }}'
        friendly_name: 'MyPV1 Generated'
        unit_of_measurement: 'kWh'
        
sensor 7:    
  - platform: pvoutput
    system_id: yourid2
    name: pv2
    api_key: xxxxx
    scan_interval: 180
  - platform: template
    sensors:
      energy_generation:
        value_template: '{{ "%0.2f"|format(states.sensor.pv2.state|float/1000) }}'
        friendly_name: 'MyPV2 Generated'
        unit_of_measurement: 'kWh'
2 Likes

Based on what I know of the PVoutput API and HASS I would recommend using 2 sensors as well.

I created an app called PVdashboard (pvdashboard.org) based on the PVoutput API. If you want to gather information from an other SID you have to do a new query on the API.

I saw a lot of hopeful activity @fabaff (https://github.com/home-assistant/home-assistant/pull/4203). Any change this will be in the next release?

Can I help out with the corresponding documentation?