Device status reading for triggers (Newbie)

Posted on
Thu Aug 02, 2012 3:07 pm
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Device status reading for triggers (Newbie)

Forgive the n00bness of my question..

I've been tearing my hair out trying to find a way of reading device states via AppleScript for use in a trigger. Ultimately what I’m trying to do is simplify 4 different triggers currently setup to read the status of a PIR sensor in the bathroom, (one to turn on during the day, one to turn off when the PIR sends the off signal, one to raise the brightness to 80% at night (from the 20% it runs at all night) and one to set it back to 20% when the PIR switches off). I’ve tried to create an AppleScript using if commands (rather than conditions) and i’ve had no problem reading variables, but when trying to get it to read device states i’m getting nowhere. Closest i’ve got so far is this:


if value of variable "BathroomLights" is "false" and value of device "Bathroom PIR Sensor" is "On" then
brighten "Bathroom Light" to 80
end if
if value of variable "BathroomLights" is "true" and value of device "Bathroom PIR Sensor" is "On" then
brighten "Bathroom Light" to 80
end if
if value of variable "BathroomLights" is "false" and value of device "Bathroom PIR Sensor" is "Off" then
brighten "Bathroom Light" to 0
end if
if value of variable "BathroomLights" is "true" and value of device "Bathroom PIR Sensor" is "Off" then
brighten "Bathroom Light" to 20
end if

but whenever i run that script i get:
Error script error: around characters 237 to 241
Error script error: Can’t get value of device "Bathroom PIR Sensor". (-1728)

I’ve trawled the forums trying to find information about device states rather than variable states, but what little i’ve found doesn’t seem to work. The device itself has three states, command = on/off, lastUpdated = date of last transmission, type = 0. I’m assuming i need to define it looking at the ‘command’ section, but nothing i’ve tried has come even close to working for that. I’ve kinda got a work around of setting a trigger to copy the status from the device to a variable, then base the script on the variable.. but i’ve found that only works if i delay the triggering of the script slightly.. and being a light it’s kinda useful for it to be switched on very quickly.. especially if i don’t want to stub my toe on the heavy bathroom scales!

Computer says no.

Posted on
Thu Aug 02, 2012 5:36 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Device status reading for triggers (Newbie)

durosity wrote:
Code: Select all
if value of variable "BathroomLights" is "false" and value of device "Bathroom PIR Sensor" is "On" then
brighten "Bathroom Light" to 80
end if
if value of variable "BathroomLights" is "true" and value of device "Bathroom PIR Sensor" is "On" then
brighten "Bathroom Light" to 80
end if
if value of variable "BathroomLights" is "false" and value of device "Bathroom PIR Sensor" is "Off" then
brighten "Bathroom Light" to 0
end if
if value of variable "BathroomLights" is "true" and value of device "Bathroom PIR Sensor" is "Off" then
brighten "Bathroom Light" to 20
end if

"value" is not a valid property of the "device" class. Try changing your if statements to something like...
Code: Select all
if value of variable "BathroomLights" is "false" and on state of device "Bathroom PIR Sensor" is true then
    brighten "Bathroom Light" to 80
end if

Posted on
Fri Aug 03, 2012 1:05 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Device status reading for triggers (Newbie)

It worked! I’m sure that was one of the options i tried last night, but didn’t have any joy with.. but regardless.. thanks, you’re a genius!

Computer says no.

Posted on
Fri Aug 03, 2012 2:42 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Device status reading for triggers (Newbie)

Awesome! Glad you got it working. :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests