Get value of device?

Posted on
Sun May 15, 2016 9:27 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Get value of device?

I really did try to figure this out from an example. Can't find one.

I'm trying to read the value of a Luminance sensor so I can (essentially) invert it for a dimmer value. I have a device called Luminance.

This compiles:

Code: Select all
set value of variable currLux to (get value of device Luminance)
set value of variable "darkness" to (currLux - 1000) * -0.1

But when I Run it I get "the variable Luminance is not defined."

I could work around this by making an Indigo variable called Lux or some such, but this seems more elegant--or it would if I had the syntax right!

So what have I got wrong here? I tried "get value of device name Luminance" and that didn't work either.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun May 15, 2016 11:09 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Get value of device?

AppleScript doesn't have access to sensor devices (nor any device types introduced in the past 5 years or so). As we've said in multiple other threads, AppleScript is legacy and hasn't been enhanced since we introduced Python in Indigo 5 (nor will it be).

The Python version of your script (written in out the long way to help with learning):

Code: Select all
# Get the source device - you can use the Copy Python Reference contextual menu to get the correct reference
sourceDevice = indigo.devices[SOURCEDEVICEIDHERE]

# Calculate the new value
newValue = (sourceDevice.sensorValue-1000) * -0.1

# Set the value of the destination variable
indigo.variable.updateValue(DESTINATIONVARIDHERE, value=str(newValue))


I think that's what you're looking to do. It could be shortened of course, but this shows you the explicit steps. Indigo Variables alway contain string values so that why we cast the new value to a string before setting it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun May 15, 2016 11:21 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Get value of device?

Thanks.

I do get that AppleScript is not the future, but I have much, much more familiarity with it than anything else, and it's also a skill I can make use of in my work if I get better at it. Moving over to Python is a tall bar to get to the same comfort level!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun May 15, 2016 11:28 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Get value of device?

also when I put what I think are the proper references in:
Code: Select all
# Get the source device - you can use the Copy Python Reference contextual menu to get the correct reference
sourceDevice = indigo.devices[450627924] # "Luminance"

# Calculate the new value
newValue = (d.sensorValue-1000) * -0.1

# Set the value of the destination variable
indigo.variable.updateValue(darkness, value=str(newValue))


on the "new value" line I get

Code: Select all
embedded script: global name 'd' is not defined


and in fact, I don't see any definition for anything called d.sensorvalue but then I don't know what the reference actually is.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun May 15, 2016 11:30 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Get value of device?

On that line, instead of "d" use "sourceDevice".

Image

Posted on
Sun May 15, 2016 11:36 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Get value of device?

"indigo.variable.updateValue(darkness, value=str(newValue))"

there is a variable named "darkness"

but I get

embedded script: global name 'darkness' is not defined"

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun May 15, 2016 11:54 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Get value of device?

ok.

I think I got it.

indigo.variable.updateValue(1021324478, value=str(newValue))

right format? It compiles. And is changing my variable!

Thanks!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 16 guests