If this is of any use (because the above website seems to have stopped working):
command_line:
- sensor:
command: >-
curl "https://data.nationalgas.com/api/find-gas-data-download?applicableFor=Y&dateFrom={{now().strftime('%Y-%m-%dT00:00:00')}}&dateTo={{now().strftime('%Y-%m-%dT23:59:59')}}&ids=PUBOB4515&latestFlag=Y&type=CSV&dateType=GASDAY" -s
| python3 /config/my_python_scripts/csv2json.py
name: Gas Calorific Value
unique_id: calorific_value_SO
unit_of_measurement: "MJ/m³"
scan_interval: 86400
value_template: '{{ value_json["Value"]}}'
json_attributes:
- Generated Time
- Data Item
need to have an additional python script (in my example, named csv2json.py
)
# convert csv to json
# https://blog.backslasher.net/python-csv-to-json.html
import csv
import sys
import json
csv.field_size_limit(sys.maxsize)
for row in csv.DictReader(sys.stdin):
sys.stdout.write(json.dumps(row)+"\n")
Same challenges of couse, of determining your local area.