I’am an rookie on home assistant, i have used before domoticz.
after i have set up different things i run on an little problem.
I want to read out some values about the fronius symo inverter.
the valuas are DC voltages and current of the mptt1 and mptt2
This is possible with an json string with an time stamp in it.
my problem is how can i set automaticly the current datetime into the string what i send.
I get now an other point, howe can i put in the datetime string{{ (now() …}} into the string.
I have deleted the dates and times and put in the datetime string{{ (now() …}} but that is not working.
answer on your quastion:
“To be clear — you want to read the 454.9, but the 192 can change and you don’t care what it is?”
Yes.
I have changed my script and do an check on “dev.tools” and than i get the next warning:
Configuration warnings
Invalid config for 'rest' from integration 'sensor' at packages/fronius_symo.yaml, line 56: invalid template (TemplateSyntaxError: expected name or number) for dictionary value 'value_template', got '{{ value_json.["Body"]["Data"]["inverter/1"]["Data"]["Voltage_DC_String_1"]["Values"].values()|first }}'
That all looks fine. There are two common formats to refer to objects within a dictionary. For:
"example": {"foo": "bar"}
you can use example.foo (“dot notation”) or example['foo'] (“bracket notation”).
You’ve used a bit of a mixture and also put some spaces in which still works, but I wouldn’t recommend it. Bracket notation is generally better, and is the only way to access items that start with a number, contain weird characters or are reserved Python keywords.
If you add device_class: current or device_class: voltage, you’ll get suitable icons for those entities.
Thanks a lot for your work! I have adapted the code for my use case and added the power values for AC L1-L3. I also calculated the power values for MPP 1 and MPP 2 with the help of ChatGPT. I can barely understand the code.
I added to configuration.yaml:
rest:!include rest_sensors.yaml
and added a new rest_sensors.yaml file with:
- resource: http://192.168.178.22/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceId=1&DataCollection=3PInverterData
sensor:
# AC currents
- name: "fronius_IAC_L1"
value_template: "{{ value_json['Body']['Data']['IAC_L1']['Value'] }}"
unit_of_measurement: "A"
device_class: current
- name: "fronius_IAC_L2"
value_template: "{{ value_json['Body']['Data']['IAC_L2']['Value'] }}"
unit_of_measurement: "A"
device_class: current
- name: "fronius_IAC_L3"
value_template: "{{ value_json['Body']['Data']['IAC_L3']['Value'] }}"
unit_of_measurement: "A"
device_class: current
# AC voltages
- name: "fronius_UAC_L1"
value_template: "{{ value_json['Body']['Data']['UAC_L1']['Value'] }}"
unit_of_measurement: "V"
device_class: voltage
- name: "fronius_UAC_L2"
value_template: "{{ value_json['Body']['Data']['UAC_L2']['Value'] }}"
unit_of_measurement: "V"
device_class: voltage
- name: "fronius_UAC_L3"
value_template: "{{ value_json['Body']['Data']['UAC_L3']['Value'] }}"
unit_of_measurement: "V"
device_class: voltage
# Calculated AC power per phase (P = U * I)
- name: "fronius_PAC_L1"
value_template: "{{ states('sensor.fronius_IAC_L1') | float * states('sensor.fronius_UAC_L1') | float }}"
unit_of_measurement: "W"
device_class: power
- name: "fronius_PAC_L2"
value_template: "{{ states('sensor.fronius_IAC_L2') | float * states('sensor.fronius_UAC_L2') | float }}"
unit_of_measurement: "W"
device_class: power
- name: "fronius_PAC_L3"
value_template: "{{ states('sensor.fronius_IAC_L3') | float * states('sensor.fronius_UAC_L3') | float }}"
unit_of_measurement: "W"
device_class: power
- resource-template: http://192.168.178.22/solar_api/v1/GetArchiveData.cgi?Scope=System&StartDate={{ (now() + timedelta(minutes=-5)).strftime('%Y-%m-%dT%H:%M:%S+01:00') }}&EndDate={{ (now() + timedelta(minutes=-5)).strftime('%Y-%m-%dT%H:%M:%S+01:00') }}Z&Channel=Current_DC_String_1&Channel=Current_DC_String_2&Channel=Voltage_DC_String_1&Channel=Voltage_DC_String_2
sensor:
# DC voltages
- name: "fronius_Voltage_DC_String_1"
value_template: "{{ value_json['Body']['Data']['inverter/1']['Data']['Voltage_DC_String_1']['Values'].values() | first }}"
unit_of_measurement: "V"
device_class: voltage
- name: "fronius_Voltage_DC_String_2"
value_template: "{{ value_json['Body']['Data']['inverter/1']['Data']['Voltage_DC_String_2']['Values'].values() | first }}"
unit_of_measurement: "V"
device_class: voltage
# DC currents
- name: "fronius_Current_DC_String_1"
value_template: "{{ value_json['Body']['Data']['inverter/1']['Data']['Current_DC_String_1']['Values'].values() | first }}"
unit_of_measurement: "A"
device_class: current
- name: "fronius_Current_DC_String_2"
value_template: "{{ value_json['Body']['Data']['inverter/1']['Data']['Current_DC_String_2']['Values'].values() | first }}"
unit_of_measurement: "A"
device_class: current
# Calculated DC power per MPP string (P = U * I)
- name: "fronius_PDC_String_1"
value_template: "{{ (value_json.Body.Data['inverter/1'].Data.Voltage_DC_String_1.Values.values() | first | float) * (value_json.Body.Data['inverter/1'].Data.Current_DC_String_1.Values.values() | first | float) }}"
unit_of_measurement: "W"
device_class: power
- name: "fronius_PDC_String_2"
value_template: "{{ (value_json.Body.Data['inverter/1'].Data.Voltage_DC_String_2.Values.values() | first | float) * (value_json.Body.Data['inverter/1'].Data.Current_DC_String_2.Values.values() | first | float) }}"
unit_of_measurement: "W"
device_class: power