Skip to content

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

@pushshift

Description

@pushshift

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions