Skip to content
View in the app

A better way to browse. Learn more.

Power Forum - Renewable Energy Discussion

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Loadshedding - Simple Python Script To Influxdb for Grafana

Featured Replies

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.

grafana-dashboard-growatt-spf5000es-loadshedding-added-grafana-settings-1.thumb.jpg.46376733e6584eeafcf6d95199c8995a.jpg

End result :)

grafana-dashboard-growatt-spf5000es-loadshedding-added.thumb.jpg.93c67e984511c7f2f2c4b8b7d406b8ec.jpg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.