Well many ways to “skin a cat” but one way is using a REST sensor. Of course, you would use your own resource URL and maybe you want some other value as the state (especially if you want to update based on some changes). You may also only want to go after the attributes of interest to you. I typically read everything into an attribute and then use templates to find what I want because after implementation I always think, damn I need that too … and that.
So this would read the whole “root” element (note I tend to use split configuration files and this would be in sensor.yaml and included with sensor:
in your configuration.yaml). If you don’t, this should have sensor: at the top of the YAML.
- platform: rest
name: stecagrid
resource: http://192.168.2.245:8123/local/Stecagrid/result.xml
value_template: "{{ now() }}"
json_attributes:
- root
Now this would create a sensor with your entire XML as an attribute … root:
Then you can use in automations through Jinja. For example:
{{ state_attr('sensor.stecagrid','root').Device.Measurements }}
Would give me the Measurement array. I only put three in this sample but you could get them all:
Result type: dict
{
"Measurement": [
{
"@Value": "228.0",
"@Unit": "V",
"@Type": "AC_Voltage"
},
{
"@Value": "365.0",
"@Unit": "W",
"@Type": "AC_Power"
},
{
"@Value": "344.8",
"@Unit": "V",
"@Type": "LINK_Voltage"
}
]
}
You can then narrow down farther to those things you desire. If you do want to trigger off the changes (like a value exceeds some value) then you likely want to parse deeper and create individual attributes or even additional sensors that have a state that is only that value.
Like, if I knew that my entry is always the second one in the “0” indexed array, this would yield “365”:
{{ state_attr('sensor.stecagrid','root').Device.Measurements.Measurement[1]['@Value'] }}
That is really quick and dirty, you can use many other methods to find the “Measurement” of interest. You can also use “jq” to parse … as I said, many ways to “skin a cat”