Skip to main content

API for the Sense Energy Monitor

Project description

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!

https://github.com/kbickar

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.

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sense_energy-0.10.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sense_energy-0.10.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sense_energy-0.10.1.tar.gz.

File metadata

  • Download URL: sense_energy-0.10.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for sense_energy-0.10.1.tar.gz
Algorithm Hash digest
SHA256 8e0d29ba05d6f90516cfcf25dc336dc9c08016f2aa5473cd9b090a44bab439ca
MD5 6f51beb67475546b054cacf3df86294a
BLAKE2b-256 e428a4f99dfe021fc4cb175d490d83952ffea3422546d052059fe80fbd348821

See more details on using hashes here.

File details

Details for the file sense_energy-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: sense_energy-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for sense_energy-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 960d2f1783dc3b4b053f9260fe229215e9d383e19a6df3d0847a9885cfd7ef5d
MD5 4cdb67eca6c30975db34d2e1497aba3b
BLAKE2b-256 d3557916a32be4f0591acf9c040d02da448a5d111f1b5465bb64d53b6b0f35f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page