Help with Sensor config

First time playing with home assistant, have managed to get most things running but am having my first hurdle.

So, I managed to get my Solax Inverter data via the Solax CLoud API as instructed here:

I made some tweaks to the code to get it working and I do get status and some data.

The issue I am having now is that I can’t seem to get it working right so that I am able to select the sensor for the energy solar generation data on the Energy Page.

Here is my configuration.yaml code (stripped of personal ID), I figure the code is a little old and may need adjusting to work for selecting as a sensor for Add Solar Production on the Energy settings page. Any guidance will be appreciated.

# INVERTOR
sensors:
  - platform: rest
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    value_template: '{{ ( value_json.result.yieldtotal | round(0) ) }}'
    name: "Solax total"
    unit_of_measurement: "KWh"
    device_class: energy

  - platform: rest
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    value_template: '{{ ( value_json.result.acpower | round(0) ) }}'
    name: "Solax now"
    unit_of_measurement: "W"
    device_class: energy

  - platform: rest
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    value_template: '{{ value_json.result.yieldtoday }}'
    name: "Solax today"
    unit_of_measurement: "KWh"
    device_class: energy

  - platform: rest
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    value_template: "{{ value_json.result.uploadTime }}"
    name: "Solax upload time"
    device_class: timestamp

  - platform: rest
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    value_template: >
          {% if value_json.result.inverterStatus == '100' %}Wait
          {% elif value_json.result.inverterStatus == '101' %}Check
          {% elif value_json.result.inverterStatus == '102' %}Normal
          {% elif value_json.result.inverterStatus == '103' %}Fault
          {% elif value_json.result.inverterStatus == '104' %}Permanent Fault
          {% elif value_json.result.inverterStatus == '105' %}Update
          {% elif value_json.result.inverterStatus == '106' %}EPS Check
          {% elif value_json.result.inverterStatus == '107' %}EPS
          {% elif value_json.result.inverterStatus == '108' %}Self-test
          {% elif value_json.result.inverterStatus == '109' %}Idle
          {% elif value_json.result.inverterStatus == '110' %}Standby
          {% elif value_json.result.inverterStatus == '111' %}Pv Wake Up Bat
          {% elif value_json.result.inverterStatus == '112' %}Gen Check
          {% elif value_json.result.inverterStatus == '113' %}Gen Run
          {% else %}Unkown Status{% endif %}
    name: "Solax status"

You need to add this:

state_class: total_increasing

To the energy sensors (i.e. those with a unit of kWh).

Also the unit has to be kWh, you can’t have a capital k.

Based on the documentation, and several other posts, neither the new REST integration or RESTful Sensor integration support the state_class option when included in the sensor’s configuration.

What has been suggested (but I have not confirmed) is to add state_class to the sensor as a custom attribute (via either customize.yaml or Configuration > Customization).

1 Like

I tried that and corrected the KWh to kWh.

I then got this when I checked my configuration:

Invalid config for [sensor.rest]: [state_class] is an invalid option for [sensor.rest]. Check: sensor.rest->state_class. (See ?, line ?).

Also with the code from my first post, I get tonnes of syntax errors when editing using Visual plugin. Something tells me that though it sort of works, its not the current way of doing things.

And just so I can confirm and not think I am going nuts… but I am very new at this, like first install a week ago.

So far all the documentation and examples of yaml code I find seem to be broken. Has there been a change recently that also affects the yaml formating?

Yes. This is the new format:

The old format is still valid though.

Also this:

Should be:

That’s indicating precisely what I explained in my previous post. You can’t add state_class to the RESTful Sensor’s configuration. However, it’s needed if you want it to be visible to the Energy integration. The workaround is to add it as a custom attribute.

Tip
If the URL is the same for all of those RESTful Sensors then you might be better off defining them using the REST integration. You still can’t add state_class directly but the syntax is a bit more compact. That’s what tom_l referred to as the “new format”.

Some progress, new code seems to be more correct as in Visual Studio no longer complains and I am still getting data.

Issue now is that nothing shows to be able to be selected in the Energy settings page.

