# 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:
```python
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:
```python
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())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/scottbonline/sense",
"name": "sense-energy",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "sense, energy, api",
"author": "scottbonline",
"author_email": "scottbonline@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ac/ba/f545dff2176fe32d187f586e4c62e02828e7aecd4298dff5ecdd422a35c0/sense_energy-0.13.4.tar.gz",
"platform": null,
"description": "# sense_api\n## Sense Energy Monitor API Interface\nThe Sense API provides access to the unofficial API for the Sense Energy Monitor. Through the API,\none can retrieve both realtime and trend data including individual devices.\n\nSystematic access to the Sense monitor data. Exploratory work on pulling data from Sense\nto be used in other tools - HomeASsistant, Smartthings, ActiveTiles, etc. \n\nPython version based on the work done here in Powershell:\nhttps://gist.github.com/mbrownnycnyc/db3209a1045746f5e287ea6b6631e19c\n\n## Local Device Emulation\nThe SenseLink class emulates the energy monitoring functionality of TP-Link Kasa HS110 Smart Plugs\n and allows you to report \"custom\" power usage to your Sense Home Energy Monitor. This requires \nenabling \"TP-Link HS110/HS300 Smart Plug\" in the Sense app.\n\nBased off the work of https://github.com/cbpowell/SenseLink\n\n### Contributors\n\nFeel free to fork and PR! \n\nhttps://github.com/kbickar\n\n### Todo\n\n- Add POST/PUT where/if applicable\n- CLI\n- Improved error handling\n\n\n### Install\n\n```\npip install sense_energy\n```\n\n### Web API Example Usage:\n```python\n from sense_energy import Senseable\n sense = Senseable()\n sense.authenticate(username, password)\n sense.update_realtime()\n sense.update_trend_data()\n print (\"Active:\", sense.active_power, \"W\")\n print (\"Active Solar:\", sense.active_solar_power, \"W\")\n print (\"Daily:\", sense.daily_usage, \"KWh\")\n print (\"Daily Solar:\", sense.daily_production, \"KWh\")\n print (\"Active Devices:\",\", \".join(sense.active_devices))\n```\n\nThere are plenty of methods for you to call so modify however you see fit\n\nIf using the API to log data, you should only create one instance of Senseable and \nthen reuse that to get the updated stats. Creating the instance authenticates \nwith the Sense API which should only be once every 15-20 minutes at most. \nCalling the `update_trend_data()` function will update all the trend stats \nand `get_realtime()` will retrieve the latest real time stats.\n\nThe get_realtime() is by default rate limited to one call per 30 seconds. This can\nbe modified by setting the Senseable object attribute `rate_limit` to a different value.\n\n### Local emulation Example Usage:\n```python\n\tasync def test():\n\t\timport time\n\t\tdef test_devices():\n\t\t\tdevices = [PlugInstance(\"lamp1\", start_time=time()-20, alias=\"Lamp\", power=10), \n\t\t\t\t\t PlugInstance(\"fan1\", start_time=time()-300, alias=\"Fan\", power=140)]\n\t\t\tfor d in devices:\n\t\t\t\tyield d\n\t\tsl = SenseLink(test_devices)\n\t\tawait sl.start()\n\t\ttry:\n\t\t\tawait asyncio.sleep(180) # Serve for 3 minutes\n\t\tfinally:\n\t\t\tawait sl.stop()\n\n\tif __name__ == \"__main__\":\n\t\tasyncio.run(test())\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "API for the Sense Energy Monitor",
"version": "0.13.4",
"project_urls": {
"Download": "https://github.com/scottbonline/sense/archive/0.13.4.tar.gz",
"Homepage": "https://github.com/scottbonline/sense"
},
"split_keywords": [
"sense",
" energy",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5c87829d8da9b8e22c13f03ef2197b9cd211940781c29fc2a8fd21c6ed6fc7f",
"md5": "de91ba7712f2004acaea92ee47948a79",
"sha256": "d6c94294ff0c5c41bc33bd902a366631a47db4bb3f2eb15d2ef539f1c1f2206e"
},
"downloads": -1,
"filename": "sense_energy-0.13.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "de91ba7712f2004acaea92ee47948a79",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 15214,
"upload_time": "2024-11-14T14:48:32",
"upload_time_iso_8601": "2024-11-14T14:48:32.510107Z",
"url": "https://files.pythonhosted.org/packages/b5/c8/7829d8da9b8e22c13f03ef2197b9cd211940781c29fc2a8fd21c6ed6fc7f/sense_energy-0.13.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "acbaf545dff2176fe32d187f586e4c62e02828e7aecd4298dff5ecdd422a35c0",
"md5": "619880626ca8c70931e8ac08738ccc44",
"sha256": "b53800a9a5e66ae6b277d6d1728ee3905b8c69c6bd7b1d9c854cff15bc56b52b"
},
"downloads": -1,
"filename": "sense_energy-0.13.4.tar.gz",
"has_sig": false,
"md5_digest": "619880626ca8c70931e8ac08738ccc44",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14084,
"upload_time": "2024-11-14T14:48:34",
"upload_time_iso_8601": "2024-11-14T14:48:34.147880Z",
"url": "https://files.pythonhosted.org/packages/ac/ba/f545dff2176fe32d187f586e4c62e02828e7aecd4298dff5ecdd422a35c0/sense_energy-0.13.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-14 14:48:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "scottbonline",
"github_project": "sense",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sense-energy"
}