WannabeSolarSparky Posted October 8, 2021 Share Posted October 8, 2021 Very Simple Python script to send loadshedding status to influxdb for use in grafana on raspberry pi Tip: If not already installed add the nano editor to your system, its just easier to use Now Create file called loadsheddingcheck.py You can do this i your home directory or anywhere you like to load your scripts, just be sure to change/edit the cron according to your preference. touch loadsheddingcheck.py Then sudo nano loadsheddingcheck.py Add (copy paste) the following code to the file and save (ctrl x y) from urllib.request import urlopen import json from influxdb import InfluxDBClient import datetime url = "https://loadshedding.eskom.co.za/LoadShedding/GetStatus" response = urlopen(url) data_json = json.loads(response.read()) print(data_json) theLoadsheddingChecker = [{"measurement":"Loadshedding", "tags": { "Country": "South Africa", "Utility": "Eskom" }, "fields": { "Stage":data_json } } ] influxdbClient = InfluxDBClient( host = 'HOST', port = PORT, username = 'INFLUXUSERNAME', password = 'INFLUXPASSWORD', database = 'INFLUXDATABASENAME' ) influxdbClient.write_points(theLoadsheddingChecker) Then add a cron to run every 30 minutes to check loadshedding status (or whichever check interval you prefer open cron editor (will ask which editor, use nano as its the easiest) crontab -e Then add the following line to the bottom at the last open line and edit to suit your requirements (the example below is for every hour). * */1 * * * /usr/bin/env python3 /home/pi/loadsheddingcheck.py > /home/pi/loadsheddingcheck.log 2>&1 ctrl x y to save Now in grafana add a Stat card and edit the settings and add some value mappings to show the correct stages. End result Proxicon, Durran and LumexClipsal 1 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.