Hello,
I wanted to extract a value from a json file.
My Problem is, one object is the UNIX timestamp.
When I want to select this object, HA Dev tools says: UndefinedError: dict object has no element…
{% set value_json = {"data":{"1675765800":{"11":{"val":"1037"},"20":{"val":"0.8"}}}} %}
{{ value_json.data.1675765800}}
Ive tried single or double quotes and curly braces,
I need the value of 11 and 20
It works, when I change the numbers to a word
Thank you in advance!
It works when I enter the exact text string “16576580”
but how to do it if I want to choose the first object. At the moment Im calculating this number from the epochtime-1 hour, this works. But if I want to simplify it, I call it data[0][“11”].val and this doesnt work.
Thank you!
Thank you!
this works, in dev template.
But in the configuration.yaml theres a error
rest:
- resource_template: html
sensor:
- name: Temperatur
value_template: >-
{% set kass = value_json.data.keys() | list %}
{% value_json.data[kass[0]]["20"].val %}
device_class: temperature
unit_of_measurement: "°C"
Invalid config for [rest]: invalid template (TemplateSyntaxError:
Encountered unknown tag 'value_json'.) for dictionary value @ data['rest'][0]['sensor'][0]['value_template'].
Got '{% set kass = value_json.data.keys() | list %} {% value_json.data[kass[0]]["20"].val %}'.
How do I put it in the configuration.yaml?
Ive found nothing about this list filter with rest and home asisstant somewhere else
value_template: >-
{% set kass = value_json.data.keys() | list %}
{{ value_json.data[kass[0]]["20"].val }}
Wrong bracket structure on the second line. Your indentation is wrong across the first three lines posted above, but I assume that’s just an editing error when you took out the URL? sensor: needs to be one more space over.
Thank you very much!
It seems to work with those two brackets.
Im happy that it works, but a bit disappointed cause it took very long to find all the error.