I’d like to add to this as the Tesco sensor last worked on 6th September.
The REST resource is https://www.tesco.com/fuel_prices/fuel_prices_data.json and my template is
value_template: "{% set station = value_json.stations | selectattr('site_id', 'eq', 'gcjcty9xrcsj') | first %}{{ '%.2f' | format(station.prices.B7 / 100) }}"
The logged error is “Template variable error: ‘value_json’ is undefined”
Nothing changed for me (no updates or reboots) when the error started appearing. I have since updated and rebooted, and the error persists.
Checking https://jsonlint.com/ the JSON Tesco is returning is actually valid.
ASDA/Sainsburys/Esso fuel price sensors are unaffected.
In Developer tools the template works as expected:
{% set value_json = {"last_updated": "17/09/2024 11:19:01", "stations": [{"site_id": "gcx1zhq978t7", "brand": "TESCO", "address": "Tesco Express Doncaster Road Brayton Selby", "postcode": "YO8 9EG", "location": {"latitude": 53.768681, "longitude": -1.089549}, "prices": {"E5": 141.9, "E10": 131.9, "B7": 138.9}}, {"site_id": "gcrjktx96h1j", "brand": "TESCO", "address": "Tesco Express Nuthall Road Nottingham", "postcode": "NG8 6AU", "location": {"latitude": 52.984551, "longitude": -1.198109}, "prices": {"E5": 136.9, "E10": 129.9, "B7": 135.9}} ... TRUCATED ...]} %}
{% set station = value_json.stations | selectattr('site_id', 'eq', 'gcjcty9xrcsj') | first %}{{ '%.2f' | format(station.prices.B7 / 100) }}
So, as koying says, the actual http call fails for whatever reason… how can I debug that reason and get to the bottom of this ‘value_json’ is undefined error?