The examples of conditional expressions are there, but the tutorial is about how to do scripting in
Indigo not how to do scripting in
Python. Start by looking at some tutorials online about equality. You already have an equality conditional in your script:
- Code: Select all
if Garage1_State and GarageAutoClose:
indigo.iodevice.setBinaryOutput(308749424, 0, True)
In pseudo-code, this is saying:
- Code: Select all
if Garage1_State equals True and GarageAutoClose also equals True
then set the binary output zero of the device with ID 308749424 to True
Here are some ways to do comparisons:
- Code: Select all
x != 1 # does not equal
y == 'true' # equals
z > 123 # greater than
a is b # identities are the same
b is not c # identities are not the same
There are lots of comparison operators and they can be broadly grouped into at least two types:
value comparisons and
identity comparisons. That is, do two items have the same value or
are the two items the same thing. This is a bit too much to describe here--there's tons of guides out there that describes this stuff.
Secondly, there's the
if/then/else type stuff. You have an example of this in your script, too. There is also lots of stuff online about Python
if/then/else as well as 'while' and 'finally'
.
There's absolutely nothing special about doing comparisons and conditionals in Indigo with respect to Python. The 'difference' is how we get the values in order to compare them, and you have examples of this in your script, too.
- Code: Select all
Garage1 = indigo.devices[308749424].binaryInputs[0]
Garage1_State = indigo.variables[552843942].getValue(bool)
Probably the only truly tricky bit is to find all the states of a device. And this bit's not that tricky.
- Code: Select all
dev = indigo.devices[12345678] # get a copy (or instance) of the indigo device (see 'identity' above)
states = dev.states # inspect the device instance and grab the dict of its states
indigo.server.log(u"{0}".format(states)) # Print the dict of states to the Indigo log
Note how 'dev' in the first line shows up in the second line and how the variable 'states' in the second line shows up in the third line. Indigo quite handily also tells us what
type of value the state is (which is nice). There can be lots of states--here's a Fantastic Weather Plugin device's states:
- Code: Select all
states : States : (dict)
alertCount : 1 (integer)
alertDescription1 : ...FLASH FLOOD WATCH REMAINS IN EFFECT TONIGHT INTO TUESDAY... .Showers and thunderstorms will continue to deposit heavy rainfall over parts of southern Wisconsin tonight. Parts of west Madison has received between 2 and 5 inches of rainfall so far. A Flash Flood Warning remains in effect this evening for this area. Elsewhere, a Flash Flood Watch remains in effect for tonight. Occasional showers and thunderstorms will produce heavy rainfall tonight, possibly lasting into into Tuesday morning over southeast and east central Wisconsin. Several inches of additional rain may fall over southern Wisconsin during this time. Flash flooding may occur especially in urban areas or areas that received several inches of rain last week. ...FLASH FLOOD WATCH REMAINS IN EFFECT UNTIL 4 AM CDT TUESDAY... The Flash Flood Watch continues for * A portion of south central Wisconsin, including the following areas, Columbia, Dane, Green, Iowa, Lafayette, Rock, and Sauk. * Until 4 AM CDT Tuesday * Periods of moderate to heavy rainfall tonight. 2 to 4 inches of rainfall is expected with locally higher amounts. * Flash flooding in urban areas will be possible if 1 to 3 inches of rain or more falls in a short period of time. Flash flooding will be possible in rural areas that have already received several inches of rain last week. (string)
alertDescription2 : (string)
alertDescription2.ui : (string)
alertDescription3 : (string)
alertDescription3.ui : (string)
alertDescription4 : (string)
alertDescription4.ui : (string)
alertDescription5 : (string)
alertDescription5.ui : (string)
alertExpires1 : 2018-08-21 04:00 (string)
alertExpires2 : (string)
alertExpires2.ui : (string)
alertExpires3 : (string)
alertExpires3.ui : (string)
alertExpires4 : (string)
alertExpires4.ui : (string)
alertExpires5 : (string)
alertExpires5.ui : (string)
alertRegions1 : [u'Columbia', u'Dane', u'Green', u'Iowa', u'Lafayette', u'Rock', u'Sauk'] (string)
alertRegions2 : (string)
alertRegions2.ui : (string)
alertRegions3 : (string)
alertRegions3.ui : (string)
alertRegions4 : (string)
alertRegions4.ui : (string)
alertRegions5 : (string)
alertRegions5.ui : (string)
alertSeverity1 : warning (string)
alertSeverity2 : (string)
alertSeverity2.ui : (string)
alertSeverity3 : (string)
alertSeverity3.ui : (string)
alertSeverity4 : (string)
alertSeverity4.ui : (string)
alertSeverity5 : (string)
alertSeverity5.ui : (string)
alertStatus : true (bool)
alertStatus.ui : True (string)
alertTime1 : 2018-08-20 18:46 (string)
alertTime2 : (string)
alertTime2.ui : (string)
alertTime3 : (string)
alertTime3.ui : (string)
alertTime4 : (string)
alertTime4.ui : (string)
alertTime5 : (string)
alertTime5.ui : (string)
alertTitle1 : Flash Flood Watch (string)
alertTitle2 : (string)
alertTitle2.ui : (string)
alertTitle3 : (string)
alertTitle3.ui : (string)
alertTitle4 : (string)
alertTitle4.ui : (string)
alertTitle5 : (string)
alertTitle5.ui : (string)
alertUri1 : https://alerts.weather.gov/cap/wwacapget.php?x=WI125AB69F1168.FlashFloodWatch.125AB6AC1ED0WI.MKXFFAMKX.e993958cbc4700746e8b4380784edbb7 (string)
alertUri2 : (string)
alertUri2.ui : (string)
alertUri3 : (string)
alertUri3.ui : (string)
alertUri4 : (string)
alertUri4.ui : (string)
alertUri5 : (string)
alertUri5.ui : (string)
apparentTemperature : 69.27 (real)
apparentTemperature.ui : 69° (string)
apparentTemperatureIcon : 69 (real)
cloudCover : 100 (real)
cloudCover.ui : 100% (string)
cloudCoverIcon : 100 (real)
currentObservation : Last updated on Aug 20, 19:16 PM -0500 (string)
currentObservation24hr : 08-20-2018 07:16 PM (string)
currentObservationEpoch : 1534810570 (integer)
dewpoint : 65.5 (real)
dewpoint.ui : 66° (string)
dewpointIcon : 66 (real)
humidity : 90 (real)
humidity.ui : 90% (string)
humidityIcon : 90 (real)
icon : rain (string)
nearestStormBearing : -99 (real)
nearestStormBearing.ui : -- (string)
nearestStormBearingIcon : -99 (real)
nearestStormDistance : 0 (real)
nearestStormDistance.ui : 0 mi. (string)
nearestStormDistanceIcon : 0 (real)
onOffState : false (bool)
onOffState.ui : Disabled (string)
ozone : 313.42 (real)
ozone.ui : 313 (string)
ozoneIcon : 313 (real)
precipIntensity : 0.1315 (real)
precipIntensity.ui : 0.13 in. (string)
precipIntensityIcon : 0 (real)
precipProbability : 100 (real)
precipProbability.ui : 100% (string)
precipProbabilityIcon : 100 (real)
pressure : 1009.6 (real)
pressure.ui : 1010 mb (string)
pressureIcon : 1010 (real)
summary : Rain (string)
temperature : 68.48 (real)
temperature.ui : 68° (string)
temperatureIcon : 68 (real)
uv : 0 (real)
uv.ui : 0 (string)
uvIcon : 0 (real)
visibility : 6.54 (real)
visibility.ui : 7 mi. (string)
visibilityIcon : 7 (real)
weatherSummaryEmailSent : true (bool)
windBearing : 40 (real)
windBearing.ui : 40 (string)
windBearingIcon : 40 (real)
windBearingName : Northeast (string)
windGust : 17.87 (real)
windGust.ui : 18 mph (string)
windGustIcon : 18 (real)
windSpeed : 9.44 (real)
windSpeed.ui : 9 mph (string)
windSpeedIcon : 9 (real)
There's lots of online tutorials to learn Python scripting--that's how I learned (with the help of folks here)--the Indigo documentation shows how to apply those concepts to Indigo. It may seem like a lot to absorb, but if you take it simple at first, watch some online tutorials, and ramp up your skills bit by bit, you'll eventually find that there's almost nothing you can't do in Indigo.