Page 1 of 1

Need help re-writting my applescript for new Plugin

PostPosted: Fri Oct 28, 2016 4:42 pm
by kidney
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!

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

PostPosted: Fri Oct 28, 2016 7:03 pm
by kw123
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

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

PostPosted: Fri Oct 28, 2016 11:28 pm
by kidney
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 ;)

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

PostPosted: Sat Oct 29, 2016 11:09 am
by kw123
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

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

PostPosted: Sat Oct 29, 2016 1:18 pm
by kidney
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)