Scrape sensor JS variable

Hi,

I could use a little help with a scrape/rest sensor. I managed to find a webpage where my solar inverter reports its current power output, daily and total outputs but need some help to import into HA.

The full return on the GET request is posted here:
https://pastebin.com/tL57NTaR

I’m specifically interested in line 12:

myDeviceArray[0]="PEL3000NREDACTED,,,,,997,222,23,,0,";

Where:
997 = 997W current power production
222 = 2220 Wh produced today
23 = 2300 Wh produced total

I have no clue how to use the ‘select’ line in the config.
Thus far I have this:

sensor:
  - platform: scrape
    resource: http://IP.AD.DR.ESS/js/status.js
    authentication: basic
    username: !secret username
    password: !secret password
    select: ???

Any help would be appreciated and of course I’ll post the outcome for other people with same inverters!

Sam.

I’m unable to help with your question, but what solar inverter do you use? Maybe someone here has the same one and is able to help, or knows another way to get the data.

I know of a way to do this using a Restful Sensor whose value_template employs regex_findall_index to extract a value. However, whether you use a Restful Sensor or a Scrape Sensor, you’re interested in extracting three separate values. How were you planning to handle the three values? Using three sensors, one sensor per value? Or one sensor showing all three values (separated by commas)?

@cjsimmons, the inverter is an EXE 3000 SP. Looked all over the internet but can’t find anyone who tried to integrate it somewhere.

@123, Thanks for the help. Managed to get it working but with 3 separate rest calls like this:

sensor:
  - platform: rest
    resource: http://IP.AD.DR.ESS/js/status.js
    method: GET
    name: Actual Solar Power Production
    device_class: power
    value_template: '{{ value | regex_findall_index("PEL3000N12345,,,,,(\d+)", ignorecase=true) | int }}'
    verify_ssl: false
    unit_of_measurement: W
    authentication: basic
    username: !secret inverter_user
    password: !secret inverter_pass
    force_update: true
  - platform: rest
    resource: http://IP.AD.DR.ESS/js/status.js
    method: GET
    name: Today's Solar Energy Production
    device_class: power
    value_template: '{{ value | regex_findall_index("PEL3000N12345,,,,,\d+,(\d+)", ignorecase=true) | float / 100 }}'
    verify_ssl: false
    unit_of_measurement: KWh
    authentication: basic
    username: !secret inverter_user
    password: !secret inverter_pass
    force_update: true
  - platform: rest
    resource: http://IP.AD.DR.ESS/js/status.js
    method: GET
    name: Total Solar Energy Production
    device_class: power
    value_template: '{{ value | regex_findall_index("PEL3000N12345,,,,,\d+,\d+,(\d+)", ignorecase=true) | float / 10 }}'
    verify_ssl: false
    unit_of_measurement: KWh
    authentication: basic
    username: !secret inverter_user
    password: !secret inverter_pass
    force_update: true

I’m now trying to make it better by only making a single rest call and templating out the values but no luck yet.
Maybe you can have a look?

sensor:
  - platform: rest
    resource: http://IP.AD.DR.ESS/js/status.js
    method: GET
    name: Solar Power Rest
    value_template: '{{ value | regex_findall_index("PEL3000N18642045,,,,,(\d+,\d+,\d+)", ignorecase=true) | string }}'
    verify_ssl: false
    authentication: basic
    username: !secret inverter_user
    password: !secret inverter_pass
    force_update: true
  - platform: template
    sensors:
      solar_actual_production:
        friendly_name: Actual Solar Production
        entity_id: sensor.solar_power_rest
        unit_of_measurement: W
        value_template: "{{ states.sensor.solar_power_rest.state | regex_findall_index(find='(\d+),\d+,\d+', index=0, ignorecase=False) | int }}"
        device_class: power

The rest sensor is working and has the 3 values I need separated by comma’s (997,222,23) but my template sensor is not separating the values correctly.

Use split to convert the comma-delimited string into a list. Then you can select the desired item from the list. The list is zero-based so the zeroth item is the first one (actual solar production).

  - platform: template
    sensors:
      solar_actual_production:
        friendly_name: Solar Production Actual
        entity_id: sensor.solar_power_rest
        unit_of_measurement: W
        value_template: "{{ states('sensor.solar_power_rest').split(',')[0] | int }}"
        device_class: power

      solar_produced_today:
        friendly_name: Solar Production Today
        entity_id: sensor.solar_power_rest
        unit_of_measurement: W
        value_template: "{{ states('sensor.solar_power_rest').split(',')[1] | float / 100 }}"
        device_class: power

      solar_produced_total:
        friendly_name: Solar Production Total
        entity_id: sensor.solar_power_rest
        unit_of_measurement: W
        value_template: "{{ states('sensor.solar_power_rest').split(',')[2] | float / 10 }}"
        device_class: power
1 Like

Thank you very much for the help!

I’ll try to improve it even a bit more and I’ll post the code if other people want to integrate the same inverter.