Smart weather tile forecast temp,hourly,today,tonight


#1

1) Give a description of the problem
Hey,
I have smart weather tile added via the groovy ide and in webcore I want to be able to use this device to get the current temp,the forecast today and forcast tonight to be able to use this for my other pistons.

I made 3 variables “integer” and set them to
Integer hourly = weather device (temperature)
Integer forecastToday = weather device (forecasttoday)
Integer forecastTonight = weather device (forecastTonight)

They all returns 0, if I changed variable to dynamic they all return something like “forecast today is 20C with clear skies” etc
How can I convert this to integer? So I only get the temperature value so I can save it and use it?

Sorry cant post piston im on mobile, its very simple thou
Best regards
D


#2

To capture the “20”, I would probably use an expression like:
mid(fc,(indexOf(fc,"C ") - 2),2)

pic

… although in your case, replace "fc" with:
[Device exact name : attribute] … or:
[Device exact name : temperature]
etc…

This should catch the numbers; even if “today” occasionally returns “tonight”.


Note: If the first 18 characters are always the same, here is that code in it’s most basic form:

mid(fc,18,2)

pic

… once again, replace "fc" with ▲


#3

Hi,

Thank you kindly for your assistance, unfortunately I’m unable to understand how the syntax work to figure out why its not displaying correctly,
if I change fc to my variable which is set by device: attribute the evaluation is : 0% and not the temperature.

The last mid(placeholder for device,18,2) won’t work in my scenario as “forecast today is 20C with clear skies” was just a random thing I wrote up.

For today the actual forcast was this “Cloudy early with scattered thunderstorms developing this afternoon. High 22C. Winds SW at 10 to 15 km/h. Chance of rain 50%.”

The variation in the forecast makes it difficult for me to predict at where the xC value is.

Thank for helping! I appreciate it, best regards.
-d


#4

The forecast may vary in length but is always in the same pattern. Use indexOf to search for C.

Mine currently is Partly cloudy. High 81F. Winds light and variable.

The high/low temperature is always in its own sentence ending in the period. indexOf(varaible,‘C.’) will give you the location. Use that instead of 18. Subtract 2 to move the cut point back 2 digits (before the integer).

Same expression that @wcmore suggested earlier, just add the period.
mid(variable,(indexOf(variable,‘C.’) - 2),2)


The alternative would be to use the built in $twcweather data points.

#5

The code I gave you works perfectly with the sentence you gave me…

Honestly, I would rather not waste my time coding for something that does not exist…


With this sentence, you can add a period to my earlier expression:

mid(fc,(indexOf(fc,"C. ") - 2),2)


#6

Thank you for the explaination, this worked good and for showing me alternative way of getting the values.


#7

Hi, thank you kindly for taking your time, ill be more clear in the future so if you ever chime in again Ill hopefully wont waste your time coding for something thats made up.

But it gave me a lesson anyway so the second example might prove useful down the road. Thank you for providing options!

Best regards,
D


#8

Glad you found it helpful… I always try to teach when helping here…


For reference, here is the Wiki page with that expression.


#9

I can testify to that!!


#10

Ouch… I am a bit hurt that you gave the solution to someone else… when both of my posts were spot on.

(unfortunately, we can only choose one solution per thread)


#11

Wow really? I didnt know that. I selected both of you, since you both gave the right answer I needed. guess I need to pay more attention to detail :smiley: No need to get hurt, its an easy fix!

I’ll be a webcore forum and piston writing master in no time! coughs good thing is I’m learning new stuff from you everyday, its adding up. Thanks!


#12

It’s all good. A common newbie mistake…

Thanks for the correction!