Check Device State with Python Example?

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Thu Dec 06, 2012 11:32 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Check Device State with Python Example?

Assuming a python script can test for a device state, could I bug someone for
a sample script that would toggle a device on/off and set at variable depending which
state the device was in?

Trying to get started with python.

Thanks,

Carl

Posted on
Thu Dec 06, 2012 11:45 am
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Check Device State with Python Example?

The device examples section of the scripting tutorial has a bunch of examples.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Dec 06, 2012 12:09 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Check Device State with Python Example?

Real quick (I haven't tested this)...

Code: Select all
# Test to see if the Desk Lamp is off or not.
if indigo.devices['Desk Lamp'].onState == False:
    # Desk Lamp is off. Save the "false" state into the OldDeskLampState variable.
    indigo.variable.updateValue(indigo.variables['OldDeskLampState'], "false")
    # Now turn on the Desk Lamp.
    indigo.device.turnOn('Desk Lamp')
else:
    # Desk Lamp is on. Save the "true" state into the OldDeskLampState variable.
    indigo.variable.updateValue(indigo.variables['OldDeskLampState'], "true")
    # Now turn off the Desk Lamp.
    indigo.device.turnOff('Desk Lamp')

Note that this code assumes you have a device named "Desk Lamp" and a variable named "OldDeskLampState". It also assumes that the Desk Lamp is a device that supports being turned on or off.

Posted on
Fri Dec 07, 2012 3:45 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Check Device State with Python Example?

Thanks, works great.

Carl

Page 1 of 1

Who is online

Users browsing this forum: Google [Bot] and 1 guest