[ANSWERED]Delayed iMessage based on device state

Posted on
Thu Nov 12, 2015 3:13 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

[ANSWERED]Delayed iMessage based on device state

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

Posted on
Thu Nov 12, 2015 4:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delayed iMessage based on device state

I don't know what kind of device "Alarm_Garage Door" is, so I'm not sure what syntax will work for it...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Nov 12, 2015 4:02 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: Delayed iMessage based on device state

Ah sorry, it's a wireless contact for my DSC alarm.
Attachments
Screen Shot 2015-11-12 at 22.03.51.png
Screen Shot 2015-11-12 at 22.03.51.png (58.29 KiB) Viewed 5840 times
Screen Shot 2015-11-12 at 22.03.54.png
Screen Shot 2015-11-12 at 22.03.54.png (61.65 KiB) Viewed 5840 times
Screen Shot 2015-11-12 at 22.04.00.png
Screen Shot 2015-11-12 at 22.04.00.png (27.69 KiB) Viewed 5840 times

Posted on
Thu Nov 12, 2015 4:51 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delayed iMessage based on device state

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

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Nov 13, 2015 3:53 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Delayed iMessage based on device state

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

Posted on
Fri Nov 13, 2015 7:47 pm
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Delayed iMessage based on device state

AppleScript can't access custom states afaik, best bet would be either setup a trigger to copy the state to a variable

Computer says no.

Posted on
Sat Nov 14, 2015 3:40 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delayed iMessage based on device state

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Nov 15, 2015 1:51 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: [ANSWERED]Delayed iMessage based on device state

Ah gotcha. Could you correct my also script for a variable or do I just change the word device for variable ?

Posted on
Mon Nov 16, 2015 12:12 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Delayed iMessage based on device state

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...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 07, 2016 12:40 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: [ANSWERED]Delayed iMessage based on device state

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

Posted on
Thu Jan 07, 2016 1:20 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Delayed iMessage based on device state

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?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 07, 2016 4:21 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: [ANSWERED]Delayed iMessage based on device state

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!

Posted on
Fri Nov 15, 2019 11:53 am
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: [ANSWERED]Delayed iMessage based on device state

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.

Posted on
Fri Nov 15, 2019 2:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Delayed iMessage based on device state

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests