View unanswered posts | View active topics It is currently Sat May 18, 2013 12:28 am



Reply to topic  [ 4 posts ] 
 Device status reading for triggers (Newbie) 
Author Message
User avatar

Joined: May 10, 2012
Posts: 205
Location: Newcastle Upon Tyne, England
Post 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!

_________________
Is it bad every time I mention my HA hobby to people they always think of this? http://www.youtube.com/watch?v=XaNuB52_Irc


Thu Aug 02, 2012 3:07 pm
Profile

Joined: Aug 09, 2010
Posts: 761
Location: CA
Post 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


Thu Aug 02, 2012 5:36 pm
Profile WWW
User avatar

Joined: May 10, 2012
Posts: 205
Location: Newcastle Upon Tyne, England
Post 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!

_________________
Is it bad every time I mention my HA hobby to people they always think of this? http://www.youtube.com/watch?v=XaNuB52_Irc


Fri Aug 03, 2012 1:05 am
Profile

Joined: Aug 09, 2010
Posts: 761
Location: CA
Post Re: Device status reading for triggers (Newbie)
Awesome! Glad you got it working. :D


Fri Aug 03, 2012 2:42 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.