Help with creating RESTful sensor to parse energy rate XML file

The regulatory agency for my province publishes an XML file outlining the approved electricity rates for all suppliers as an XML file. I would like to be able to extra the 3 time-of-use rates for my supplier from this file. I consistently struggle with parsing XML and would appreciate any guidance.

The XML file can be found here: https://www.oeb.ca/_html/calculator/data/BillData.xml

This appears to describe a table, with each row being the information for each supplier. The supplier is defined by the <Dist></Dist> keys. The 3 rates I would like to capture for one specific supplier are under the RPPOffP, RPPMidP and RPPOnP keys.

I’ve hunted through the forums, but cannot figure out how to extra a specific “row”.

This is maybe not the most elegant solution, but it works. Just replace the supplier’s name with yours in each sensor.

rest:
  - resource: https://www.oeb.ca/_html/calculator/data/BillData.xml
    scan_interval: 600
    sensor:
      - name: RPPOffP
        value_template: >
          {% for row in value_json['BillDataTable']['BillDataRow'] %}
            {% if row['Dist'] == "Brantford Power Inc." %}
              {{ row['RPPOffP'] }}
            {% endif %}
          {% endfor %}
      - name: RPPMidP
        value_template: >
          {% for row in value_json['BillDataTable']['BillDataRow'] %}
            {% if row['Dist'] == "Brantford Power Inc." %}
              {{ row['RPPMidP'] }}
            {% endif %}
          {% endfor %}
      - name: RPPOnP
        value_template: >
          {% for row in value_json['BillDataTable']['BillDataRow'] %}
            {% if row['Dist'] == "Brantford Power Inc." %}
              {{ row['RPPOnP'] }}
            {% endif %}
          {% endfor %}
1 Like

Thank you!

1 Like