PVoutput plugin for HASS

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?

Don’t know yet if it’s will be in 0.33.

Docs are ready but thanks for the offer.

1 Like

I am very interested in this plugin.
Can i add it manually ?

Is included in 0.33.

1 Like

9 posts were split to a new topic: PVoutput sensor configuration