Getting a Weatherlink device temp into a variable as an int

Posted on
Mon May 03, 2021 9:00 am
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

ckeyes888 wrote:
Code: Select all
 Trigger                         Integer Fix Temp Out Python

# Getting the integer value
intValue = wsTempOut.getValue(int)   # 0 if it can't be converted
intValue = wsTempOut.getValue(int, default=10) # 10 if it can't be converted

indigo.variable.updateValue(1618693284, value=intValue)
   Schedule                        Davis Wind Direction/Gust Text Set Variable (delayed action)
   Schedule                        Integer Fix Temp Out Python

# Getting the integer value
intValue = wsTempOut.getValue(int)   # 0 if it can't be converted
intValue = wsTempOut.getValue(int, default=10) # 10 if it can't be converted

indigo.variable.updateValue(1618693284, value=intValue) (delayed action)


Carl, I have to say that your code block totally confuses me. Is that what's showing up in the Event log? Why is there Python code showing up in the Event Log?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon May 03, 2021 9:34 am
FlyingDiver online
User avatar
Posts: 5337
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Getting a Weatherlink device temp into a variable as an

ckeyes888 wrote:
Here’s the trigger to populate the wsTempOut variable.


Can you show the actions for this trigger?

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

Posted on
Mon May 03, 2021 2:35 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

Wow, now I’m even more confused. I have no idea why the python code is showing in the event log...or why it’s not the exact code
I’m executing in the action.

FlyingDiver: The code I’m executing in the action is the same posted above. Nothing else happening.

Carl

Posted on
Mon May 03, 2021 2:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

ckeyes888 wrote:
Wow, now I’m even more confused. I have no idea why the python code is showing in the event log...or why it’s not the exact code
I’m executing in the action.

FlyingDiver: The code I’m executing in the action is the same posted above. Nothing else happening.

Carl


Please take a screenshot of the Actions tab for that trigger. If it's a script, expand the window so we can see the whole script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon May 03, 2021 4:41 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

Here ya go.

Carl
Attachments
C48A63A9-D16C-47BA-B124-C2581F553E08.jpeg
C48A63A9-D16C-47BA-B124-C2581F553E08.jpeg (404.33 KiB) Viewed 358 times

Posted on
Mon May 03, 2021 5:02 pm
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

That has a different name than the trigger image you posted earlier - I'm still confused...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon May 03, 2021 6:43 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

The other one populates the wsTempOut variable.
The above removes the decimal...and has the condition it contain a “.”

Edit: Populating the wsTempOut directly from the device change, even with a delay on the script, yielded the worst result.

If there’s a better way to remove the decimal I’d sure like to try it.

Thanks,’

Carl

Posted on
Tue May 04, 2021 10:03 am
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

Ok, let's start over again since we seem to not be on the same page. Please post the Trigger and Action tabs for the trigger that populates your variable from the device state. Nothing else, just those two things. Please disable all other triggers that are trying to manipulate that variable.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 04, 2021 1:53 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

Here ya go.

Thanks,

Carl
Attachments
9ACC39CF-60F6-44C0-A7ED-5CAFB4CFE693.jpeg
9ACC39CF-60F6-44C0-A7ED-5CAFB4CFE693.jpeg (383.36 KiB) Viewed 304 times
3C08C9BF-A796-47D3-8A80-7ED63B6A6D2D.jpeg
3C08C9BF-A796-47D3-8A80-7ED63B6A6D2D.jpeg (197.62 KiB) Viewed 304 times

Posted on
Tue May 04, 2021 3:23 pm
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

Perfect. Now, without enabling any other triggers, let's change that action (don't add a new one, just change the existing one) to execute the following script:

Code: Select all
# Get the device
dev = indigo.devices["Davis Weather All"]  # You should really use the ID of the weatherlink device rather than the name here
# Get the temp and cast it to an integer
temp_as_int = int(dev.states["temp"])
# Update the variable with the new integer temp
indigo.variable.updateValue(1618693284, value=str(temp_as_int))


That should do exactly what you want in a single step. If it doesn't let us know and we'll figure out why it's not working.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 04, 2021 5:09 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

So far no misses. Thanks a bunch!
Curious to know what the difference is between the script I was using and yours?
I had tried my script in exactly the same way with mixed results.

Carl

Posted on
Wed May 05, 2021 10:12 am
jay (support) offline
Site Admin
User avatar
Posts: 16818
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Getting a Weatherlink device temp into a variable as an

First, the two approaches are quite different. You had 2 triggers: the first just copied the float value of the temp state into a variable, and the second attempted to set itself to an integer value of itself. On the surface, this might have worked, but because of how you defined the second trigger there could be some odd timing issues (every time you update a variable to a new value via the script, it would fire the trigger again, but only if the value actually changed). This is an overly complicated approach that might be prone to odd issues based on the timing of each trigger and the executions of their actions.

The second and more efficient approach is to just have 1 trigger that fires when the temp state value changes. The script gets the value of the temp state directly from the device, converts it to an integer, then assigns that to the variable. Only one trigger, no potential odd recursion or other side effects, etc.

It is most likely a bad idea to alter the value of a variable from a script that's firing on that same variable's value being changed. While Indigo will usually catch a recursion, it's possible that the timing of other things that are updating the variable with the timing of the self-change trigger will cause unexpected results. Best to keep it simple.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed May 05, 2021 6:47 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Getting a Weatherlink device temp into a variable as an

Makes perfect sense. Thanks for taking the time to explain it so well!

Carl

Who is online

Users browsing this forum: No registered users and 2 guests