Solar Analytics API integration into HA Energy Management

Using Adams I get 5 second "Live"updates if I have solar analytics web page open but it returns one minute updates not to long after the webpage is closed. Is this the behaviour you get as well?

Hi everyone - sorry for my lack of contribution as a didn’t realise this thread was still alive. Similar to the notes above, I’ve been digging into the Solar Analytics My Energy Usage webpage code. As a result I’ve added a couple of improvements to my original code above (still in configuration.yaml, but the sa_site_id is in the secrets.yaml.

In particular, I have two new gets that provide updates to how the original code establishes the latest power (now minutely update) and energy which is 5 minutely update for all channels (e.g. HVAC, EV, hot-water). Summary of the gets as follows and full link to my updated solution on GitHub is below.

Get 5 minute energy data for all channels:

https://portal.solaranalytics.com.au/api/v2/site_data/{{ states('input_text.sa_site_id') }}?all=true&gran=minute&trunc=false&power=false&tstart={{ now().strftime("%Y%m%d") }}&tend={{ now().strftime("%Y%m%d") }}

Note newly introduced parameters are as follows.

  • all=true # gets data for all device channels
  • trunc=false # gets decimal part of energy usage (makes for more accurate total)
  • power=false # gets energy, instead of power (defaults to true).

Also note, the “raw” parameter is not used, nor required, as with the no-trunc decimals enabled the total numbers are exactly as reported via the SA portal. This also reduces the data size of the get to just the per 5 minute data fields for the day.

Get minute power updates for consumption and generation (as has been discussed by others above)

https://portal.solaranalytics.com.au/api/v3/live_site_data?site_id={{ states('input_text.sa_site_id') }}&last_six=true

You can see my updated complete solution with more notes and instructions on git-hub:

Further to my post above I meant to add a note regarding the configuration of the channels. To see the names of the available channels use the developer tools - states to look at “sa_data_by_5min” entity. As shown in my example below, it includes the original energy generated/consumed attributes, and now any other loads. If you aren’t using the full three/six channels of your SA monitoring device, then some code segments will need to be deleted.

btw, I would also recommend keeping the scan_interval at max 300 secs (5 mins) as polling more frequently won’t change the results and only add to the load on the Solar Analytics servers and your HA platform.

These load names (e.g. load_air_conditioner) should be included in the code block as per the extract below:

      sa_todays_air_conditioner_total:
        friendly_name: Heating Cooling Energy
        unit_of_measurement: "Wh"
        value_template: "{{ states.sensor.sa_data_by_5min.attributes.data | rejectattr('load_air_conditioner', 'equalto', None) | sum(attribute='load_air_conditioner') | int }}"
        icon_template: mdi:hvac
        device_class: "energy"
        attribute_templates:
          state_class: total_increasing
          time_stamp: "{{ states.sensor.sa_data_by_5min.state }}"
      sa_todays_electric_vehicle_total:
        friendly_name: Electric Vehicle Energy
        unit_of_measurement: "Wh"
        value_template: "{{ states.sensor.sa_data_by_5min.attributes.data | rejectattr('load_ev_charger', 'equalto', None) | sum(attribute='load_ev_charger') | int }}"
        icon_template: mdi:car-electric
        device_class: "energy"
        attribute_templates:
          state_class: total_increasing
          time_stamp: "{{ states.sensor.sa_data_by_5min.state }}"

Once generated, the new energy entities can be added to the HA Energy Manager - Monitor Individual Devices window/widget. Go to HA settings and then search for “Energy Configuration” to make the changes. See example results below:

1 Like

Now available as a package to include in your configuration.yaml file.

See github for details:

1 Like

Thanks for your work on this, @PeterH24x7 and whoever else has been involved!

I just got it up and running this evening, fairly painless other than some YAML tomfoolery.

1 Like

You’re welcome Daniel. Thank you for the feedback. I presume you managed to get all your Solar Analytics channels reporting 5 minute energy updates, and also managed to complete the set-up in the HA Energy configuration.

Yes, that’s correct. My Solar Analytics setup doesn’t have many channels, I must’ve gotten the barebones package :frowning:. Do you guys have energy monitoring clamps on your hot water circuits, etc?

I will need to check the values against the SA dashboard tomorrow, as mine is a 3-phase system and I saw some mention in this thread about the 3-phase numbers being out of whack.

Hi Daniel - 3-phase will consume 3-channels just for general consumption. If you’re using a 6-channel SA device then you’ll have another 3-channels including your solar-PV (maybe 1 channel for each phase).
The numbers being “out of whack” should be fixed as described above - where data with decimal point values are used for the daily sum (before rounding the total to an integer). The numbers you see in HA should be the exactly same as in the SA portal (and the SA data download).

1 Like

Just a quick thank you Peter… I’d hacked together a sensor for my airconditioning load but really had no idea how it worked. Have just set up the package and, once I corrected some user entry errors, it’s working beautifully.

1 Like

Is anyone else finding that restarting HA results in the energy management dashboard showing the subsequent hour’s totals as if they are for the whole preceding day… therefore incorrectly inflating the dashboard’s cumulative totals?

Easy to see the hours after three restarts this morning.

I’ve done my best to work it out… but failed so far. I thought I had found it when I saw that device_class in the yaml was with quotes in relation to sensors - eg device_class: "energy"
but elswhere without quotes - device_class: energy.

But I removed all quotes and doesn’t seem to have made any difference.

Now testing with my Fronius Inverter as the source of the data for the dashboard. Perhaps the problem is with HA or my setup rather than with the SA integration.

Edit… so far it looks like the Fronius integration works well with the energy dashboard. Will keep testing to be sure.

further to my query immediately above… I have just noticed this https://github.com/PeterH24x7/-Solar-Analytics-integration-for-Home-Assistant-Energy-monitoring/issues/6

That looks a lot like what I’m seeing. Rougly eyeballing the graph, it looks like the spurious figures are about equal to the whole of the preceding day’s figures plus a little bit for that hour… ie same as the issue I’m describing.

and further reading here Energy Integration Spike - #23 by petro suggests that the problem may be that, when restarting (or otherwise unavailable) the sensor is briefly recorded as zero (which is the case when it’s viewed in history).

It seems that an availability statement of some sort (if that’s the jargon) in the yaml might be the solution… but at present that’s beyond my skills.

Hi @ddwdiot - I am in the midst of testing a solution to the issue listed on git-hub. I hope to have an updated solution in the next week. Once I’ve finished some prelim testing (i.e. nothing is broken), I will post the updated “solar_analytics.yaml” code under the issue on git-hub if you’re interested in testing it out too.

Thanks Will definitely be checking that out.

Meanwhile, I’m stumbling around with the availability template… which seems like it might be the answer to my particular issue. But I won’t keep posting unless I find something useful.

I wasn’t aware of the availability template. My solution rather deals with any “unavailable” rest platform get sensor by simply preserving the previous state and attributes of the template sensor data. Given your interest I’ve posted the ‘beta’ solution to the issue on git-hub.

Thanks again Peter. Seems like my problem is a little different to yours… ie yours is rare and perhaps random whereas I see mine every time I restart HA. Not sure if others have the same experience… perhaps I restart more often than others.

Others who might be at my basic skills level, can read about availability here Template - Home Assistant. Following is how it looks in just one of the sensors. Just one extra line in the code four up from the bottom.

  - platform: template
    sensors:
      sa_todays_energy_consumed_total:
        friendly_name: Total Energy Consumed
        unit_of_measurement: "Wh"
        value_template: "{{ states.sensor.sa_data_by_5min.attributes.data | rejectattr('energy_consumed', 'equalto', None) | sum(attribute='energy_consumed') | int }}"
        icon_template: mdi:home-lightning-bolt-outline
        device_class: energy
        availability_template: "{{ states.sensor.sa_data_by_5min.attributes.data | rejectattr('energy_consumed', 'equalto', None) | sum(attribute='energy_consumed') | int}}"
        attribute_templates:
          state_class: total_increasing
          time_stamp: "{{ states.sensor.sa_data_by_5min.state }}"

Here is what it looks like in the sensor history chart… before and after the yaml change which was done about 9 am. Your beta solution would produce a smoother chart (without the gap) but I don’t think the result will be different on the HA Energy Management dashboard.

Will report back if any problems over next few days of monitoring and please note that I can’t vouch for this as a solution for others.

No probs. I only restart my HA about once a week but I do note that some sensors have a period of being “unknown” until they first update. In case it helps I’ve replaced the
!= "unavailable"
with
not in ("unavailable", "unknown")
See updates on git-hub.

The fixes for the failed data gets have now been published as an updated solar_analytics.yaml on github.

1 Like

Thanks for this. I wonder if you could add unique ids to these which would allow UI changes such as hiding, moving rooms. I guess it can be same as the name?

image

I don’t have any oven integration on my SA. I guess all I really need is

So I would hide/disable the rest and move rooms.

Hi Peter - Great work, I have set this up very effectively in my system.

Query - Is there a sensor that shows lifetime compensation instead of just daily?

@aussie1497 - this has been done. See latest release 5 on github for this and many more enhancements.