GivEnergy and Polybar: Show stats from Solar array in my status bar

This was a quick fun hack to pull back the data from my solar inverter and display it in my status bar.

Here’s the code

view raw Readme.md hosted with ❤ by GitHub
#!/usr/bin/env python3
import datetime
from givenergy_modbus.client import GivEnergyClient
from givenergy_modbus.model.plant import Plant
client = GivEnergyClient(host="")
p = Plant(number_batteries=1)
client.refresh_plant(p, full_refresh=True)
def format_color(color: str, text: str):
return "%{F" + color + "}" + text + "%{F-}"
def format_wattage(input: int):
if input > 1000:
return f"{input/1000}Kw"
return f"{input}w"
def format_icon(input: str):
return format_color("#F0C674", f" {input} ")
surplus = p.inverter.p_load_demand < (p.inverter.p_pv1 + p.inverter.p_pv2)
if surplus:
lightening_color = "#2d862d"
lightening_color = "#b30000"
output = format_color(lightening_color, "")
output += format_icon("") + format_wattage(p.inverter.p_load_demand)
output += format_icon("󰶛") + format_wattage(p.inverter.p_pv1 + p.inverter.p_pv2)
output += format_icon("") + str(p.inverter.battery_percent) + "%"
output += format_icon("") + format_wattage(p.inverter.p_grid_out)
except Exception as e:
print("Error talking to inverter")
view raw givenergy.py hosted with ❤ by GitHub
type = custom/script
exec = $HOME/.config/polybar/givenergy.py
interval = 60

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s