Motion Detecting Help Needed

Posted on
Sat Feb 21, 2004 6:41 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Motion Detecting Help Needed

I'm looking for a way to do various things after X minutes from the last motion detected in the house. This "away mode" is going to be different then day and night and it has to look at when the last motion was detected from all the motion detectors in the house.

Do the readers of the board have any suggestions?

Posted on
Sat Feb 21, 2004 7:23 pm
dscottbuch offline
Posts: 90
Joined: Jan 19, 2004

Re: Motion Detecting Help Needed

gregjsmith wrote:
I'm looking for a way to do various things after X minutes from the last motion detected in the house. This "away mode" is going to be different then day and night and it has to look at when the last motion was detected from all the motion detectors in the house.

Do the readers of the board have any suggestions?


Here's one idea.

Have a variable "motion detected"

Whenever any motion is detected toggle this variable between true and false.

Have two trigger actions, one that activates on the true-false transition and on on the false-true transition

These trigger actions both do the same thing, they 'remove delayed actions' for the target devices and then they re-establish the delayed actions for the target devices in X minutes. If any motion occurs the delays are reset. This is done with the applescript commands.

How does that sound??

Posted on
Sun Feb 22, 2004 11:04 am
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

I had considered this:

A variable called "lastInsideMotion" in which every motion detector puts its Current Date into.

I would have trigger action called "Away Mode" that reacts to a change to this variable. The reaction would be do somethings via applescript in a new trigger event that would occur in X minutes. It would also have to delete any trigger events that exist to do this already.

Doesn't look like I can create trigger events via applescript so I'm not sure where to go now.

Posted on
Sun Feb 22, 2004 12:24 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

Can you pre-create the Time/Date Action that executes your AppleScript? If it was an "Every N minutes" Time/Date Action, then you could toggle it from a disabled to an enabled state. Whenever a countdown (Every N minutes) Time/Date action transitions from a disabled to enabled it resets the countdown timer.

Regards,
Matt

Posted on
Sun Feb 22, 2004 12:25 pm
dscottbuch offline
Posts: 90
Joined: Jan 19, 2004

(No subject)

Maybe I'm missing something but I would think the following applescript

Code: Select all
remove delayed actions for trigger "target trigger"
enable trigger action "target trigger" in X minutes*60



executed in a trigger action which activates on the change of the variable "lastInsideMotion" would work.

Each motion trigger could simply write the date to the variable using the applescript

Code: Select all
 set value of variable "lastInsideMotion" to (current date a string)


which would also tell you the last time motion was detected.

This can be done for each trigger action or device.

Posted on
Sun Feb 22, 2004 1:35 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

I've got it working, but got Indigo crashing as well.

I've got on trigger that is activated by a variable change called "Set Away mode" It has this embeded applescript:

Code: Select all
   if value of variable "HouseOccupied" is true then
      disable trigger action "Initiate Away Mode"
      enable trigger action "Initiate Away Mode"
   else if value of variable "HouseOccupied" is false then
      set value of variable "HouseOccupied" to true
      SetSetpoint("H", (value of variable "HeatingOccupiedTemp"))
   end if


I've got a date/time trigger set for 45 minutes called "Initiate Away Mode". It has the following embedded applescript:

Code: Select all
SetSetpoint("H", (value of variable "HeatingAwayTemp"))
set (value of variable "HouseOccupied") to false


After a motion detector fires Indigo will crash. When I restart i will see that the "Initiate Away Mode" trigger will have the new date/time stamp on it.

Posted on
Sun Feb 22, 2004 1:43 pm
dscottbuch offline
Posts: 90
Joined: Jan 19, 2004

(No subject)

question:

If you put the applescript in an external script and run it manually does Indigo crash or does applescript crash?

If you remove the SetSetpoint does it crash?

Posted on
Sun Feb 22, 2004 1:45 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

Hi Greg,

Are you running Indigo 1.3.2? I finally pushed this out of beta status to the release download (on the download web page). I fixed some AppleScript problems in the last couple of dot releases.

Regards,
Matt

Posted on
Sun Feb 22, 2004 2:42 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

It was doing it in an external applescript as well. i have 1.3.0, I will download the latest and let you know.

Posted on
Sun Feb 22, 2004 3:04 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

Downloaded the latest version. Nice icon by the way :)

