Parsing an integer out of a string

Hello everyone,

Introductory post as this is my first day with SharpTools. I’m a legacy SmartThings/WebCore user and have started making the migration. Things are moving along good so far, but I’ve run into something I’m not sure how to replicate.

I have a weather tile that has a “wind” value. What I want to do is turn off a device if the wind speed gets above 15 MPH. The weather tile’s wind value is a string in the format “15MPH”. I don’t think I can really do a “> 15” comparison as it is a string. How would I go about doing this in SharpTools?

Thank you.

1 Like

Hi @Michael_Beatty - welcome to the community. You could use an Expression to parse the number part.

For example, you could use the replace() method to replace the "MPH" with "". You could then output that to a number variable and it would automatically coerce the string "15" to a number.

image

1 Like

Thank you for the reply. What would the trigger condition be? For the “wind” attribute, I’d think I would want to use a simple “changes”, but ShartTools doesn’t appear to have that. Would I just set it as changes and is not = “”?

Yeah, you could set it to changes and is not some value that it would never be (eg. a blank space).

Edit: there’s a feature request for a Generic Change Event if you want to cast a vote and/or bump the thread. :slight_smile:

1 Like

I would also add that since it sounds like you want to parse the value from a device that’s triggering the rule, you can use Context Variables:

So the expression might look like

replace($context.event.value, "MPH", "")
1 Like