Page 1 of 1

[ANSWERED]Delayed iMessage based on device state

PostPosted: Thu Nov 12, 2015 3:13 pm
by petematheson
Hi Guys,

I managed to delete my old trigger when switching devices over.
Could someone correct my script for me please?

I want to send an iMessage if the Garage Door is left open for more than 5 minutes.
I have the trigger defined as, If Garage Door state open = true, then run the following script (which has a delay of 5 minutes)

set GarageDoorOpen to state of device "Alarm_Garage Door"
if GarageDoorOpen = (open) then
tell application "Messages"
set theBuddy to buddy "Pete"
send "Garage door has been left open" to theBuddy
end tell
else
end if

The sending works fine - it's just the checking if statement I can't get to work. It says that it can't get the state of Alarm_Garage Door

Re: Delayed iMessage based on device state

PostPosted: Thu Nov 12, 2015 4:00 pm
by jay (support)
I don't know what kind of device "Alarm_Garage Door" is, so I'm not sure what syntax will work for it...

Re: Delayed iMessage based on device state

PostPosted: Thu Nov 12, 2015 4:02 pm
by petematheson
Ah sorry, it's a wireless contact for my DSC alarm.

Re: Delayed iMessage based on device state

PostPosted: Thu Nov 12, 2015 4:51 pm
by jay (support)
Well, assuming it's a relay device type (vs a custom device);

Code: Select all
set GarageDoorOpen to on state of device "Alarm_Garage Door"
if GarageDoorOpen  then
    tell application "Messages"
        set theBuddy to buddy "Pete"
        send "Garage door has been left open" to theBuddy
    end tell
end if

Re: Delayed iMessage based on device state

PostPosted: Fri Nov 13, 2015 3:53 pm
by howartp
Jay

Garage door WAS a tilt sensor - Pete has replaced it with an alarm contact sensor that the DSC plugin reports as a custom zone device with custom state 'state' with values 'open' and 'closed'.

Can AppleScript access custom states of custom devices - if so, what is the script for that?


Sent from my iPhone using Tapatalk

Re: Delayed iMessage based on device state

PostPosted: Fri Nov 13, 2015 7:47 pm
by durosity
AppleScript can't access custom states afaik, best bet would be either setup a trigger to copy the state to a variable

Re: Delayed iMessage based on device state

PostPosted: Sat Nov 14, 2015 3:40 pm
by jay (support)
howartp wrote:
Garage door WAS a tilt sensor - Pete has replaced it with an alarm contact sensor that the DSC plugin reports as a custom zone device with custom state 'state' with values 'open' and 'closed'.

Can AppleScript access custom states of custom devices - if so, what is the script for that?


Ah ha. Well, that totally explains it. The tilt sensor was probably a standard relay (on/off) device, which AppleScript can see and check the "on state" of. Custom device states, however, aren't exposed to AppleScript (as durosity points out). I agree with him that creating a trigger that inserts the state into a variable is the easiest way to do it.

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Sun Nov 15, 2015 1:51 pm
by petematheson
Ah gotcha. Could you correct my also script for a variable or do I just change the word device for variable ?

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Mon Nov 16, 2015 12:12 pm
by jay (support)
I don't know exactly what's going to be inserted into the variable since I don't know what the state value is, but the script will look something like this:

Code: Select all
if value of variable "someVarNameHere" is "open" then
    tell application "Messages"
        set theBuddy to buddy "Pete"
        send "Garage door has been left open" to theBuddy
    end tell
end if


In the first line, replace open with whatever the actual value is. That's pretty close anyhow...

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Thu Jan 07, 2016 12:40 pm
by petematheson
Hi Jay & All,

No dice on this one, after realising today that my garage was stuck half-open today and I received no text. Left open for half a day, lucky nothing useful was in it!

I'm using the following:
if value of variable "GarageDoor" is "open" then
tell application "Messages"
set theBuddy to buddy "Pete Matheson"
send "Garage door has been left open" to theBuddy
end tell
end if

even if I set this to immediately (instead of delay by 5 minutes) then I don't get a text.
It works perfectly if I click the 'Run' button. But just doesn't seem to work if I click Execute Actions Now

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Thu Jan 07, 2016 1:20 pm
by jay (support)
Hmmm - I don't see how that's possible (pressing Run and it works, clicking Execute Actions Now doesn't). What shows up in the event log when you press the Execute Actions Now button?

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Thu Jan 07, 2016 4:21 pm
by petematheson
Hmmm, execute actions seems to be working now! Although I've changed the variable to 'closed' for now as it's late / dark / cold to go test with it open.
I'll give it a try tomorrow with the door open and see what happens, weird!

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Fri Nov 15, 2019 11:53 am
by petematheson
Sorry to resurrect an old thread, with the changes to Applescript - what do I need to do to achieve this same result?

Garage door opens (the trigger)
A few minutes later Indigo checks if the door is still open - if yes = send iMessage every 5 minutes until it's closed.

Re: [ANSWERED]Delayed iMessage based on device state

PostPosted: Fri Nov 15, 2019 2:47 pm
by jay (support)
You might want to look at the iMessages plugin - assuming it does the notification part like you want, then you probably don't even need a script. When the door opens, enable a timer device for however long you want to wait. Create a trigger that executes when the timer expires to send the message. Have another trigger that stops the timer when the door closes.