AC Battery / Solar PV Status

DRAX UK Grid Status:  Status

Air Pollution:  Get a reading

AC Battery Status

Solar Generation Status

Example Python Script to read GivEnergy Battery Information:

Note: you need to add 2-spaces before each line under a function
import network
import urequests

def do_connect():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print(‘connecting to network…’)
wlan.connect(‘your SSID’, ‘your PASSWORD’)
while not wlan.isconnected():
pass
print(‘network config:’, wlan.ifconfig())

do_connect()

url = ‘https://api.givenergy.cloud/v1/inverter/<your Invert Serial Number>/system-data/latest’
payload = “{‘inverter_serials’: [‘<your Inverter Serial Number>’], ‘setting_id’: 17}”
headers = {
‘Authorization’: ‘Bearer <your API key>’,
‘Content-Type’ : ‘application/json’,
‘Accept’ : ‘application/json’
}

response = urequests.get(url, data = payload, headers = headers)

if response.status_code == 200:
print(response.json())

soc = response.json()[‘data’][‘battery’][‘percent’]
Inverter = response.json()[‘data’][‘inverter’][‘power’] / 1000
if (soc == 100):
Mode = “(Full)”
elif (Inverter < 0):
Mode = “(Charging)”
else:
Mode = “(Discharging)”

Consumption = response.json()[‘data’][‘consumption’] / 1000
solarCharge = response.json()[‘data’][‘solar’][‘power’] / 1000

print (“SoC = “, soc, “%”)
print (“Inverter = “, Inverter, “kW “, Mode)
print (“Consumption = “, Consumption, “kW “)
print (“Solar Charge Rate = “, solarCharge, “kW “)

Typical response:
{‘data’: {‘inverter’: {‘output_voltage’: 241.3, ‘power’: 118, ‘output_frequency’: 49.92, ‘eps_power’: 0, ‘temperature’: 34.1}, ‘consumption’: 386, ‘solar’: {‘power’: 262, ‘arrays’: [{‘array’: 1, ‘current’: 1, ‘power’: 262, ‘voltage’: 240.2}, {‘array’: 2, ‘current’: 0, ‘power’: 0, ‘voltage’: 0}]}, ‘battery’: {‘temperature’: 22, ‘percent’: 23, ‘power’: 143}, ‘time’: ‘2022-06-18T11:28:31Z’, ‘grid’: {‘current’: 0.6, ‘frequency’: 49.95, ‘power’: -5, ‘voltage’: 242.7}}}
Formated:
{
“data”: {
“time”: “2022-06-15T20:59:53Z”,
“solar”: {
“power”: 6,
“arrays”: [
{
“array”: 1,
“voltage”: 245.4,
“current”: 0,
“power”: 6
},
{
“array”: 2,
“voltage”: 0,
“current”: 0,
“power”: 0
}
]
},
“grid”: {
“voltage”: 247.7,
“current”: 1.7,
“power”: 12,
“frequency”: 50.03
},
“battery”: {
“percent”: 68,
“power”: 486,
“temperature”: 22
},
“inverter”: {
“temperature”: 38.1,
“power”: 437,
“output_voltage”: 246.8,
“output_frequency”: 50.02,
“eps_power”: 0
},
“consumption”: 431
}
}

Micropython to Access GivEnergy Battery and display on ILI9341

import network
import urequests
import time
import ntptime
from ili9341 import Display, color565
from machine import Pin, SPI
from xglcd_font import XglcdFont
ntptime.host = “uk.pool.ntp.org”

def startWiFi():
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print(‘connecting to network…’)
wlan.connect(‘SSID’, ‘PASSWORD’)
while not wlan.isconnected():
pass
print(‘network config:’, wlan.ifconfig())

#Wiring for a standard SPI connection
#EPD_BUSY = 4; // to EPD BUSY
#EPD_CS = 5; // to EPD CS
#EPD_RST = 16; // to EPD RST
#EPD_DC = 17; // to EPD DC
#EPD_SCK = 18; // to EPD CLK
#EPD_MISO = 19; // Master-In Slave-Out not used, as no data from display
#EPD_MOSI = 23; // to EPD DIN

