Page 2 of 2

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

PostPosted: Mon May 03, 2021 9:00 am
by jay (support)
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?

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

PostPosted: Mon May 03, 2021 9:34 am
by FlyingDiver
ckeyes888 wrote:
Here’s the trigger to populate the wsTempOut variable.


Can you show the actions for this trigger?

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

PostPosted: Mon May 03, 2021 2:35 pm
by ckeyes888
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

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

PostPosted: Mon May 03, 2021 2:48 pm
by jay (support)
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.

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

PostPosted: Mon May 03, 2021 4:41 pm
by ckeyes888
Here ya go.

Carl

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

PostPosted: Mon May 03, 2021 5:02 pm
by jay (support)
That has a different name than the trigger image you posted earlier - I'm still confused...

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

PostPosted: Mon May 03, 2021 6:43 pm
by ckeyes888
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

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

PostPosted: Tue May 04, 2021 10:03 am
by jay (support)
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.

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

PostPosted: Tue May 04, 2021 1:53 pm
by ckeyes888
Here ya go.

Thanks,

Carl

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

PostPosted: Tue May 04, 2021 3:23 pm
by jay (support)
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.

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

PostPosted: Tue May 04, 2021 5:09 pm
by ckeyes888
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

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

PostPosted: Wed May 05, 2021 10:12 am
by jay (support)
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.

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

PostPosted: Wed May 05, 2021 6:47 pm
by ckeyes888
Makes perfect sense. Thanks for taking the time to explain it so well!

Carl