Skip to content

A demonstration of pulling data from a Tesla Powerwall and pushing it to New Relic

License

Notifications You must be signed in to change notification settings

eosborne-newrelic/pwmon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pwmon

pwmon.py is a quick and dirty python script to demonstrate how to pull information from the Tesla Powerwall API and push it up to New Relic. I use it on my home solar system. If you want to use the weather bits you need to create an account at openweathermap.org.

Contents

There are five files in this repo. The only one you need is pwmon.py.

The other four are to make it easy to run in a container. This is how I do it.

Dockerfile is the Dockerfile. Not much to say about this one.

Makefile is because I like shortcuts. make image and make container are the two rules you want.

env.list is the list of environment variables pwmon.py wants to see in order to run.
If you want to run pwmon.py from the CLI, one good trick is

export $(grep -v '^#' env.list | xargs)
pwmon.py

requirements.txt pulls in tenacity (a retry library - the Powerwall API has some atrociously low rate-limit), tesla_powerwall, and python-dotenv.

This code is licensed under Apache 2.0. Essentially - do what you want with it but neither I nor New Relic are to be held liable for it. This is hacked-together demo code and it works for me at home but that's as far as I've taken it.

Usage

From the CLI

eosborne@host pwmon % export $(grep -v '^#' env.list | xargs)
eosborne@host pwmon % ./pwmon.py
submitted at 2022-01-11 08:57:20.332818 return code 0
{'common': {'attributes': {'app.name': 'solar',
                           'mode': 'Self_Consumption',
                           'poll_timestamp': 1641909439380,
                           'status': 'Connected'},
...

From Docker

Build the image:

eosborne@host:~/prog/pwmon$ make image
.....
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
pwmon        latest    de412555d252   17 hours ago 277MB                                                                                                                                      

Start a container:

eosborne@host:~/prog/pwmon$ make container
docker run -d --restart unless-stopped --name pwmon --env-file env.list pwmon
974d312084d6ab79b65813dc485d18f3a110bcadc73967480b9273d9eadf3da5

Check that it works (you get one log line per minute):

eosborne@host:~/prog/pwmon$ docker logs pwmon
submitted at 2022-01-11 14:00:42.418491 return code 0

Getting data from New Relic

There's a lot you can do once your data is in New Relic. Like, a lot. One sample query to get you started:

FROM Metric SELECT average(solar.battery_charge_pct) TIMESERIES SINCE 1 week ago

which looks like this: battery charge query

About

A demonstration of pulling data from a Tesla Powerwall and pushing it to New Relic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published