Hello everyone,
I am rather new to Home Assistant, and have a problem configuring one sensor (all others work fine). I have a RESTful server running on a raspi, which returns XML data for an MBus device. I can see that Home Assistant can retrieve the XML by setting
# Grundwasserzaehler
- platform: rest
resource: http://raspberrypi.home:8080/mbus/get/ttyAMA0/2400/0
method: POST
name: "Grundwasserzaehler"
value_template: "{{ value|truncate(50) }}"
scan_interval: 600
Then the sensor contains the first 50 characters of the XML response and they look correct. If instead I try to extract something from the parsed json with
# Grundwasserzaehler
- platform: rest
resource: same as above
method: POST
name: "Grundwasserzaehler"
value_template: "{{ value_json.MBusData.SlaveInformation.Id }}"
scan_interval: 600
I get an âunkownâ value and the following log entry:
âTemplate variable error: âvalue_jsonâ is undefined when rendering '{{
value_json.MBusData.SlaveInformation.Id }}â.
If, instead, I try to access attributes using
# Grundwasserzaehler
- platform: rest
resource: same as above
method: POST
name: "Grundwasserzaehler"
json_attributes_path: $.MBusData.SlaveInformation
value_template: "OK"
json_attributes:
- Id
- Version
scan_interval: 600
I get a log entry âREST result could not be parsed as JSONâ
In a python script the XML gets parsed completely fine, see below. If I try the recommended online tool at xmltodict-debugger.glitch.me it looks a bit different. Iâd be happy to post the XML and JSON samples but the community forum wonât let new users post more than two links. I think it is confused with the XML, even when using code backticks.
I am really at a loss. Short of writing my own RESTful server that delivers JSON instead of XML I really donât know what to do. So any help would be appreciated. I am not sure what Home Assistant does differently. Sorry for the very long post, any response is really appreciated.
Best,
Gregor