#define TFT_CS 14 //for D32 Pro
#define TFT_RST 33 //for D32 Pro
#define TFT_DC 27 //for D32 Pro
#define TS_CS 12 //for D32 Pro
#define MOSI 23 //for D32 Pro
#define MISO 19 //for D32 Pro
#define SCK 18 //for D32 Pro

def startDisplay():
global spi
spi = SPI(2, baudrate=40000000, sck=Pin(18), mosi=Pin(23))
global display
display = Display(spi, dc=Pin(27), cs=Pin(14), rst=Pin(33), width=320, height=240, rotation=90)
print(‘Loading fonts…’)
#print(‘Loading arcadepix’)
#global arcadepix
#arcadepix = XglcdFont(‘fonts/ArcadePix9x11.c’, 9, 11)
#print(‘Loading bally’)
#global bally
#bally = XglcdFont(‘fonts/Bally7x9.c’, 7, 9)
#print(‘Loading broadway’)
#global broadway
#broadway = XglcdFont(‘fonts/Broadway17x15.c’, 17, 15)
print(‘Loading espresso_dolce’)
global espresso_dolce
espresso_dolce = XglcdFont(‘fonts/EspressoDolce18x24.c’, 18, 24)
#print(‘Loading fixed_font’)
#global fixed_font
#fixed_font = XglcdFont(‘fonts/FixedFont5x8.c’, 5, 8)
#print(‘Loading neato’)
#global neato
#neato = XglcdFont(‘fonts/Neato5x7.c’, 5, 7, letter_count=223)
#print(‘Loading robotron’)
#global robotron
#robotron = XglcdFont(‘fonts/Robotron13x21.c’, 13, 21)
#print(‘Loading unispace’)
#global unispace
#unispace = XglcdFont(‘fonts/Unispace12x24.c’, 12, 24)
#print(‘Loading wendy’)
#global wendy
#wendy = XglcdFont(‘fonts/Wendy7x8.c’, 7, 8)
print(‘Fonts loaded.’)

#Define addresses for data and credentials
url = ‘https://api.givenergy.cloud/v1/inverter//system-data/latest’
payload = “{‘inverter_serials’: [‘<your Inverter Serial Number>’], ‘setting_id’: 17}”
headers = {
‘Authorization’: ‘Bearer <API KEY>’,
‘Content-Type’ : ‘application/json’,
‘Accept’ : ‘application/json’
}

def getData():
response = urequests.get(url, data = payload, headers = headers)
print (response.text)

if response.status_code == 200:
print(response.json())

soc = response.json()[‘data’][‘battery’][‘percent’]
batteryPower = response.json()[‘data’][‘battery’][‘power’] / 1000
Inverter = response.json()[‘data’][‘inverter’][‘power’] / 1000
if (batteryPower < 0.01):
BMode = “(Charging)”
else:
BMode = “(Discharging)”

if (soc == 100):
IMode = “(Full)”
elif (Inverter < 0.001):
IMode = “(Charging)”
else:
IMode = “(Discharging)”

Consumption = response.json()[‘data’][‘consumption’] / 1000
SolarCharge = response.json()[‘data’][‘solar’][‘power’] / 1000

print (“SoC = “, “{:.0f}”.format(soc), “%”)
print (“Battery = “, “{:.2f}”.format(batteryPower), “kW “, BMode)
print (“Inverter = “, “{:.2f}”.format(Inverter), “kW “, IMode)
print (“Consumption = “, “{:.2f}”.format(Consumption), “kW “)
print (“Solar Charge Rate = “, “{:.2f}”.format(SolarCharge), “kW “)

display.draw_text(40, 100, “State of charge = ” + str(soc) + “%”, espresso_dolce,
color565(225, 0, 128))

startWiFi() # Start WiFi
startDisplay() # Start Display

while True:
getData()
ntptime.settime()
year, month, day, hour, mins, secs, weekday, yearday = time.localtime()
# Print a date – YYYY-MM-DD
print(“{}-{:02d}-{:02d}”.format(year, month, day))
# Set a variable to a date
Time = “{}:{:02d}:{:02d}”.format(hour+1, mins, secs)
print(time)
display.draw_text(90, 130, “Time = ” + Time, espresso_dolce,
color565(225, 128, 128))
time.sleep(60)

TOP_IMG