Solar Analytics API integration into HA Energy Management

At first glance, it seems OK to me.
We’d probably need more info from your logs to help but I’m not sure I’m the best person to help troubleshoot… A lot of my home assistant troubleshooting is just trial and error + googling. :relaxed:

1 Like

No problem. So if I don’t change to the hashed line, I get a different error.

ERROR (MainThread) [homeassistant.config] Package solar_analytics setup failed. Integration solar_analytics Integration ‘solar_analytics’ not found. (See /config/packages/solar_analytics.yaml:5)

Is the content of your solar_analytics.yaml file exactly the same as mine? Especially the first line?

I didn’t change a thing, copy paste.

Do you know if there’s a limit to how often I can pull the real-time data based on the api? Could I pull every minute rather?

From here:
https://api-docs.solaranalytics.com/home.html

Rate Limits
Rate limits for all of the APIs will be assigned to the credentials or API key provided by Solar Analytics. Depending on the service, an API key will be able to do 3 requests per second, with a maximum of 86,400 requests for the whole day. If the limit is reached with your account the HTTP status code returned will be 429 (Too Many Requests). If you need to increase these limits, please reach out to [email protected].


My configuration is set to request the data every 60 seconds.
Having said that, the data on the solar analytics server only seems to be updated every 5 minutes so updating too often wouldn’t be very useful…

Sorry. Not sure I can be much help without seeing your full configuration. Maybe a separate, dedicated thread for you issue would be best.

Nice work guys, I am just requesting a key to be able to join you.

You right the data time stamp is only every 5 min so I suppose it doesn’t matter how often I poll. I probably should have gone with my own energy monitoring solution for more “live power” for automations. I want to control my water heate/pool etc based on excess energy. But the 5min lag might make this less useful.

Thanks for all the hard work everyone has put into this!

I’m pretty new to home-assistant but I’m not too shabby at programming and intercepting network traffic to get the data I need :slight_smile:

