Help needed with new sensor solar component. (almost there)

Nice work. Would you mind sharing the code?

All credits for this to Edwin Biemond, bij de weg.

import http.client
import ssl
import time
import calendar
import hmac
import hashlib
import base64

appSecret = b’’
appKey = ‘’
apiKey = ‘’

ourTime = round(time.time() * 1000)

signature = “GET\napplication/json\n\n\n\nX-Ca-Key:” + appKey + “\nX-Ca-Timestamp:” + str(ourTime) + “\n/getPlantOverview?key=” + apiKey

print(signature)

signature2 = base64.b64encode(hmac.new(appSecret, signature.encode(), hashlib.sha256).digest()).decode()
print(signature2)

conn = http.client.HTTPSConnection(“api.general.zevercloud.cn”, context = ssl._create_unverified_context())
payload = ‘’
headers = {
‘Accept’: ‘application/json’,
‘X-Ca-Key’: appKey,
‘X-Ca-Signature’: signature2,
‘X-Ca-Signature-Headers’: ‘X-Ca-Key,X-Ca-Timestamp’,
‘X-Ca-Timestamp’: str(ourTime)
}
conn.request(“GET”, “/getPlantOverview?key=”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))

@arjenotto when setting the right settings for

appSecret = b'<appsecret>'
appKey = '<appkey>'
apiKey = '<apikey>'

And replacing some broken quotes, like ‘’ which should be " (looks like a paste error) I’m unable to get any data printed.
No errors are printed nor any data.
I’m getting the following response:

python zever.py                                                                                                                                                                                                                
GET
application/json

X-Ca-Key:25053317
X-Ca-Timestamp:1621723906250
/getPlantOverview?key=<appSecret>
JIy9vhJRLKXqsS6WF5TjbmlB14oo5ZqlJXpeDdc+4OM=

It’s only printing the signatures, like print(signature2)
What am I missing?

regards,
Passie

Maybe u forgot to put your appkey in

conn.request(“GET”, “/getPlantOverview?key={yourappkey}”, payload, headers)

The python code works for me with apiKey instead of appKey and I get proper response.


conn.request("GET", "/getPlantOverview?key={apiKey}", payload, headers)

How will I integrate it with HomeAssistant now? I guess I need to add a custom component but my skills are not there yet.

@arjenotto can you shed a bit of more light how have you done it?

I have made a commandline :

  • platform: command_line
    name: ZeverSolarPlant
    json_attributes:
    • sid
    • ludt
    • status
    • E-Today
    • E-Month
    • E-Total
    • TotalYield
    • CO2Avoided
    • Power
      command: “python3 /home/pi/(yourscript).py”
      value_template: ‘OK’
  • platform: template
    sensors:
    e_today_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“E-Today”][“value”] }}’
    unit_of_measurement: “W”
    e_month_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“E-Month”][“value”] }}’
    unit_of_measurement: “kWh”
    e_total_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“E-Total”][“value”] }}’
    unit_of_measurement: “MWh”
    totalyield_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“TotalYield”][“value”] }}’
    unit_of_measurement: “€”
    co2avoided_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“CO2Avoided”][“value”] }}’
    unit_of_measurement: “T”
    power_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“Power”][“value”] }}’
    unit_of_measurement: “W”
    status_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“status”][“value”] }}’
    ludt_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“ludt”][“value”] }}’
    sid_value:
    value_template: ‘{{ states.sensor.zeversolarplant.attributes[“sid”][“value”] }}’

I have added the config to configuration.yaml and also placed the script in /home/homeassistant/zevercloud.py. Hovewer I’am getting the following errors

Logger: homeassistant.components.command_line.sensor
Source: components/command_line/sensor.py:121
Integration: command_line (documentation, issues)
First occurred: 12:01:28 AM (1 occurrences)
Last logged: 12:01:28 AM

Unable to parse output as JSON: GET application/json X-Ca-Key:xxx X-Ca-Timestamp:1622671286651 /getPlantOverview?key=xxx= {"sid":xxx,"ludt":"2021-06-02 20:37:41","status":"0","E-Today":{"unit":"KWh","value":47.1},"E-Month":{"unit":"KWh","value":88.4},"E-Total":{"unit":"MWh","value":13.83},"TotalYield":{"unit":"zł","value":7607.88},"CO2Avoided":{"unit":"T","value":13.83},"Power":{"unit":"W","value":0}}

and also

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:71
Integration: template (documentation, issues)
First occurred: 12:01:48 AM (6 occurrences)
Last logged: 12:01:48 AM

TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.zeversolar.attributes["E-Month"]["value"] }}")' for attribute '_state' in entity 'sensor.e_month_value'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.zeversolar.attributes["E-Total"]["value"] }}")' for attribute '_state' in entity 'sensor.e_total_value'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.zeversolar.attributes["TotalYield"]["value"] }}")' for attribute '_state' in entity 'sensor.totalyield_value'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.zeversolar.attributes["CO2Avoided"]["value"] }}")' for attribute '_state' in entity 'sensor.co2avoided_value'
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.zeversolar.attributes["Power"]["value"] }}")' for attribute '_state' in entity 'sensor.power_value'

Here is my config below:

  - platform: command_line
    name: ZeverSolarPlant
    json_attributes:
      - E-Today
      - E-Month
      - E-Total
      - TotalYield
      - CO2Avoided
      - Power
    command: "python3 /home/homeassistant/zevercloud.py"
    value_template: 'OK'
  - platform: template
    sensors:
      e_today_value:
        value_template: '{{ states.sensor.zeversolar.attributes["E-Today"]["value"] }}'
        unit_of_measurement: "kWh"
      e_month_value:
        value_template: '{{ states.sensor.zeversolar.attributes["E-Month"]["value"] }}'
        unit_of_measurement: "kWh"
      e_total_value:
        value_template: '{{ states.sensor.zeversolar.attributes["E-Total"]["value"] }}'
        unit_of_measurement: "MWh"
      totalyield_value:
        value_template: '{{ states.sensor.zeversolar.attributes["TotalYield"]["value"] }}'
        unit_of_measurement: "z ^b"
      co2avoided_value:
        value_template: '{{ states.sensor.zeversolar.attributes["CO2Avoided"]["value"] }}'
        unit_of_measurement: "T"
      power_value:
        value_template: '{{ states.sensor.zeversolar.attributes["Power"]["value"] }}'
        unit_of_measurement: "W"

Do you know what am am I doing wrong?

i’m trying to get this working as well, where do i find my appkey and do i need to add anything at appSecret? Thanks

The AppKey and APPsecret can be found in your zevercloud account management settings.

I tried to read all the comments and make something of this but i don’t understand all.
Can someone explain what to do?
Never mind, I found the best and the easiest way. Go and the check it out: GitHub - Brahmah/ZeverSolar-Home-Assistant: Query's Data From ZeverSolar Inverters Locally Without Using ZeverCloud

I found this a while ago and used the local implementation mentioned in the post above. It mostly works fine but sometimes there are some minor issues where the sensor values are incorrect. I made some slight improvements to the configuration to address these issues. The code is posted here: GitHub - HarmvZ/home-assistant-zeversolar: Set of configuration files to setup local polling of ZeverSolar inverter stats in Home Assistant