Have a device that puts out climate measurements as an XML file. I’m trying to extract the Temperature (C) value only. So far, I have not been able to correctly parse this using the RESTful sensor.
Original XML
<devices>
<device id="XXXXXXXX" name="Climate Monitor" type="server" available="1" index="0">
<field key="TempC" value="30.88" niceName="Temperature (C)" min="-20" max="50" type="2"/>
<field key="TempF" value="87.58" niceName="Temperature (F)" min="-4" max="122" type="2"/>
<field key="Humidity" value="40.00" niceName="Relative Humidity" min="0" max="99" type="2"/>
<field key="Airflow" value="2.20" niceName="Air Flow" min="0" max="100" type="2"/>
<field key="Light" value="1.00" niceName="Light Level" min="1" max="99" type="2"/>
<field key="Sound" value="1.00" niceName="Sound Level" min="0" max="99" type="2"/>
<field key="IO1" value="99.00" niceName="IO-1" min="0" max="99" type="2"/>
<field key="IO2" value="99.00" niceName="IO-2" min="0" max="99" type="2"/>
<field key="IO3" value="99.00" niceName="IO-3" min="0" max="99" type="2"/>
</device>
</devices>
XML Converted to JSON
{
"devices": {
"device": {
"field": [
{
"_key": "TempC",
"_value": "30.88",
"_niceName": "Temperature (C)",
"_min": "-20",
"_max": "50",
"_type": "2"
},
{
"_key": "TempF",
"_value": "87.58",
"_niceName": "Temperature (F)",
"_min": "-4",
"_max": "122",
"_type": "2"
},
{
"_key": "Humidity",
"_value": "40.00",
"_niceName": "Relative Humidity",
"_min": "0",
"_max": "99",
"_type": "2"
},
{
"_key": "Airflow",
"_value": "2.20",
"_niceName": "Air Flow",
"_min": "0",
"_max": "100",
"_type": "2"
},
{
"_key": "Light",
"_value": "1.00",
"_niceName": "Light Level",
"_min": "1",
"_max": "99",
"_type": "2"
},
{
"_key": "Sound",
"_value": "1.00",
"_niceName": "Sound Level",
"_min": "0",
"_max": "99",
"_type": "2"
},
{
"_key": "IO1",
"_value": "99.00",
"_niceName": "IO-1",
"_min": "0",
"_max": "99",
"_type": "2"
},
{
"_key": "IO2",
"_value": "99.00",
"_niceName": "IO-2",
"_min": "0",
"_max": "99",
"_type": "2"
},
{
"_key": "IO3",
"_value": "99.00",
"_niceName": "IO-3",
"_min": "0",
"_max": "99",
"_type": "2"
}
],
"_id": "XXXXXXXXXXXXXX",
"_name": "Climate Monitor",
"_type": "Server",
"_available": "1",
"_index": "0"
}
}
}
REST API config
rest:
- scan_interval: 20
resource: "http://xxx.xxx.xxx.xxx/data.xml"
sensor:
- name: "Temperature"
unique_id: "Server Temperature"
state_class: measurement
unit_of_measurement: "°C"
value_template: "{{ value_json.devices.device.field[0]._value }}"
json_attributes:
- Value
Have also tried using value_template: “{{ value_json[‘devices’][‘device’][‘field0’][‘_value’] }}” without success.
Edit: HomeAssistant and the device have connectivity. HomeAssistant can retrieve the XML file from terminal using curl without issue.