Parsing the result of a string value to use as an integer?


#1

1) Give a description of the problem
Trying to get something to trigger based on yesterdays solar generation value

2) What is the expected behavior?
Be able to use logic if yesterdays production is less than 15kwh then switch on the electric water heater in the morning

Thanks for any help!


#2

Yeah, just make it an Expression and convert the string into an Integer…

Something like this will do it.

Those two functions will first take the value and trim it down to just the numbers part:

left(StringValue,4)

You’ll end up with a string with “13.3” in it… Then:

Int(StringValue)

Will convert the string “13.3” into an integer value of 13

Then you can make your comparison and off you go.

Just substitute your device for the “StringValue” or first put your the return of your device into the StringValue… Either will work…but probably better to define it up top.


#4

So… this doesnt appear to be triggering… says that the piston does not subscribe to any events so will not run by itself…


#5

I’ve seen that issue before. Move the TIME trigger up to the first spot.


#6

This is not necessary since both int('12.563249kWh') and round('12.563249kWh') automatically discard the non-numeric suffix. Prefixes (e.g. round('$12.56')) are discarded as well. It’s safer to let those find the correct number than trying to split it out with left()


#7

Ive adjusted the order of the TIME trigger. Seems to remove that message. It does seem to be pulling the correct Solar production value… should I adjust the function?


#8

Might as well. That way you don’t have to worry about if you ever get a value like “16.0kWh” at any point.