Scrape sensor for SMA Sunny Portal

Hi There, did you ever get this to work?

@Felix this is my config in sensors.yaml (just replace the ID from your sunnyportal.com public page)

# Webscrapping for SMA Inverter values
- platform: scrape
  resource: "https://www.sunnyportal.com/Templates/PublicPage.aspx?page=>>PublicID<<"
  name: pv_einheit
  select: '#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldUnit'

- platform: scrape
  resource: "https://www.sunnyportal.com/Templates/PublicPage.aspx?page=>>PublicID<<"
  name: pv_periode
  select: '#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldPeriodTitle'

- platform: scrape
  resource: "https://www.sunnyportal.com/Templates/PublicPage.aspx?page=>>PublicID<<"
  name: pv_wert
  select: '#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldValue'
  value_template: '{% if is_state("sensor.pv_einheit", "Wh") %}{{ value | float / 1000 }}{% else %}{{ value | float }}{% endif %}'
#unit_of_measurement: 'kW/h'

- platform: template
  sensors:
pv_energie:
  value_template: '{%- if is_state("sensor.pv_periode", "Today") and (states.sensor.pv_wert.state | float) < 150 -%}{{ states.sensor.pv_wert.state | round(1) }}{% else %}0{% endif %}'
  friendly_name: 'SMA'
  unit_of_measurement: 'kW/h'

Maybe you need to adjust the formatting. But this one works for me.

How do I find the “public page” address for my instance? This looks like a solution to my desire to extract certain information about my solar production but I don’t know the public page address. Can this be used with the regular log in site as well???

After you registered your pv system to Sunnyportal.com you will find the public page config in the configuration menu-> PV System Presentation.

I didn’t register my plant. The installer did…

I tried this same path, but the quality of the data I could retrieve wasn’t great.
See here for alternative approach using SBFspot

I have a 3600TL-21 with no webconnect and cannot get modbus working so have tried the ‘scrape’ method - with parts of Freshhats code I have got the total PV kWh out. But I really need the realtime Watts value that his code does not seem to provide me.

The value seems to be in the following webpage code (current value is ‘0’). I would be really grateful if anyone could help me get the Home Assistant scrape parameters right to get this value out?
Thanks in advance.

Found same issue as Marius82 - the webpage has a “-” in place before it updates with the real number and the scrape does not have any delay capability so only reads the “-” – hence does not work :roll_eyes:

Hello,

i do know that this tread is pretty old. But may be someone can help. I do use the following confitguration in the configuration.yaml:

  - platform: scrape 
    resource: "https://sunnyportal.com/FixedPages/Dashboard.aspx" 
    username: !secret SMA_username
    password: !secret SMA_passwort
    name: sma yield
    select: "#ctl00_ContentPlaceHolder1_UserControlShowDashboard1_energyYieldWidget_energyYieldValue"
    unit_of_measurement: kWh    

All i get is:

2021-09-21 18:05:21 ERROR (MainThread) [homeassistant.components.scrape.sensor] Unable to extract data from HTML for sma_yield

Does anyone has a working solution for this?

Thanks in advance
Frank


i have a HA OS based installation on a raspi 4

Hello,
have solved the problem. The web address was wrong. It does not go the general web address. In sunnyportal the specific public page must be activated for the user. See above.

Starting with: https://www.sunnyportal.com/Templates/PublicPage.aspx?page=7431e23c

Frank

Hi, thanks for the very helpful configuration examples.
I managed to scrape the sensors described by @Marius82
Now I wonder if it’s possible to get the sensor of “.mainValueAmount” somehow.
Any ideas?

Hi, can you please share your configuration.yaml ?

Hi Frank, can you please share the configuration.yaml for this ? TIA

OK, i tried a lot. So far i have the part which answers the production for a day.
I really would like to see the actual consumption.
Anyhow, i am struggling to create this template Sensors:
‘’’

  • platform: template
    sensors:
    pv_energie:
    value_template: ‘{%- if is_state(“sensor.pv_periode”, “Today”) and (states.sensor.pv_wert.state | float) < 150 -%}{{ states.sensor.pv_wert.state | round(1) }}{% else %}0{% endif %}’
    friendly_name: ‘SMA’
    unit_of_measurement: ‘kW/h’
    ‘’’

Hello Carsten,

yes i can.

Several aspects are important for a successful readout. First, the sharing must be activated on the sunnyportal page. To do this, activate inside the ‘Anlagenübersicht’ in the share. The link that appears there is required.

you need this link in your configuration.yaml

sensor:
  - platform: scrape 
    resource: "https://www.sunnyportal.com/Templates/PublicPage.aspx?page=a2f24cdd-7e9c......" 
    username: !secret SMA_username
    password: !secret SMA_passwort
    name: SMA_Tagesertrag_energy_total
    select: "#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldValue"
    unit_of_measurement: Wh   

If you want to use the readout in the Energy section you need to set the following properties for the entity:

device_class: energy
state_class: total_increasing

To have this the following must be entered at the beginning of configuration.yaml.

homeassistant:
  customize: !include customize.yaml

Then a file with the name customize.yaml must be created. The following must be entered there:

sensor.sma_tagesertrag_energy_total:
  device_class: energy
  state_class: total_increasing

Now it should work.

Frank

Hi Frank,
thanks a lot.
Any idea how to read the consumption from the Sunny Portal ?
I can see it in the sunny portal, but no luck to read it for HA.

Regards
Carsten

Hello Carsten,

all i can get is the daily and total production. Unfortunately SMA is not giving more via this special webpage. Yes a also have more inside the sunnyportal …

Frank

Similar question to others here…is there a way to get the “current production” number? Rather than just the daily total?
Tried to read into the scraping tools, but I’m too new at this to make any progress.

You may try to find proper CSS select here.
I have no luck to get CSS selector for “Current PV Power”.

Hello, i need to get data from SMA Sunny portal to HA DB and grafana. Can you share how?? i am beginner in HA Thank you so much