I am very new to Home Assistant and are struggling with coding in jinja / home assistant.
OK, anyway, I am trying to iterate over a json file that contains an object of date-stamps YYYYMMDD each with an array that determines the types for that day.
This is actually a bin collection schedule, and on certain days, certain types of rubbish will be collected, here’s what I have:
This is an extract of the json file:
{
"20220509": [ "GARDEN" ],
"20220514": [ "RECYCLING", "REFUSE" ],
"20220519": [ "RECYCLING" ],
"20220523": [ "GARDEN" ]
}
And this is my sensor code:
- platform: file
name: Bin Collection
file_path: /config/bins.json
value_template: >-
{% for i in value_json %}
{% if value_json[i] == now().strftime('%Y%m%d') %}
{% for t in value_json[i] %}
value_json[i][t]
{% endfor %}
{% endif %}
{% endfor %}
What I am expecting is that if the YYYYMMDD matches today’s date, then the types of collection will be outputted as the sensor state.
Is my approach correct ? - I have not found any examples that do a similar thing to what I am trying to achieve.
Any help would be appreciated