Python to update a delayed action

Posted on
Thu Apr 05, 2018 6:31 am
jenkins007 offline
Posts: 113
Joined: Nov 08, 2006
Location: Seguin, TX

Python to update a delayed action

I am in the process of converting my 30+ scripts to python. Jay, you are right it seems way better than Apple Script! I have several devices that are triggered by motion detectors. Depending on certain factors (either temperature outside and inside, or the time of day), different actions occur. My main kitchen lights, for example, turn on during the in the afternoon for 45 minutes at a time, and there are 4 different durations (I use a variable kitchenDelay) that get set by a schedule (like only 1 minute after 11pm).

As I was converting, I used the if statement to only turn on when the lights were off. This reduced a lot (LOTS) of insteon traffic. However, the lights always turn off after the duration, making my wife not a happy camper. So I removed the if's and are are back to more traffic, although using python.

I was wondering if there is a better way to update the delayed actions if the lights are on when a new motion is detected, in python. Basically to reset the delayed turn off actions to the delay variable. The delayed actions are 2 lights, on/off and dimmer, and a keypadlinc button (which is on/off via a trigger based on on/off state of the lights).

I've tried this, but the off command is immediate with the delay to turn them back on instead of my desire to adjust the auto off delayed action. The names in the script are linked to the python instance number...
Code: Select all
if kitchenLight.onState:
   indigo.device.turnOff(kitchenLight, duration = kitchenDelay)
   indigo.device.turnOff(kitchenTable, duration = kitchenDelay)
   indigo.server.log("Turning off kitchen lights in " +Delay + " minutes");
else:
   indigo.device.turnOn(kitchenLight, duration = kitchenDelay)
   indigo.device.turnOn(kitchenTable, duration = kitchenDelay)
   indigo.server.log("Turning on kitchen lights for " +Delay + " minutes");

Thanks,
Matthew

Posted on
Thu Apr 05, 2018 9:32 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python to update a delayed action

I think you want to use the delay parameter rather than duration, right?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Apr 06, 2018 7:46 am
jenkins007 offline
Posts: 113
Joined: Nov 08, 2006
Location: Seguin, TX

Re: Python to update a delayed action

Thanks Jay! That is exactly what I was looking for. I am definitely a noob at python. I apologize if I missed this, but I've spent the better part of a week looking at this so far. Also, using the delay every time the motion is detected, you must first remove any other delayed actions in the trigger using the built-in UI under server actions.

I made my way comfortable with the AppleScript dictionary since indigo version 2, but haven't been able to find the various parameters by device or action equivalent in python. I've checked out the IOM and gone through the Wiki tutorials and it definitely helped, but I have been hit and miss on the specific commands/parameters for specific devices not listed in your excellent documentation, such as device types defined by RFX plugin or others. So what is the command in python that will give me those parameters for each device type and or action, for example an RFX temp sensor?

Thanks,
Matthew

Posted on
Fri Apr 06, 2018 9:44 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python to update a delayed action

The details for all built-in device types are all listed in the Devices section of the IOM Reference. That shows the properties, states, and commands that can be used.

With the introduction of plugins and plugin devices (such as those defined by the RFXCOM plugin, it became the responsibility of the developer of the plugin to document the device states and actions that the plugin presents. Custom device types inherit all of the properties defined in the Device Base Class. They are very likely to add their own device states, which can be inspected by looking at the Custom States tile in the Indigo UI or by opening a scripting shell and viewing them in there as shown in the Access a custom device state section of the Scripting Tutorial.

Plugins should document how to call the plugin-defined actions (here's an example of how we documented them for the iTunes plugin). If a plugin you're using has actions but hasn't documented the necessary parameters/properties that it's expecting, just ask the developer for that information.

Unlike AppleScript, where the dictionary must be defined for anything to work correctly and where that dictionary can be inspected automatically, Python has no such requirements, so documentation is required.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 17 guests