SWAT9119
(Chris)
January 6, 2022, 12:45pm
1
Hello together,
I try to implement data from my Varta Battery via XML.
Via http-Request i got following answer:
<root Timestamp="1641472928" id="125000323" ChargerCount="1" Description="VARTA">
<inverter id="M378734">
<var name="P" value="507"/>
<var name="SOC" value="15"/>
<var name="Capacity" value="5868"/>
<var name="State" value="2"/>
</inverter>
</root>
How can I get the Value Data? My configuration file looks so:
##Varta Batterie##
#Ladeleistung#
- platform: rest
name: "Varta Ladeleistung"
scan_interval: 10
resource: http://192.168.178.18/cgi/ems_data.xml
value_template: '{{ value_json.varta.value["<var name="P" value="459"/>"] | replace(",", ".")}}'
unit_of_measurement: "W"
The documentation for the XML-File can be found here:
link to documentation
Thanks in Advance!!!
tom_l
January 6, 2022, 12:59pm
2
Try this:
value_template: "{{ value_json.inverter.var[0]["@value"] }}"
SWAT9119
(Chris)
January 6, 2022, 1:16pm
3
Thanks for your fast answer!
Now I have following code:
##Varta Batterie##
#Ladeleistung#
- platform: rest
name: "Varta Ladeleistung"
scan_interval: 10
resource: http://192.168.178.18/cgi/ems_data.xml
value_template: '{{ value_json.inverter.var[0]["@value"] }}'
unit_of_measurement: "W"
right? Now I have an entity but no value…
And this Log:
Template variable error: 'dict object' has no attribute 'inverter' when rendering '{{ value_json.inverter.var[0]["@value"] }}'
for specification:
I only need following data:
<var name="P" value="507"/>
<var name="SOC" value="15"/>
<var name="Capacity" value="5868"/>
<var name="State" value="2"/>
And for each data I need an own entity. How can i specificate which value for which entity?
tom_l
January 6, 2022, 3:39pm
4
If you just use this value template what does it return:
value_template: '{{ value }}'
koying
(Chris B)
January 6, 2022, 3:59pm
5
Shouldn’t it be
value_template: "{{ value_json.root.inverter. [...]
tom_l
January 6, 2022, 4:17pm
6
I ran the xml through a json converter and path finder and that is what it gave me. Mind you the default settings for the converter may not be the same as what home assistant uses.
The only way to know for sure is to grab the lot and hope it is under 255 characters.
SWAT9119
(Chris)
January 7, 2022, 6:56am
9
It seems to work with root in the value string - Thank you very much!!!
Now I have a last question:
How can I include a alias for the state?
The var [3] gives back a state in a number, now I want to have an alias for the state:
0:Busy
1:Active
2:charge
3:discharge
etc.
koying
(Chris B)
January 7, 2022, 7:53am
10
Easiest is probably play if
/ else
. Plenty of examples in
If you actually mean “alias” (i.e. you need the original number value), you might consider a template select