Hi,
I am trying to retrieve values of gas consuption from a JSON wich is daily updated by pulling data from the gas provider to update a new sensor with long term statistic to feed the Energy dashboard.
The Json file seems to be correctly structured:
{"29/09/2021": {"kwh": 1, "mcube": 0.17}, "30/09/2021": {"kwh": 4, "mcube": 0.39}, "01/10/2021": {"kwh": 0, "mcube": 0.0}, "02/10/2021": {"kwh": 3, "mcube": 0.33}, "03/10/2021": {"kwh": 4, "mcube": 0.39}, "04/10/2021": {"kwh": 1, "mcube": 0.17}, "05/10/2021": {"kwh": 4, "mcube": 0.41}, "06/10/2021": {"kwh": 8, "mcube": 0.73}, "07/10/2021": {"kwh": 3, "mcube": 0.33}, "08/10/2021": {"kwh": 3, "mcube": 0.27}, "09/10/2021": {"kwh": 0, "mcube": 0.05}, "10/10/2021": {"kwh": 2, "mcube": 0.18}}
With an online json parser we can find the structure where each date is composed by sub values “kwh” and “mcube”.
I want to extract the value from the last day (more recent) and store it in a sensor for all this day, then the sensor will be updated each day at 7pm with the new (yesterday) value from the JSON of the day. I dont know yet how to deal with this 24h shift on the sensor timeline.
I had trying someting like:
- platform: file
sensor:
name: gas daily consuption
file_path: /config/gazpar/conso_par_jour.json
value_template: "{{ value_json.29/09/2021.mcube | float }}"
unit_of_measurement: 'm³'
state_class: "measurement"
device_class: "gas"
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
Where ‘29/09/2021’ must be called dynamically with the current date.
I have done some research but dit not find how to deal with JSON structure.
Thanks a lot for your help,
Regards