Convert a string into a Num?

Is there a way in RM to convert a string to a num? I want to use "chance of rain" ( chanceOfRain : 0), which is a string, in a > comparison. ie: if chanceofrain > 50 then don't water... Or do I need to write my first app?

Rule Machine can't do that on its own, but the driver (also) could. Is this a stock driver or a custom driver? Either way, if the value is only numeric, using a numeric data type on the driver side sounds like a better option than handling it on the app side, anyway. Basically, this would involve declaring the attribute as type NUMBER instead of STRING (or nothing at all, often seen in ported SmartThings code) and making sure that any events created to change it don't try to send strings. (You can still specify units for display purposes, which seems likely to me to work for 0-100% values. Does the attribute do anything besides this?)

You can use RM to first set a decimal variable from the string then use it in your comparison.

2 Likes

Learned something new! (Thanks!) I guess RM will try to be nice and convert for you:

image

That being said, I'm still curious what driver this is and if there's any reason it should need to be a string attribute in the first place.

1 Like

Its Cobra's WU driver. It's just parsing out WeatherUnderground data. Thanks for the tip at9.

Tagging @Cobra

I think there's a reasonable use case for the output being a number here - anyway to do this in the driver?

Can you elaborate on where to do this, please? Do you need a separate rule? I'm trying to read a Weather attribute also, but for MyEcobeeDevice. I cannot see how/where to use this variable set.