Page 1 of 2

Change variable to integer (I think)

PostPosted: Tue Aug 15, 2017 8:43 am
by Gusten
Hi
I am using HTTPD plugin to report my weight from a Withing scale, and i get my weight in as a variable.

And i want to use this variable in a trigger as a condition "If variable is between xxx and xxx"

And this do not work, and i think its beacouse the variable is not an integer

Can this be and whats the easyest way to convert the variable to a integer? Or use this variable and convert to a new variable that i can use?

The variable is like this 85.81 so its all numbers with a dot and two decimals

Thanx

Martin

Re: Change variable to integer (I think)

PostPosted: Tue Aug 15, 2017 8:48 am
by FlyingDiver
Post the script you've got now and we'll tell you what needs to be fixed.

Re: Change variable to integer (I think)

PostPosted: Tue Aug 15, 2017 10:19 am
by Gusten
I actual don't have a script, I just used a indigo trigger and set a condition


Skickat från min iPhone med Tapatalk

Re: Change variable to integer (I think)

PostPosted: Tue Aug 15, 2017 12:02 pm
by FlyingDiver
I think the trigger condition code auto-converts, so that's not the issue.

I'm guessing the issue is that the number from the scale is in US floating point format (with a ".") and your European locale is causing Indigo to expect a "," as the floating point separator.

Re: Change variable to integer (I think)

PostPosted: Tue Aug 15, 2017 12:58 pm
by jay (support)
I'm not sure the number format is the issue. A simple way of testing it is to manually change the variable value to 85,81 (or whatever would cause the trigger to fire) and see if that works. My quick test here switching my preferred language to Swedish didn't seem to change how the number is used, though I'll admit I'm not fully versed in making my system completely localized.

Take screenshots of all 3 tabs in your trigger tabs (Trigger, Condition, Actions) so we can see how they're configured.

Re: Change variable to integer (I think)

PostPosted: Wed Aug 16, 2017 1:51 am
by Gusten
Hi

Here are the images, what you cant see in the images is that there is two zeros behing the dot

I tried to manual change the "httpd_withings" variable, but it wont fire

I altso tried to change the condition to between 87 and 89 without dots, and the change the "httpd_withings" variable to 88 still no fire?

//Martin

Re: Change variable to integer (I think)

PostPosted: Wed Aug 16, 2017 9:21 am
by jay (support)
Let's do some tests. First:

  1. Disable the trigger or schedule that's inserting the value of the device into the httpd_withings variable so it's not changing automatically
  2. Change the Condition to Always
  3. Change the value of cbweight to something other than "yellow"
  4. Change the value of httpd_withings to 85.0, be sure to tab out of the field (you should see the trigger fire and cbweight should change to yellow)
  5. Again change the value of cbweight to something other than "yellow"
  6. Change the value of httpd_withings to 86.0, be sure to tab out of the field (again you should see the trigger fire and cbweight should change to yellow)

If something didn't work, let us know which step didn't work. If everything worked, then:

  1. Change the Condition back to between 87 and 89 (shouldn't need to use the decimals)
  2. Change the value of cbweight to something other than "yellow"
  3. Change the value of httpd_withings to 87.5, be sure to tab out of the field (you should see the trigger fire and cbweight should change to yellow)
  4. Again change the value of cbweight to something other than "yellow"
  5. Change the value of httpd_withings to 86.0, be sure to tab out of the field (this time you shouldn't see the trigger fire and cbweight shouldn't change)

If something didn't work, let us know which step didn't work. If everything worked, then the trigger is configured correctly and should be working fine. Turn the trigger or schedule that's updating httpd_withings back on and watch it to see that its working correctly.

Change variable to integer (I think)

PostPosted: Sat Aug 19, 2017 2:39 am
by Gusten
Hi

Idid try to do what you told me, and its working when changing the variable manually

But the weird part is, that when the httpd plugin updates the variable, it do not trigger.

And if i let Httpd plugin update the value, and directly after change the variable manually it do not trigger either. It seems like i need to change the variable value to text and back to numbers to get it to trigger??

/Martin

Re: Change variable to integer (I think)

PostPosted: Sat Aug 19, 2017 8:52 am
by jay (support)
My guess is that there's something getting inserted into the variable value that's keeping Indigo from casting it to a number (extra spaces at the beginning or end, etc). Otherwise it would work (as you've proven by manually editing the value).

When the plugin updates the variable, edit the variable and select everything that's in the edit field and then paste it into a code tag in a reply.

To put it in a code tag, first click the Code button above the post edit field (in the Selection style bar), then paste in the value. It's important to get ALL of the variable value from Indigo in between the Code tags so we can see what's really in it.

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 1:18 am
by Gusten
Hi

Here is the latest variable, sent by httpd plugin

Code: Select all
 88.65


You were right there is a blank before the numbers, didn't see that :-)

When i remove the blank, its triggers.

Is there any easy way to remove that blank automatic, like with a small script or something

Thanx

/Martin

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 1:53 am
by howartp
The HTTPD plugin author needs to tidy that up so that blank spaces before and after are handled and removed.


Sent from my iPhone using Tapatalk Pro

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 4:02 am
by Gusten
I checked another variable that httpd sets from another IFTTT source and its altso have the blank before the variable. I will make a note on the httpd forum of this. And if anyone knows of a way to get rid of the blank in a variable please let me know

/Martin


Skickat från min iPhone med Tapatalk

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 5:24 am
by FlyingDiver
howartp wrote:
The HTTPD plugin author needs to tidy that up so that blank spaces before and after are handled and removed.


Not so fast there. The HTTPd plugin isn't adding that space. I'm not sure it should be removing it either. I'm very reluctant to have the HTTPd plugin arbitrarily changing data.

The IFTTT applet is sending the weight string with the leading zero, it appears. That's bad in this case, but might be required in other uses. The RIGHT answer is to get it to stop doing that, if at all possible.

I don't have any Withings devices, so I can't look at the IFTT applets to see what configuration options there are. Is it possible that the OP has inadvertently added that space to the URL string specified in IFTTT that's sending the data to Indigo?

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 5:28 am
by howartp
I never said you were adding it, but it's a perfectly appropriate suggestion to provide the option to remove it.


Sent from my iPhone using Tapatalk Pro

Re: Change variable to integer (I think)

PostPosted: Sun Aug 20, 2017 5:28 am
by FlyingDiver
Gusten wrote:
I checked another variable that httpd sets from another IFTTT source and its altso have the blank before the variable. I will make a note on the httpd forum of this.


I'm not getting any blanks in the variables I've set from IFTTT. Can you post an image of the IFTTT action you're using to send the variable(s) to Indigo?