--[url=applescript://com.apple.scripteditor/?action=new&script=tell%20application%20%22Indigo%22%0A%09if%20not%20(variable%20%22HouseOccupied%22%20exists)%20then%0A%09%09make%20new%20variable%20with%20properties%20%7Bname%3A%22HouseOccupied%22,%20value%3A%22true%22%7D%0A%09end%20if%0A%09if%20(value%20of%20variable%20%22HouseOccupied%22)%20is%20true%20then%0A%09%09disable%20trigger%20action%20%22Initiate%20Away%20Mode%22%0A%09%09enable%20trigger%20action%20%22Initiate%20Away%20Mode%22%0A%09%09log%20%22Reset%20away%20mode%20date%2Ftime%20trigger%20for%2045%20minutes%22%0A%09else%20if%20(value%20of%20variable%20%22HouseOccupied%22)%20is%20false%20then%0A%09%09set%20(value%20of%20variable%20%22HouseOccupied%22)%20to%20true%0A%09%09SetSetpoint(%22H%22,%20(value%20of%20variable%20%22HeatingOccupiedTemp%22))%0A%09end%20if%0Aend%20tell]Click here to open this script in a new Script Editor window[/url].

tell application "Indigo"
     if not (variable "HouseOccupied" exists) then
          make new variable with properties {name:"HouseOccupied", value:"true"}
     end if
     if (value of variable "HouseOccupied") is true then
          disable trigger action "Initiate Away Mode"
          enable trigger action "Initiate Away Mode"
          log "Reset away mode date/time trigger for 45 minutes"
     else if (value of variable "HouseOccupied") is false then
          set (value of variable "HouseOccupied") to true
          SetSetpoint("H", (value of variable "HeatingOccupiedTemp"))
     end if
end tell



It doesn't crash Indigo but it doesn't disable or enable anything. It also doesn't make the log entry.

Posted on
Sun Feb 22, 2004 4:23 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

This is an AppleScript variable casting problem caused by the fact that variable values from Indigo are always returned as strings.

Change this line:
  if (value of variable "HouseOccupied") is true then
to:
  if (value of variable "HouseOccupied" as boolean) is true then

This one from:
  else if (value of variable "HouseOccupied") is false then
to:
  else if (value of variable "HouseOccupied" as boolean) is false then

And this one from:
  SetSetpoint("H", (value of variable "HeatingOccupiedTemp"))
to:
  SetSetpoint("H", (value of variable "HeatingOccupiedTemp" as integer))

Regards,
Matt

Posted on
Sun Feb 22, 2004 4:32 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

Matt, thanks for your help. but still having problems. The event log looks like this:

Code: Select all
tell application "Indigo"
   exists variable "HouseOccupied"
      true
   get value of variable "HouseOccupied"
      "true"
   disable trigger action "Initiate Away Mode"
      "Indigo got an error: Some data was the wrong type."


My script now looks like this:

--[url=applescript://com.apple.scripteditor/?action=new&script=tell%20application%20%22Indigo%22%0A%09if%20not%20(variable%20%22HouseOccupied%22%20exists)%20then%0A%09%09make%20new%20variable%20with%20properties%20%7Bname%3A%22HouseOccupied%22,%20value%3A%22true%22%7D%0A%09end%20if%0A%09if%20(value%20of%20variable%20%22HouseOccupied%22%20as%20boolean)%20is%20true%20then%0A%09%09disable%20trigger%20action%20%22Initiate%20Away%20Mode%22%0A%09%09enable%20trigger%20action%20%22Initiate%20Away%20Mode%22%0A%09%09log%20%22Reset%20away%20mode%20date%2Ftime%20trigger%20for%2045%20minutes%22%0A%09else%20if%20(value%20of%20variable%20%22HouseOccupied%22%20as%20boolean)%20is%20false%20then%0A%09%09set%20(value%20of%20variable%20%22HouseOccupied%22)%20to%20true%0A%09%09SetSetpoint(%22H%22,%20(value%20of%20variable%20%22HeatingOccupiedTemp%22%20as%20integer))%0A%09%09log%20%22House%20is%20not%20occupied%22%0A%09end%20if%0Aend%20tell]Click here to open this script in a new Script Editor window[/url].

tell application "Indigo"
     if not (variable "HouseOccupied" exists) then
          make new variable with properties {name:"HouseOccupied", value:"true"}
     end if
     if (value of variable "HouseOccupied" as boolean) is true then
          disable trigger action "Initiate Away Mode"
          enable trigger action "Initiate Away Mode"
          log "Reset away mode date/time trigger for 45 minutes"
     else if (value of variable "HouseOccupied" as boolean) is false then
          set (value of variable "HouseOccupied") to true
          SetSetpoint("H", (value of variable "HeatingOccupiedTemp" as integer))
          log "House is not occupied"
     end if
end tell


Edit: i got it, changed it to time date action from trigger.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 25 guests