Need Help Reading XML for Varta

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!!!

Try this:

value_template: "{{ value_json.inverter.var[0]["@value"] }}"

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?

If you just use this value template what does it return:

value_template: '{{ value }}'

Shouldn’t it be

value_template: "{{ value_json.root.inverter. [...]

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.

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.

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