Skip to content

Is this capable of checking if a smart plug is plugged in? #126

Closed Answered by rytilahti
Concrete18 asked this question in Q&A
Discussion options

You must be logged in to vote

Or you could simple ping the device :-)

This library is more aimed to control & read information from those devices and not really aimed for connectivity tracking.
Anyway, to answer your question, something like this should work with this library:

import asyncio
from kasa import SmartPlug

async def is_online(addr):
    plug = SmartPlug(addr)
    try:
        await plug.update()
    except Exception:
        return False

    return True

asyncio.run(is_online("192.168.1.1"))

The exception block catches all exceptions (e.g., maybe there is a device in the given address, but it isn't a supported one and replies with something unexpected) which may be too wide depending on what exactly (an…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rytilahti
Comment options

Answer selected by rytilahti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants