Getting data from xml file, how?

I have some data that I want to get into HA. The input is quite long, so with the RESTfull integration I am over the 256 char limit. When using grep period I get all the data I am looking for see below:
(for the curious people, this is the output of a windturbine in Wh).

$ curl --silent | grep period

        <subset interval="HOUR" period="DAY" tstart="2020-04-06 00:00:00" tend="2020-04-06 23:59:00" sum="14632.255">
        <subset interval="DAY" period="MONTH" tstart="2020-04-01 00:00:00" tend="2020-04-30 00:00:00" sum="88488.797">
        <subset interval="DAY" period="WEEK" tstart="2020-03-31 00:00:00" tend="2020-04-06 00:00:00" sum="91294.59000000001">
        <subset interval="MONTH" period="YEAR" tstart="2020-01-01 00:00:00" tend="2020-12-31 00:00:00" sum="2189460.426">
        <subset interval="YEAR" period="LIFETIME" tstart="2013-01-01 00:00:00" tend="2020-12-31 00:00:00" sum="3.4027436681E7">

What I want to see in HA is for each different period the value of the sum. Thus I would like to get this:

somename.DAY= 14632.255

How to do this in HA? Any pointers is appreciated.
I have it working for DAY only with the use of curl|grep|awk|sed but it is a bit long commandline and only for 1 sum, not for all.

The common pattern that I use for this sort of thing is to integrate using MQTT entities. I then use some external (python in my case) script tobang against the device and then publish JSON to an MQTT topic.

At that point you can have multiple MQTT sensor subscribing to the topic, each of which picks out the data item of interest. I do this for

  • Maxim one-sided bus temperature sensors
  • Weather station
  • 32 channel power measurement

I like using MQTT as the integration technology because you can always just subsibe to the topic to see what’s going on for debugging.

I your case, I imagine there are tools or libraries around to parse the XML message and do stuff with the results that ultimately could be published to MQTT.

Home assistant can parse XML to json automatically since v0.106.0

As for the 255 character limit, store the result in an attribute. They are not limited to 255 chars like states are.

Then use template sensors to extract the values you want from the attribute.

That is what I was trying to do. I have this now:

- platform: rest
  name: windmill
    - response.productie.subseti[*].-period
    - response.productie.subseti[*].-sum
  value_template: "{{ response.productie['-actual'] }}"

This is supposed to give me all the -period and -sum values as attribute and the -actual as a state if I understand it correctly.
If I leave out the line with value_template I get a State max length is 255 characters. error. Unfortunately the above sensor is leaving me with no data at all. What am I doing wrong?

The xml converted to json looks like this:

  "response": {
    "productie": {
      "-molenid": "2",
      "-winddelen": "10154",
      "-actual": "2216012.0",
      "-factor": "0.989",
      "subset": [
          "-interval": "HOUR",
          "-period": "DAY",
          "-tstart": "2020-04-07 00:00:00",
          "-tend": "2020-04-07 23:59:00",
          "-sum": "430.2149999999999",
          "p": [
              "-dt": "2020-04-07 00:00:00",
              "-est": "1",
              "#text": "27.692"
...left out most for briefness...
              "-dt": "2020-01-01 00:00:00",
              "-est": "1",
              "-v": "0.26873573795790323",
              "-fc": "5077000.0",
              "#text": "2192443.25"



That is indeed a typo, or more like a vi usage error :frowning: good catch.

Anyway. Still no data. The state is shown as unknown for the sensor. If I change the last line from:

   value_template: "{{ response.productie['-actual'] }}"


    value_template: '{{ response.productie.-actual }}'

which should be the same for json, I get an error when I check my configuration file:
    - Invalid config for []: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['value_template']. Got '{{ response.productie.-actual }}'. (See ?, line ?).
    - platform: rest
      json_attributes: [source /home/homeassistant/.homeassistant/sensors.yaml:26]
        - response.productie.subset[*].-period
        - response.productie.subset[*].-sum
      name: windmill
      value_template: {{ response.productie.-actual }}

So I suspect HA or the templating has some difficulty with the - in the json attribute name. Any ideas?

The jinja2 template engine is probably parsing that ‘-’ character as a minus sign denoting subtraction.

Did you manage the connection with Winddelen? I would like to add this to my Home Assistant setup, but unfortunately I cannot find a lot if info about it. You are my only hope ':wink:

yes please see here: De Windcentrale