For live data (every 1 minute) then give the below a try. I’ve used the same concept under packages/*** like Glen.

This is the same data you see when you log into the SA portal and see the “live” consumption and production figures.

EDIT: I’ve actually put this down to every 10 seconds and it’s working well :slight_smile:

# This package requires the following entries in the secrets.yaml file...
#   sa_site_id: XXXXXX    (Site ID can be found here: https://my.solaranalytics.com/au/my-site/)
#   sa_username: [email protected]
#   sa_password: ************

solar_analytics_live:
  input_text:
    sa_site_id_live:
      initial: !secret sa_site_id
      
  rest:
    - authentication: basic
      resource_template: "https://portal.solaranalytics.com.au/api/v3/live_site_data?last_six=true&site_id={{ states('input_text.sa_site_id_live') }}"
      username: !secret sa_username
      password: !secret sa_password
      scan_interval: 60
      sensor:
       - name: "sa_site_data_portal_live"
         value_template: "{{ value_json['data'][-1:].t_stamp }}"
         json_attributes_path: "$.data[-1:]"
         json_attributes:
          - "consumed"
          - "generated"
          - "t_stamp"
    

  template:
    - sensor:
      - unique_id: "sa_live_consumption"
        name: "Live Consumption"
        state: "{{ state_attr('sensor.sa_site_data_portal_live', 'consumed') }}"
        
      - unique_id: "sa_live_generation"
        name: "Live Generated"
        state: "{{ state_attr('sensor.sa_site_data_portal_live', 'generated') }}"

Looking forward to this :smiley:

1 Like

Having any dramas with it eating a lot of bandwidth?

All good, there is def something going on with my config, just have to find where the issue is.

I have the data (and live data) working - nice! Thank you for all the efforts on this :slight_smile:

I have 5kW of solar on each of 3 phases and am using this SA device https://www.solaranalytics.com.au/community-news/solar-analytics-monitoring-now-for-3-phase-homes-and-up-to-6-circuits. So monitoring L1, L2, L3 solar production, and then 3 CT’s monitoring grid import/export on L1, L2, L3.

Any idea on the data variables I need to grab from the live data stream to get these 6 individual values, rather than the values combined? The installer live view shows these individually, so they are there :slight_smile:

I guess I am asking how can I ‘print’ ‘sensor.sa_site_data_portal_live’ to see what is in there?

1 Like

I reckon there will be neater ways of doing it… but I hacked something together that worked for me.
higher up in this thread (Jan 27 last year).

Thank you… From Jan 27

- platform: rest
    name: sa_my_clamp
    resource_template: 'https://portal.solaranalytics.com.au/api/v2/site_data/######?gran=minute&raw=true&tstart={{ now().strftime("%Y%m%d") }}&tend={{ ((as_timestamp(now()) | int) + 24*60*60) | timestamp_custom("%Y%m%d") }}'
    username: !secret sa_username
    password: !secret sa_password
    authentication: basic
    value_template: "{{  now() }}"
    json_attributes_path: "$.data.[2].[0]"
    json_attributes:
      # - "apparentPower"
      - "current"
      - "energy"
      # - "energyNeg"
      # - "energyPos"
      - "power"
      # - "powerFactor"
      # - "reactiveEnergy"
      # - "reactivePower"
      - "time"
      - "voltage"
    scan_interval: 120
    force_update: true

  - platform: template
    sensors:
      sa_my_clamp_power:
        friendly_name: "My Clamp Power"
        value_template: "{{ state_attr('sensor.sa_my_clamp', 'power') | round(1) }}"
        unit_of_measurement: "W"
        device_class: power
      sa_my_clamp_time:
        friendly_name: "My Clamp Time Read"
        value_template: "{{ state_attr('sensor.sa_my_clamp', 'time') | int | timestamp_custom ('%d-%m-%Y %H:%M')  }}"

I am not sure that is the full list of available paramaters?

Sorry about the misdirection with the wrong date. Have edited my post so as not to confuse others.

Yes… that’s just for one clamp… The only one I needed for my purposes. The other clamps can be read by substituting the relevant number in the json attributes path.

I’m afraid it’s been some time since I hacked this together but pretty sure my clamp was clamp 2 so try other numbers in that spot. You may need to use postman to have a look at the raw json result.

Sorry can’t be more helpful. I was on my limit with the code I posted in January.

1 Like

Perfect thank you! Getting 5 minute data for all 3 solar systems + the 3 phase CT clamps…

2 Likes

Wooo good stuff!

I’ve actually found a better source for solar generation now as i’ve hooked directly into my Goodwe inverter. However, the consumption data from Solar Analytics using the above method I put has been working sweet for a few weeks now :smiley:

Thank you for this, I have wanted live solar analytics data for a long time

This is my current config which pulls the data every 5 seconds. I gleamed the GET call from the Live Monitor of the SA Dashboard.

I have been trying to get the RAW data call to work for my site which is 3phase. However when I add up the energyPos/energyNeg value across the 3 phases, they never get to the same values as what’s displayed in SA dashboard. Not sure if I’m using the values correctly so I gave up.

EDIT - Oops! Just realised that adam91holt already shared similar which performs the same REST call.

  - platform: rest
    name: sa_data_by_5sec
    resource: https://portal.solaranalytics.com.au/api/v3/live_site_data?last_six=true&site_id=#######
    username: !secret sa_username
    password: !secret sa_password
    authentication: basic
    value_template: >-
      {% set most_recent_sensor_data = value_json['data'] | rejectattr('consumed', 'equalto', None) | list | last %}
        {{ most_recent_sensor_data.t_stamp }}    
    json_attributes:
        - "data"
    state_class: measurement
    device_class: energy
    scan_interval: 5
    force_update: true

  - platform: template
    sensors:
      sa_consumption_power:
        friendly_name: Power Consumption
        unit_of_measurement: "W"
        value_template: >      
          {% set most_recent_sensor_data = states.sensor.sa_data_by_5sec.attributes.data | rejectattr('consumed', 'equalto', None) | list | last %}
            {{ most_recent_sensor_data.consumed }}
        icon_template: mdi:home-lightning-bolt-outline
        device_class: "power"
        attribute_templates:
          state_class: measurement
          time_stamp: "{{ states.sensor.sa_data_by_5sec.state }}"
      sa_generation_power:
        friendly_name: Power Generation
        unit_of_measurement: "W"
        value_template: >      
          {% set most_recent_sensor_data = states.sensor.sa_data_by_5sec.attributes.data | rejectattr('generated', 'equalto', None) | list | last %}
          {{ 0 if most_recent_sensor_data.generated < 0 else most_recent_sensor_data.generated }}
        icon_template: mdi:transmission-tower-import
        device_class: "power"
        attribute_templates:
          state_class: measurement
          time_stamp: "{{ states.sensor.sa_data_by_5sec.state }}"
      sa_import_export_power:
        friendly_name: Power Import Export
        unit_of_measurement: "W"
        value_template: >      
          {{ (states.sensor.sa_consumption_power.state | int) - (states.sensor.sa_generation_power.state | int) }}
        icon_template: mdi:transmission-tower
        device_class: "power"
        attribute_templates:
          state_class: measurement
          time_stamp: "{{ states.sensor.sa_data_by_5sec.state }}"