Plugin requests

Post scripts or code snippits to get help converting them to Python 3 (available in Indigo 2022.1 and beyond).
User avatar
jay (support)
Site Admin
Posts: 18479
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Plugin requests

Post by jay (support) »

EagleDTW wrote: Fri Nov 01, 2024 7:59 pmThanks, Jay...this is pretty straightforward and I appreciate the example read through!
It really is quite simple to do that sort of logic in a Python script with just a basic understanding. Let us know if you have any issues with your scripts over in the scripting forum section - lots of helpful and friendly people will chime in with examples and recommendations.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

EagleDTW wrote: Fri Nov 01, 2024 7:59 pm
jay (support) wrote: Fri Nov 01, 2024 9:29 am The easiest way is with a simple script:

Code: Select all

# Set up some local variables
#  this is the ID of nest device - it gets the full device instance
device_to_test = indigo.devices[IDOFTESTDEVICE]

#  this is the ID of the state as shown in the custom states list
#   it gets the value of the specified state for comparison later
device_state_value = device_to_test.states["ACTUALSTATEID"]

#  these are the IDs of the action groups to execute later
true_action_group = IDOFTRUEACTIONGROUP
false_action_group = ISOFFALSEACTIONGROUP

# This does the actual work
#  the comparison that your image shows is to check to see if the state value contains the
#  specified string, but if the value is an exact match you can use '!=' instead of 'in'
if "heat_cool" not in device_state_value:
    # it's not in the state value so execute the true group
    indigo.actionGroup.execute(true_action_group)
else:
    # it's in the state value, so execute the false group
    indigo.actionGroup.execute(false_action_group)
Don't be freaked out - I've broken things out and added comments to describe what's going on as a learning exercise. However, if you want to simplify:

Code: Select all

if "heat_cool" not in indigo.devices[IDOFTESTDEVICE].states["ACTUALSTATEID"]:
    indigo.actionGroup.execute(IDOFTRUEACTIONGROUP)
else:
    indigo.actionGroup.execute(ISOFFALSEACTIONGROUP)
Just substitute the appropriate UPPERCASEVALUES with the actual values and I think it'll work.
Thanks, Jay...this is pretty straightforward and I appreciate the example read through!
Hi @Jay I thought that it was pretty straightforward, but the method to get the actualstateID eludes me...does this output to a list somewhere?
User avatar
DaveL17
Posts: 6905
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Plugin requests

Post by DaveL17 »

jay (support) wrote: Sat Nov 02, 2024 2:28 pm does this output to a list somewhere?
In the Indigo UI, right-click on the device and select "Print Device Details to Event Log". Within the log output, look for the key `states` -- all the state names will be listed for the device.
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
User avatar
jay (support)
Site Admin
Posts: 18479
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Plugin requests

Post by jay (support) »

Assuming it's a custom state, it also shows in the Custom States tile when you select the device in the Home Window.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

I appreciate the quick responses from both of you!!
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

Hi @Jay,

Are Variable states just this script or something a bit different:

if "status_var" not in indigo.variables[IDOFVARIABLE].value["ACTUALVALUE"]:
indigo.actionGroup.execute(IDOFTRUEACTIONGROUP)
else:
indigo.actionGroup.execute(ISOFFALSEACTIONGROUP)



Thank you,
Daniel
User avatar
DaveL17
Posts: 6905
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Plugin requests

Post by DaveL17 »

Variables don't have `states`, they have `values` and the values are always strings. You can access the variable's string value directly.

Try this:

Code: Select all

if "status_var" not in indigo.variables[IDOFVARIABLE].value:
    indigo.actionGroup.execute(IDOFTRUEACTIONGROUP)
else:
    indigo.actionGroup.execute(ISOFFALSEACTIONGROUP)
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

Nice - thanks, Dave! I'll give that a try!!

-Daniel
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

And Dave would it be this for changing a variable value:

if "status_var" not in indigo.variables[IDOFVARIABLE].value:
indigo.variables(IDOFVARIABLE).value[true]
else:
indigo.actionGroup.execute(ISOFFALSEACTIONGROUP)
EagleDTW
Posts: 106
Joined: Thu Apr 30, 2020 5:56 pm

Re: Plugin requests

Post by EagleDTW »

Got it solved!!

if "true" not in indigo.variables[18821087].value:
myVar = indigo.variables[8360458]
indigo.variable.updateValue(myVar, "true")
else:
indigo.actionGroup.execute(861401)

-Daniel
User avatar
DaveL17
Posts: 6905
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Plugin requests

Post by DaveL17 »

Good on ya. In circumstances like this, it's best to check the documentation. It'll save you a lot of time.

For instance,
https://wiki.indigodomo.com/doku.php?id ... able_class
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
Post Reply

Return to “Help Converting to Python 3”