Need help re-writting my applescript for new Plugin

Posted on
Fri Oct 28, 2016 4:42 pm
kidney offline
Posts: 237
Joined: Jul 15, 2007

Need help re-writting my applescript for new Plugin

Hi!

I used to have an applescript that would open the light according to the point of entry into the house that went like this

Code: Select all
if the value of variable "DSC_Entry_point" is "Porte garage-maison" then turn on "Portique" in 5 for 180
if the value of variable "DSC_Entry_point" is "Garage" then turn on "Passage Garage Salle d'eau" in 5 for 180


But now with the new DSC plugin i dont have the same hooks to make this work, so I would need help to re-write the script either in python or apple script.

The output remains the same, but the hooks are different
So here are what I think are the proper hooks to trigger the proper the action but don't know how to code it!
Device state changed: Porte Garage-Maison: Changed Timer (mins.) changed; become less than 2; then turn on "Portique" in 5 for 180
and the other should be
Device state changed: Porte Entree principale: Changed Timer (mins.) changed; become less than 2; then turn on "Passage Garage Salle d'eau" in 5 for 180

Hope fully someone can help me and understand what I'm trying to achieve!

Posted on
Fri Oct 28, 2016 7:03 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Need help re-writting my applescript for new Plugin

here your code in python
[code]## a more complex condition you can put here: (integer value of state "Changed Timer (mins.)" < 2)
if int(indigo.devices["Porte Garage-Maison"].states["Changed Timer (mins.)"]) >2:return
##
## 1. condition ok now check other conditions and then execute
if indigo.variable["DSC_Entry_point"].value == "Porte garage-maison":
indigo.device.turnOn("Portique", duration=180, delay=4)
if indigo.variable["DSC_Entry_point"].value == "Garage":
indigo.device.turnOn("Passage Garage Salle d'eau", duration=180, delay=4)
and the trigger and conditions page

I strongly recommend to use python and not applescript. If done wrong and you can easily do it wrong, it can kill other plugins and create havoc in devices etc when the script times out .

if you have more complex conditions we can add that to the script, have shown a small example

hope that helps

Karl
Attachments
Screen Shot 2016-10-28 at 19.56.39.png
Screen Shot 2016-10-28 at 19.56.39.png (40.89 KiB) Viewed 2513 times
Screen Shot 2016-10-28 at 19.56.48.png
Screen Shot 2016-10-28 at 19.56.48.png (34.14 KiB) Viewed 2513 times

Posted on
Fri Oct 28, 2016 11:28 pm
kidney offline
Posts: 237
Joined: Jul 15, 2007

Re: Need help re-writting my applescript for new Plugin

Thanks but you missed the part where the script doesn't use variable anymore.....

I'm trying to use device state now.
Here is what is what to work or hope that would work

Device state changed: Porte Entree principale: Changed Timer (mins.) changed; become less than 2; then turn on "Portique" in 5 for 180
Device state changed: Porte Garage-Maison: Changed Timer (mins.) changed; become less than 2; then turn on "Passage Garage Salle d'eau" in 5 for 180

So here is the entire plans
Trigger is has follow:
Device state Changed: Keypad: Alarm state changed to Entry delay

Conditions:
Match All
if dark
if device: Keypad: Armed state is Armed Away (true or false): is true

Action is the python script

hope that make more clear ;)

Posted on
Sat Oct 29, 2016 11:09 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Need help re-writting my applescript for new Plugin

could you post name of device and name of state of things that triggers and device and state names to things that should change

trigger:
- devicename=
- statename=
- condition=

action:
- devicename =
- statename =
- what the action should do

then we can with this. your example looks like 2 triggers / actions ?

this action script turns "GameRoomCeilingLights" on after 4 seconds for 180 seconds if state "Pi_0_Distance" >10 of device with id= 1434599495
Code: Select all
if float(indigo.devices[1434599495].states["Pi_0_Distance"]) >10:
  indigo.device.turnOn("GameRoomCeilingLights", duration=180, delay=4)


and in the trigger you need to put if any change to device/state
you can replace the id with the name, but then you must use quotes. -- if you right click on a device state you can copy the python script reference


Karl

Posted on
Sat Oct 29, 2016 1:18 pm
kidney offline
Posts: 237
Joined: Jul 15, 2007

Re: Need help re-writting my applescript for new Plugin

Thanks Karl works great

Code: Select all
# 1.
if int(indigo.devices["Porte Entree principale"].states["LastChangedTimer"]) <=2:
   indigo.device.turnOn("Portique", duration=180, delay=4)
# 2.
if int(indigo.devices["xxxxx"].states["LastChangedTimer"]) <=2:
   indigo.device.turnOn("Passage Garage Salle d'eau", duration=180, delay=4)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests