Skip to content

Instantly share code, notes, and snippets.

@emresaglam
Created April 14, 2018 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emresaglam/d1e03f6c9ed0d59b2654b2a6ade31c4e to your computer and use it in GitHub Desktop.
Save emresaglam/d1e03f6c9ed0d59b2654b2a6ade31c4e to your computer and use it in GitHub Desktop.
Script to poll the home assistant database running on PostgreSQL. The only requirement is psycopg2. (The script doesn't do any error/exception handling)
import psycopg2
# The name of the home assistant database
DB = "<DBNAME>"
# The user to connect to your home assistant database
DBUSER = "<DBUSER>"
# The IP/hostname of the PostgreSQL server
DBHOST = "<DBHOST>"
# The password for the user
DBPASSWORD = "<DBPASSWORD>"
props = "dbname='{}' user='{}' host='{}' password='{}'".format(DB, DBUSER, DBHOST, DBPASSWORD)
conn = psycopg2.connect(props)
cur = conn.cursor()
sizecmd = "select pg_database_size('{}');".format(DB)
cur.execute(sizecmd)
rows = cur.fetchall()
print (rows[0][0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment