sense_api
Sense Energy Monitor API Interface
The Sense API provides access to the unofficial API for the Sense Energy Monitor. Through the API, one can retrieve both realtime and trend data including individual devices.
Systematic access to the Sense monitor data. Exploratory work on pulling data from Sense to be used in other tools - HomeASsistant, Smartthings, ActiveTiles, etc.
Python version based on the work done here in Powershell: https://gist.github.com/mbrownnycnyc/db3209a1045746f5e287ea6b6631e19c
Local Device Emulation
The SenseLink class emulates the energy monitoring functionality of TP-Link Kasa HS110 Smart Plugs and allows you to report "custom" power usage to your Sense Home Energy Monitor. This requires enabling "TP-Link HS110/HS300 Smart Plug" in the Sense app.
Based off the work of https://github.com/cbpowell/SenseLink
Contributors
Feel free to fork and PR!
Todo
- Add POST/PUT where/if applicable
- CLI
- Improved error handling
Install
pip install sense_energy
Web API Example Usage:
from sense_energy import Senseable
sense = Senseable()
sense.authenticate(username, password)
sense.update_realtime()
sense.update_trend_data()
print ("Active:", sense.active_power, "W")
print ("Active Solar:", sense.active_solar_power, "W")
print ("Daily:", sense.daily_usage, "KWh")
print ("Daily Solar:", sense.daily_production, "KWh")
print ("Active Devices:",", ".join(sense.active_devices))
There are plenty of methods for you to call so modify however you see fit
If using the API to log data, you should only create one instance of Senseable and
then reuse that to get the updated stats. Creating the instance authenticates
with the Sense API which should only be once every 15-20 minutes at most.
Calling the update_trend_data() function will update all the trend stats
and get_realtime() will retrieve the latest real time stats.
update_trend_data() covers the period scales in TREND_SCALES (Scale.DAY,
Scale.WEEK, Scale.MONTH, Scale.YEAR, Scale.CYCLE). Scale.HOUR is not one of
them — fetch any single hour explicitly:
from datetime import datetime, timedelta, timezone
from sense_energy import Scale
hour = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0) - timedelta(hours=1)
sense.get_trend_data(Scale.HOUR, hour)
print("Hourly:", sense.get_stat(Scale.HOUR, "usage"), "KWh")
print("For hour starting:", sense.trend_start(Scale.HOUR))
for device in sense.devices:
print(device.name, device.energy_kwh[Scale.HOUR], "KWh")
Each call replaces the stored hour, and trend_start(Scale.HOUR) says which hour it
describes — check it, since a request outside the day returned leaves the previous hour
in place. Usage, per-device energy and production are exact; from_grid and to_grid are
approximated from the hourly net, rescaled so the day matches the API's exact totals.
Hours may be fetched in any order, not just ascending/completed ones.
You can also fetch the current, in-progress hour — its values are partial and to-date, growing until the hour ends:
sense.get_trend_data(Scale.HOUR, datetime.now(timezone.utc))
Check whether the stored hour is still in progress with
sense.trend_start(Scale.HOUR) + timedelta(hours=1) > datetime.now(timezone.utc).
start is read by the API as UTC. Offset-aware datetimes are converted; naive ones are
sent as given.
The get_realtime() is by default rate limited to one call per 30 seconds. This can
be modified by setting the Senseable object attribute rate_limit to a different value.
Local emulation Example Usage:
async def test():
import time
def test_devices():
devices = [PlugInstance("lamp1", start_time=time()-20, alias="Lamp", power=10),
PlugInstance("fan1", start_time=time()-300, alias="Fan", power=140)]
for d in devices:
yield d
sl = SenseLink(test_devices)
await sl.start()
try:
await asyncio.sleep(180) # Serve for 3 minutes
finally:
await sl.stop()
if __name__ == "__main__":
asyncio.run(test())
Metadata
Release files for sense-energy 0.15.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sense_energy-0.15.0.tar.gz | 19.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sense_energy-0.15.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.4 kB
Release files / sense_energy-0.15.0.tar.gz
| Download URL | sense_energy-0.15.0.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c50f59c1467d4a0735e190fd54620203f88d85d637ed42c55bdc5511e961ca34
|
|
BLAKE2b-256 checksum How to use checksums |
04e8114d233aed8d3006c41d0eccc92e65f25129baa81a088ff7bfd52171b53e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sense_energy-0.15.0-py3-none-any.whl
| Download URL | sense_energy-0.15.0-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c142d125649f95f976a8c46e70c558269cfee23dd6f1555cfa939ad44e5eaad1
|
|
BLAKE2b-256 checksum How to use checksums |
2f3bbc8ca885e779fa167f489d69c41b0a92a18396b2a533122053e6248b6a0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|