Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Trying to poll device every 5 seconds but getting asyncio errors #316

Copy link
Copy link
@pushshift

Description

@pushshift
Issue body actions

Here is a copy of my current code:

#!/usr/bin/env python3

from kasa import SmartPlug
import asyncio
import time

plug = SmartPlug("192.168.1.96")

while True:
    asyncio.run(plug.update())
    power = plug.emeter_realtime.power
    print(power)
    time.sleep(5)

This almost works, but I encounter "Detected protocol reuse between different event loop" and then it eventually errors out.

What is the proper way to update the emeter information every X seconds?

Polling devices and storing them in a database is probably one of the top reasons for using this library. It would be wonderful if more examples were added to the documentation to show how to poll every X seconds / minutes.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.