Specific Device Check with Python

Posted on
Thu Nov 07, 2019 5:34 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Specific Device Check with Python

I'm trying to figure out a script to check specific devices. These are all devices that make up the perimeter of my home: z-wave door locks, insteon garage doors, DSC doors/windows.

What I have now is working... but IMO it's a pretty messing looking script (the first if is like 3 feet long). The end result is a one line message:
A) "House is Secure"
or
B) "House is not secure. Check (list of unlocked/open devices)".

Has anyone else done something like this or have a better way to do the same thing?

Code: Select all
theMessage = "House is not secure. Check "

if indigo.devices[649246778].onState == True and indigo.devices[1996124477].states['binaryInput1'] is True and indigo.devices[628198642].states['binaryInput1'] is True and indigo.devices[542492456].states['state.open'] is False and indigo.devices[629336732].states['state.open'] is False and indigo.devices[195317907].states['state.open'] is False and indigo.devices[1036911557].states['state.open'] is False and indigo.devices[752595934].states['state.open'] is False and indigo.devices[1798016138].states['state.open'] is False and indigo.devices[1862120226].states['state.open'] is False and indigo.devices[1969267507].states['state.open'] is False:
   theMessage = "House is Secure"


if indigo.devices[649246778].onState == False:
   theMessage = theMessage + "front door lock, "

if indigo.devices[628198642].states['binaryInput1'] is False:
   theMessage = theMessage + "Right Garage Door, "

if indigo.devices[1996124477].states['binaryInput1'] is False:
   theMessage = theMessage + "Left Garage Door, "

if indigo.devices[542492456].states['state.open'] is True:
   theMessage = theMessage + "Front Door, "

if indigo.devices[629336732].states['state.open'] is True:
   theMessage = theMessage + "Laundry Door, "
           
if indigo.devices[195317907].states['state.open'] is True:
   theMessage = theMessage + "Side Door, "

if indigo.devices[1036911557].states['state.open'] is True:
   theMessage = theMessage + "Back Door, "

if indigo.devices[752595934].states['state.open'] is True:
   theMessage = theMessage + "Kitchen Windows, "

if indigo.devices[1798016138].states['state.open'] is True:
   theMessage = theMessage + "Master Bedroom Windows, "

if indigo.devices[1862120226].states['state.open'] is True:
   theMessage = theMessage + "Nursery Windows, "

if indigo.devices[1969267507].states['state.open'] is True:
   theMessage = theMessage + "Front Windows, "

indigo.server.log(theMessage)

Bill
My Plugin: My People

Posted on
Thu Nov 07, 2019 7:21 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Specific Device Check with Python

What I would do is a series of individual if statement, each of which appends the name of the device to an output string if no secure.

Then test the string. If it’s not empty set the message accordingly.


Sent from my iPhone using Tapatalk

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Nov 08, 2019 7:06 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Specific Device Check with Python

Wouldn’t a virtual device group do this by UI?

If it’s on (they match predefined states) they’re all secure, otherwise they’re not?


Sent from my iPhone using Tapatalk Pro

Posted on
Fri Nov 08, 2019 7:10 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Specific Device Check with Python

One simple way to make your script a little cleaner: there's no need in Python to say `if XXXX == True` or if `XXXX is True`. You can just say `if XXXX` and `if not XXXX`.

Code: Select all
a = True
b = False

# Instead of `if a is True`:
if a:
    print(u"a is True")
   
# Instead of `if b is False`:
if not b:
    print(u"b is False")

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Nov 08, 2019 9:58 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Specific Device Check with Python

howartp wrote:
Wouldn’t a virtual device group do this by UI?

If it’s on (they match predefined states) they’re all secure, otherwise they’re not?


If all the devices support an onState, this is what I'd do. See the section that describes the devices that make up the zone in this wiki article.

And if some don't directly support an onState, you might be able to use one of the other virtual device plugins (like the Masquerade plugin) to wrap those devices with a device that does.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Nov 08, 2019 11:13 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Specific Device Check with Python

howartp wrote:
Wouldn’t a virtual device group do this by UI?

If it’s on (they match predefined states) they’re all secure, otherwise they’re not?


Sent from my iPhone using Tapatalk Pro


Tried and failed. Virtual device group doesn't like/see I/O devices. I've also tried numerous plugins to try to get all the devices to group in some way (Security Manager, Cynical Behaviors, Group Change Listener, Group Trigger) but always ran into a brick wall at some point.

End goal will be a singular command, i.e., "Alexa, I'm ready for bed" -> "Bed check virtual device" -> Security Check (this script) - > Check Lights & other devices (another script)-> Arm alarm, announce tomorrow's calendar events & tomorrow's weather. <- something like that... not all the details are worked out yet.

Bill
My Plugin: My People

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests