Hi, I am trying to directly read an inverter with Solaredge inverter and meter via Modbus TCP. It communicates with SunSpec protocol, I saw that there is integration, but it has problems with scaling and the author has not responded for a long time. SunSpec for each quantity gives you two Modbus address the value and scale (which keeps changing). I would like to access the inverter directly and not use extensions that depend on the developer and solaredge. I have tried to do it myself, but the continuous scale changes lead to incorrect values, especially in the variations. I have modified the code so that it only calculates when the scale has not changed recently, but I keep getting absurd values 2/3 times a day. Sometimes they look like Modbus read errors, but sometimes they look like calculation errors.
Here is the code that goes to read the modbus data:
- name: "SolarEdge"
type: tcp
host: "192.168.1.9" # Sostituisci con l'indirizzo IP del tuo inverter
port: 1502 # Porta predefinita per Modbus TCP
sensors:
- name: "Scala_W_pensiline_L"
address: 40084
input_type: holding
data_type: int16
unit_of_measurement: ""
scale: 1
state_class: measurement
scan_interval: 30
- name: "Pensiline_Potenza_L"
address: 40083 # Registro SunSpec per la potenza AC
input_type: holding
data_type: int16
scale: 1
unit_of_measurement: "W"
device_class: power
state_class: measurement
scan_interval: 30
Here the one that calculates the derived values
sensor:
pensiline_potenza:
unique_id: "id_pensiline_potenza"
friendly_name: "Pensiline Potenza"
unit_of_measurement: "kW"
device_class: power
value_template: >-
{% set s1 = states('sensor.Pensiline_Potenza_L') %}
{% set s2 = states('sensor.Scala_W_pensiline_L') %}
{% set scale_last_change = as_timestamp(states.sensor.Scala_W_pensiline_L.last_changed) %}
{% set now_ts = as_timestamp(now()) %}
{% if (now_ts - scale_last_change) < 5 %}
{{ none }}
{% else %}
{% if s1 not in ['unknown', 'unavailable', None] and s2 not in ['unknown', 'unavailable', None] %}
{{ (s1 |float (0) * 10**(s2 |float (0))) / 1000 | round(2) }}
{% else %}
{{ none }}
{% endif %}
{% endif %}
Do you have any suggestions to eliminate these error? It would be fine for me to simply eliminate them when absurd. Many thanks