Script to increment variable with timing?

Posted on
Thu Jul 27, 2017 6:12 pm
FlyingDiver offline
User avatar
Posts: 7216
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script to increment variable with timing?

Different Computers wrote:
How can I round it off in the script? I'm starting to research this, but I worry about breaking the script.


If it doesn't want any decimal places, just convert it to an integer:

Code: Select all
# Calculate the new value originally set at darknessValue = (sourceDevice.sensorValue-1000) * -0.1

darknessValue = int((sourceDevice.sensorValue-1000) * -0.1)

# Set the value of the destination variable
indigo.variable.updateValue(1021324478, value=str(darknessValue))

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jul 27, 2017 6:48 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Script to increment variable with timing?

Perfect!!
Thank you.

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
Mon Jul 31, 2017 8:47 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Script to increment variable with timing?

What in the world am I missing??

Luminance reading = 1.04% This is sourceDevice.sensorValue.

Python code: darknessValue = int((sourceDevice.sensorValue-1000) * -0.1)

1.04 -1000 x -0.1 = 99.896

My darkness variable (which is derived from the python code above) equals 94

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
Tue Aug 01, 2017 5:09 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Script to increment variable with timing?

I'm not sure. When I run your code, I get 99. If my math is right, you need a sensorValue of around 60 to arrive at 94.

Also, I'd suggest doing the following which would be a little bit more precise:
Code: Select all
r_val = round((sourceDevice.sensorValue-1000) * -0.1)
i_val = int(r_val)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 3 guests