Turning on devices that are deactivated

Python scripts to do various things. These would be scripts that talk directly with Indigo (use indigo.* methods).
pgershon
Posts: 516
Joined: Sat Jul 10, 2004 1:07 am

Turning on devices that are deactivated

Post by pgershon »

Looking for some general help here and I will post this also in the TP-Link specific forum, but I believe the usage/application is more global.

I use the TP-Link plug-in to control 40+ Kasa devices (generally HS200 and HS220 dimmers and switches). The plug-in works great, with one exception. My devices periodically seem to lose their communication with the network, then get it back. Not normally as issue as the TP-Link plugin polls the devices and keeps track of consecutive failures to communicate. The problem is that periodically devices get deactivated and need to be (1) notices and then (2) manually re-activated in the console. Obviously the best solution would be to identify why the devices go on and off line and rectify the problem, but I suspect it is simply the general behavior of devices and wifi access point in multiple locations of a large house competing with one another (RSSI is very strong on all devices normally). I have been trying to nail this down for years now and have given up.

Absent a global solution to eliminate the problem, the next best thing would be to write a script that would poll all TP-Link devices that are deactivated (comm field set to off) and activate them. I imagine what I want to do is scan all devices where indigo.device.enable(dev.id, value=False) and reset the field value to true for them. I could then run this routine every 30 minutes or so so fix most of my issues. Unfortunately my programing skills in Python are limited so any help /suggestions would be most appreciated. I believe this is a relatively simple process to do.

Thanks in advance...
User avatar
DaveL17
Posts: 6905
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Turning on devices that are deactivated

Post by DaveL17 »

If I understand the situation, something like this should work.

Code: Select all

plugin = indigo.server.getPlugin("YOUR-PLUGIN-ID-HERE")  # get this from the plugin menu "Copy Plugin ID"
if plugin.isEnabled:
    for dev in indigo.devices.iter(filter=plugin.pluginId):
        if not dev.enabled:
            indigo.device.enable(dev.id, True)
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
pgershon
Posts: 516
Joined: Sat Jul 10, 2004 1:07 am

Re: Turning on devices that are deactivated

Post by pgershon »

Thanks. I will try that.

AND IT WORKS PERFECTLY!
Post Reply

Return to “Python Scripts”