JSON Output to Gauge in Home Assistant

Hi, I just want to see if anyone knows how to integrate a JSON Output from a solis-inverter (Solar Panels) to Home Assistant, to be able to read it’s values. I have the following json output:

{"lastSeen":1605035609563,"inverter":{"model":"00B7",,"firmwareMain":"003A","firmwareSlave":"001B"},"logger":{,"version":"MW_08_512_0501_1.80","mode":"STA","ap":{"ssid":"AP_724118333","ip":"10.10.100.254",},"sta":{"ssid":"Home","ip":"192.168.1.48","rssi":"42%"}},"remoteServer":{"a":true,"b":false},"power":2626,"energy":{"today":32,"total":647}}

But I don’t know how I can make a sensor in Home Assistant that would read for instance the “power” value.

Any help it’s appreciated.

Thanks

If you are getting the value from a rest api provided by the solis inverter, you can use a rest sensor, see here. https://www.home-assistant.io/integrations/rest/.

You do have problem with the json since there appear to be some trailing commas which makes the json invalid. For instance,

"model":"00B7",,"firmwareMain"

You have two consecutive commas here which is invalid json. Not sure how to clean this up, but maybe you can use a regular expression to parse the output since the word “power” only appear once in the json output.

You have two consecutive commas here which is invalid json. Not sure how to clean this up, but maybe you can use a regular expression to parse the output since the word “power” only appear once in the json output.

My bad, I removed some information like MAC address and Serial Number, I might have skipped some commas in the process.

I did look at this https://www.home-assistant.io/integrations/rest/ before asking the question, but the only way I can get some specific data from the JSON output would be to use this line in cmd:

curl -s ‘http://192.168.1.223:80’ | python -mjson.tool | grep power`

changing “power” to other value’s name would give me the other value’s data. But the RESTful page does not seem to use the same way to get its value.

Sorry if it doesn’t make much sense I am not an expert in this subject.

If you post the entire json, I will have a look at a json template.

Here it is:

{
    "energy": {
        "today": 34.2,
        "total": 649
    },
    "inverter": {
        "firmwareMain": "003A",
        "firmwareSlave": "001B",
        "model": "00B7",
        "serial": "XXXXXXXXXXXXXXXXXXX"
    },
    "lastSeen": 1605037320606,
    "logger": {
        "ap": {
            "ip": "10.10.100.254",
            "mac": "XXXXXXXXXXXX",
            "ssid": "AP_724118333"
        },
        "mode": "STA",
        "serial": "XXXXXXXXX",
        "sta": {
            "ip": "192.168.1.48",
            "mac": "XXXXXXXXXXXX",
            "rssi": "45%",
            "ssid": "Home"
        },
        "version": "MW_08_512_0501_1.80"
    },
    "power": 5272,
    "remoteServer": {
        "a": true,
        "b": false
    }
}

This should work:

  - platform: rest
    name: Solis power 
    resource: http://IP_TO_THE_REST_API
    value_template:  '{{ value_json.power }}'

Thank you it indeed worked.

Now if it’s not too much to ask how can I make a Gauge graphic out of this.

Similar to this one from Freeboard.io Screen Shot 2020-11-10 at 3.27.09 PM

Nevermind I got it: I edited the ui-lovelace.yaml file and added this configuration:

type: gauge
name: Solis Current Power
entity: sensor.solis_power
unit: 'Watts'
min: 0
max: 8500
severity:
  green: 5000
  yellow: 2500
  red: 0

1 Like

Great!

You might want to add

unit_of_measurement: W

to the rest sensor config, I forgot that. It helps when creating graphs.

Follow up question @tjntomas

How do I get the value for today and total?

They seem to be a subdivision of energy. If I add the value_template as
‘{{ value_json.total }}’ or {{ value_json.today }}’

There is no data passed to home assistant. But if I write {{ value_json.energy }}’ I am getting the 2 values at the same time without proper formatting: something like


“energy":{“today”:19.6,“total”:676}}

Thanks in advance for your help

value_template:  '{{ value_json.energy.today }}'

and

value_template:  '{{ value_json.energy.total }}'

Also, if you haven’t figured it out, you dont need to restart Ha everytime you change the value_json, just go to server management and click on RELOAD REST ENTITIES AND NOTIFY SERVICES.

Wow thank you for both things, the value_template worked and yes I did reload HA each time I modify the configuration.yaml file. Way better to just reload rest entities and notify services.

You rock! Thanks for your help.

Also, since we are at it, look into separating your sensors into a separate folder. The configuration.yaml file tend to get really large otherwise.

Any documentation to achieve that?

Look here: https://www.home-assistant.io/docs/configuration/splitting_configuration/

1 Like

thank you I will try that