RESTful and XML Integration for multiple sensors

Hi all, I’ve been trying for days to extract data from an XML to create sensors but with no success.

I am attaching the XML code:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<index_refresh>
<system>
<ip_address>192.168.40.250</ip_address>
<date>18/12/2022</date>
<time>22:38</time>
<hp_season>0</hp_season>
<hp_mode>2</hp_mode>
</system>
<zone>
<idx>0</idx>
<name>Zona Giorno</name>
<type>7</type>
<temp_op>22.5</temp_op>
<hum>52.5</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_grey</term_on_classname>
<hum_on_classname>icon deum_grey_off</hum_on_classname>
<renew_on_classname>icon refresh_grey_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=0</link>
</zone>
<zone>
<idx>1</idx>
<name>Camera Matrimoniale</name>
<type>7</type>
<temp_op>21.5</temp_op>
<hum>50.9</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_red</term_on_classname>
<hum_on_classname>icon deum_grey_off</hum_on_classname>
<renew_on_classname>icon refresh_grey_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=1</link>
</zone>
<zone>
<idx>2</idx>
<name>Cabina Armadio</name>
<type>7</type>
<temp_op>21.1</temp_op>
<hum>50.0</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_red</term_on_classname>
<hum_on_classname>icon deum_grey_off</hum_on_classname>
<renew_on_classname>icon refresh_grey_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=2</link>
</zone>
<zone>
<idx>3</idx>
<name>Cameretta</name>
<type>7</type>
<temp_op>21.2</temp_op>
<hum>48.8</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_red</term_on_classname>
<hum_on_classname>icon deum_grey_off</hum_on_classname>
<renew_on_classname>icon refresh_grey_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=3</link>
</zone>
<zone>
<idx>4</idx>
<name>Bagno PT</name>
<type>9</type>
<temp_op>20.4</temp_op>
<hum>--.-</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_red</term_on_classname>
<hum_on_classname>icon deum_white_off</hum_on_classname>
<renew_on_classname>icon refresh_white_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=4</link>
</zone>
<zone>
<idx>5</idx>
<name>Bagno P1</name>
<type>9</type>
<temp_op>21.4</temp_op>
<hum>--.-</hum>
<radzone>1</radzone><status>1</status>
<term_on_classname>icon radiator_red</term_on_classname>
<hum_on_classname>icon deum_white_off</hum_on_classname>
<renew_on_classname>icon refresh_white_off</renew_on_classname>
<alarm_classname>icon alarm_grey_off</alarm_classname>
<link>/zone.php?ids=5</link>
</zone>
</index_refresh>

I would like to extract the 6 temprature data (temp_op)

Thanks in advance to whoever will help me Text

Post what you’ve tried and what went wrong. People will better understand your situation and may be reluctant to help with just “do it for me”.

rest:
  - resource: http://192.168.1.12/status.xml ### <--- Your resource here, auth too if you need it
    sensor:
      - name: "Zona Giorno Temperature"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
        value_template: "{{ value_json.zone[0].temp_op }}"

      - name: "Camera Matrimoniale Temperature"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
        value_template: "{{ value_json.zone[1].temp_op }}"

      - name: "Cabina Armadio Temperature"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
        value_template: "{{ value_json.zone[2].temp_op }}"

...etc
1 Like

I’m sorry but it’s the first time I’ve written and I didn’t think to put what I tried.
I did some tests with both the Scrape method and the Rest method.
With the Scrape method the sensor is not created and I think it is because it cannot read any data.
With the Rest method the sensor is created but always returns the unknown value.

I tried the solution you told me by inserting my link for resources but I always get unknown sensor value.
You indicated as resourse http://192.168.xx.xx/status.xml but my link where I get the data is http://192.168.xx.xx/index_refresh.php.
The code that I have indicated above I have transformed online from XML to JSON.