Scrape sensor for SMA Sunny Portal

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

A solution for reading out the “Current PV Power” from sunny portal is available here:

Hi Frank, can you help me out please?
I opened up the public link in Sunnyportal
I added the text to the configuration.yaml file (and replaced your link with mine)
I guess i dont need to replace the SMA_username and SMA_password cause its a public link?

But the step after that you lost me :wink:
Where do I have to add this code →

device_class: energy
state_class: total_increasing

Thanks!

Hello mvanimpe,

if you go back to my post #23 you will find the file …
o 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

But this was not working for me anymore. You have to move on to the scrape integration:

see also:

Frank

Thank you Frank!
I’ll look into that!

Hello,
i am installer and need monitoring all systems. can you help me with text to yaml?

For reference, here is my scrape for the SMA Sunnyportal, using the new way to scrape:

scrape:
  - resource: https://www.sunnyportal.com/Templates/PublicPage.aspx?page=fb.... #change to yours
    sensor:
      - name: SMA_pv_unit
        select: "#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldUnit"
      - name: SMA_pv_period
        select: "#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldPeriodTitle"
      - name: SMA_pv_wh
        select: "#ctl00_ContentPlaceHolder1_PublicPagePlaceholder1_PageUserControl_ctl00_PublicPageLoadFixPage_energyYieldWidget_energyYieldValue"
        value_template: '{{ value | replace (",", ".") | float }}'

template:
  - sensor:
      - name: SMA_energy
        unique_id: id_SMA_energy
        unit_of_measurement: "Wh"
        state_class: "total_increasing"
        device_class: "energy"
        state: >
          {% if is_state('sensor.SMA_pv_period', 'Today') %}
            {% if is_state('sensor.SMA_pv_unit', 'kWh') %}
              {{ states('sensor.SMA_pv_wh') | round(1) *1000 }}
            {% else %}
              {{ states('sensor.SMA_pv_wh') | round(1) }}
            {% endif %}  
          {% else %}
            0
          {% endif %}

Stefan