# IOT-INVERTOR-01
rest:
  - scan_interval: 60
    resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXXXXXXXXXXXXXXXXXX&sn=XXXXXXXXXX
    sensor:
      - name: "Solax Serial"
        value_template: "{{ value_json.result.inverterSN }}"
      - name: "Solax ID"
        value_template: "{{ value_json.result.sn }}"
      - name: "Solax Now"
        value_template: "{{ ( value_json.result.acpower | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax Today"
        value_template: "{{ value_json.result.yieldtoday }}"
        unit_of_measurement: "kWh"
      - name: "Solax Total"
        value_template: "{{ ( value_json.result.yieldtotal | round(0) ) }}"
        unit_of_measurement: "kWh"
      - name: "Solax Feedin"
        value_template: "{{ ( value_json.result.feedinpower | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax Feed Total"
        value_template: "{{ ( value_json.result.feedinenergy | round(0) ) }}"
        unit_of_measurement: "kWh"
      - name: "Solax Consume"
        value_template: "{{ ( value_json.result.consumeenergy | round(0) ) }}"
        unit_of_measurement: "kWh"
      - name: "Solax FeedIn 2"
        value_template: "{{ ( value_json.result.feedinpowerM2 | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax EPS 1"
        value_template: "{{ ( value_json.result.peps1 | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax EPS 2"
        value_template: "{{ ( value_json.result.peps2 | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax EPS 3"
        value_template: "{{ ( value_json.result.peps3 | round(0) ) }}"
        unit_of_measurement: "W"
      - name: "Solax Type"
        value_template: >
          {% if value_json.result.inverterType == '1' %}X1-LX
          {% elif value_json.result.inverterType == '2' %}X-Hybrid
          {% elif value_json.result.inverterType == '3' %}X1-Hybiyd/Fit
          {% elif value_json.result.inverterType == '4' %}X1-Boost/Air/Mini
          {% elif value_json.result.inverterType == '5' %}X3-Hybiyd/Fit
          {% elif value_json.result.inverterType == '6' %}X3-20K/30K
          {% elif value_json.result.inverterType == '7' %}X3-MIC/PRO
          {% elif value_json.result.inverterType == '8' %}X1-Smart
          {% elif value_json.result.inverterType == '9' %}X1-AC
          {% elif value_json.result.inverterType == '10' %}A1-Hybrid
          {% elif value_json.result.inverterType == '11' %}A1-Fit
          {% elif value_json.result.inverterType == '12' %}A1-Grid
          {% elif value_json.result.inverterType == '13' %}J1-ESS
          {% else %}Unkown Type{% endif %}
      - name: "Solax Status"
        value_template: >
          {% if value_json.result.inverterStatus == '100' %}Wait
          {% elif value_json.result.inverterStatus == '101' %}Check
          {% elif value_json.result.inverterStatus == '102' %}Normal
          {% elif value_json.result.inverterStatus == '103' %}Fault
          {% elif value_json.result.inverterStatus == '104' %}Permanent Fault
          {% elif value_json.result.inverterStatus == '105' %}Update
          {% elif value_json.result.inverterStatus == '106' %}EPS Check
          {% elif value_json.result.inverterStatus == '107' %}EPS
          {% elif value_json.result.inverterStatus == '108' %}Self-test
          {% elif value_json.result.inverterStatus == '109' %}Idle
          {% elif value_json.result.inverterStatus == '110' %}Standby
          {% elif value_json.result.inverterStatus == '111' %}Pv Wake Up Bat
          {% elif value_json.result.inverterStatus == '112' %}Gen Check
          {% elif value_json.result.inverterStatus == '113' %}Gen Run
          {% else %}Unkown Status{% endif %}
      - name: "Solax Upload Time"
        value_template: "{{ value_json.result.uploadTime }}"

Because each sensor needs:
device_class: energy
state_class: total_increasing

The first can be added to each sensor’s configuration, the second one added as a custom attribute to each sensor (using one of the two methods described in my previous post). Maybe in the future the REST integration will support state_class in the configuration but, for now, you must add it as customization.

If I have to have device_class for each sensor, could I just put it with the URL to apply it to all sensors?

Not according to the documentation.

The common information is just for the connection.

had a few more hiccups with getting customize.yaml working but finally have the sensors available in the energy tab.

Thank you very much for the guidance, but more importantly, for not giving me the straight-up answer. I still had to nut it out and therefore have learnt quite a bit in the process.

The only question I have now is what sensors to set to consumption, return to grid and the solar-generated. The values from the API are here: https://www.eu.solaxcloud.com/phoebus/resource/files/userGuide/Solax_API_for_End-user_V1.0.pdf

I think–
Solar Production: yieldtotal
Consumption: consumeenergy
Return to Grid: feedinenergy

All of the errors in your configuration were clearly identified and instructions provided to correct them. Even links to the documentation were supplied.

What do you feel would have constituted a more ‘straight-up’ answer?

I was just pointing out that I was happy with that. Rather than just being given a code sample that works, I still had to read and learn and work out the code to use. Sometimes in various things, I just get told do this. No explanations, or anything, and therefore I don’t learn.

I am not being sarcastic or anything if you think that, I am being genuine. After this experience, I now know lots more about the YAML code than I did when I started. I will guarantee this won’t be my last hurdle, and knowing more will mean I should be able to solve more problems myself in future.

And, also, a big thankyou for your help, it was very much appreciated.

1 Like

hi, do you have final sensors.yaml file, im strugling to get this working…
it seems very difficult.