@petro Can you help us out here?
There’s nothing changed on the code, but still it doesn’t work and can’t figure out why. This is the converted XML to JSON coming back from the inverter and put it in the template editor. It throws the exact same error as I see in the log files:
UndefinedError: ‘None’ has no attribute 'Device’
{## Imitate available variables: ##}
{% set my_test_json = {
"root": {
"Device": {
"Measurements": {
"Measurement": [
{
"_Value": "228.8",
"_Unit": "V",
"_Type": "AC_Voltage"
},
{
"_Value": "1.832",
"_Unit": "A",
"_Type": "AC_Current"
},
{
"_Value": "403.4",
"_Unit": "W",
"_Type": "AC_Power"
},
{
"_Value": "49.977",
"_Unit": "Hz",
"_Type": "AC_Frequency"
},
{
"_Value": "415.2",
"_Unit": "V",
"_Type": "DC_Voltage"
},
{
"_Value": "0.975",
"_Unit": "A",
"_Type": "DC_Current"
},
{
"_Value": "39.1",
"_Unit": "°C",
"_Type": "Temp"
},
{
"_Unit": "V",
"_Type": "LINK_Voltage"
},
{
"_Unit": "W",
"_Type": "GridPower"
},
{
"_Unit": "W",
"_Type": "GridConsumedPower"
},
{
"_Unit": "W",
"_Type": "GridInjectedPower"
},
{
"_Unit": "W",
"_Type": "OwnConsumedPower"
},
{
"_Value": "100.0",
"_Unit": "%",
"_Type": "Derating"
}
]
},
"_Name": "StecaGrid 3600x",
"_NominalPower": "3680",
"_Type": "Inverter",
"_Serial": "xxxxx",
"_BusAddress": "1",
"_NetBiosName": "xxxxx",
"_IpAddress": "xxxxx",
"_DateTime": "2021-06-21T18:23:19"
}
}
} %}
{% set root = state_attr('my_test_json', 'root') %}
{{ (root.Device.Measurements.Measurement[2]["@Value"] | float / 1000) }}
And this is the logging from homeassistant logbook:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 389, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1358, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 326, in getattr
value = getattr(obj, attribute)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1382, in _fail_with_undefined_error
raise ex
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1374, in _fail_with_undefined_error
return super()._fail_with_undefined_error(*args, **kwargs)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'Device'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 505, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 391, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'Device'