Page 1 of 1

Specific Device Check with Python

PostPosted: Thu Nov 07, 2019 5:34 pm
by whmoorejr
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)

Re: Specific Device Check with Python

PostPosted: Thu Nov 07, 2019 7:21 pm
by FlyingDiver
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

Re: Specific Device Check with Python

PostPosted: Fri Nov 08, 2019 7:06 am
by howartp
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

Re: Specific Device Check with Python

PostPosted: Fri Nov 08, 2019 7:10 am
by DaveL17
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")

Re: Specific Device Check with Python

PostPosted: Fri Nov 08, 2019 9:58 am
by jay (support)
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.

Re: Specific Device Check with Python

PostPosted: Fri Nov 08, 2019 11:13 am
by whmoorejr
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.