Duke Energy Usage

Hello everyone! I have been working on a new sensor component for Duke Energy electric and gas usage. This collects data from Duke Energy smart meters using their API (undocumented/unofficial) you have to have a smart meter and be able to access that data online (Takes several weeks after it is installed)

There have been a couple users testing this out and they have had good results, would like to open this up to more testers and see if we can work out any more issue before I make an official Home Assistant component for it.

If you would like to test, follow the steps below.

Inside of your configuration director create the following path/file custom_components/sensor/duke_energy.py and populate the file with https://hastebin.com/niwihutolo.py

Add the following to your config

sensor:
  - platform: duke_energy
    username: YOUR_DUKE_USERNAME
    password: YOUR_DUKE_PASSWORD

Restart, and you should get a sensor named (sensor.duke_energy_METER_ID) which is the energy usage form yesterday. It also has the following attributes

lastBillsUsage (Total usage from last bill)
lastBillsAverageUsage (Average daily usage from the last bill)
lastBillsDaysBilled (Total number of days billed)

Unfortunately Duke doesn’t offer current day usage so this is the best that is available at the moment.

2 Likes

I don’t have my smart meter yet, but I’m using HASS and found this thread while looking for something just like this. This sounds brilliant. Thanks for working on this! When my smart meter gets installed, I’ll give this a go.

1 Like

Should be in the next release (probably in beta now)

1 Like

I have been getting this error since the update allowed Duke energy ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform duke_energy

I have also tried your custom components and still nothing. here is the log for the custom component
File "/config/custom_components/sensor/duke_energy.py", line 37, in setup_platform meters = duke.get_meters() File "/usr/local/lib/python3.6/site-packages/pydukeenergy/api.py", line 52, in get_meters self._get_meters() File "/usr/local/lib/python3.6/site-packages/pydukeenergy/api.py", line 160, in _get_meters meter_data = json.loads(soup.find("duke-dropdown", {"id": "usageAnalysisMeter"})["items"]) TypeError: 'NoneType' object is not subscriptable 2018-08-12 11:36:18 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (sqlite3.DatabaseError) database disk image is malformed [SQL: 'INSERT INTO events (event_type, event_data, origin, time_fired, created) VALUES (?, ?, ?, ?, ?)'] [parameters: ('component_loaded', {"component": "switch"}', 'LOCAL', '2018-08-12 15:35:26.745631', '2018-08-12 15:36:18.805151')] (Background on this error at: http://sqlalche.me/e/4xp6)

One of your error is a database error, I think it might be corrupt. The Duke energy error looks like something might have changed, can you enable debug logs and try again? Is it possible your username/password are incorrect?

Username and password is correct. nothing is showing in the log since i removed the custom component.

Can you delete the deps directory in your config folder and restart? It should try to redownload all of the libraries again.

did that, this is what i am getting now

2018-08-12 12:48:07 WARNING (MainThread) [homeassistant.components.http] You have been advised to 
set http.api_password.
2018-08-12 12:48:25 WARNING (MainThread) [homeassistant.setup] Setup of config is taking over 10 
seconds.
2018-08-12 12:48:29 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up 
platform duke_energy
Traceback (most recent call last):
 File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 129, in 
_async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/duke_energy.py", line 42, in 
setup_platform
add_devices([DukeEnergyMeter(meter) for meter in duke.get_meters()])
File "/usr/local/lib/python3.6/site-packages/pydukeenergy/api.py", line 52, in get_meters
self._get_meters()
File "/usr/local/lib/python3.6/site-packages/pydukeenergy/api.py", line 160, in _get_meters
meter_data = json.loads(soup.find("duke-dropdown", {"id": "usageAnalysisMeter"})["items"])
TypeError: 'NoneType' object is not subscriptable

And you have added this to your config?

logger:
  default: info
  logs:
      pydukeenergy.api: debug

So I noticed that my duke energy usage sensor stopped working. Looks like the usage page is now missing in my account. Is anyone else seeing the same thing?

Is this working again?

Not for me :frowning:

I was able to get this working but I do not know how to intergrate it into home assistant. If someone is willing to help me let me know.

You can see the python fork of pydukeenergy here: https://github.com/d4yz/pydukeenergy

This was part of home assistant awhile back, it was removed early last year.

You can take a look at the Home Assistant source code here.

dig in to homeassistant/components/duke_energy to see whats going on. Might not need to make many tweaks.

To get it really added to Home Assistant you are either going to need to open a PR to my pydukeenergy project so I can push it to pypi or you would need to make you own library and push it up so Home Assistant can download it during startup.

One think to think about, the previous version used beautiful soup to grab the meter ID if it is still doing that the HA devs do not officially allow web scraping so it won’t be allowed back in.

Here is a link to the PR that removed it that might help too.

Definitely disappointing that Duke Energy doesn’t allow access via an API so this integration can be implemented properly.

If anyone spins this up in a custom integration, I would love to help test. Unfortunately I have not had time to learn enough python to try and implement it myself.

1 Like