Weather Question


#21

Nice work, @dejavux2!

The only thing that bugs me a bit about piston “k087” is you are making 15 hits to the weather server to gather 7 data points…

The way I do it is to store the $twcweather into local variables, and then the rest of the piston only references those variables, instead of spamming the server a few milliseconds later for the same query. (globals are still ok to be set towards the end)

For example:

Set variable temp = $twcweather.conditions.temperature
Log info "Temp is {temp}"
Set variable @globalTemp = {temp}

Just my two cents.


#22

Good point… I will have it log the variables, instead of hitting $twcweather again.

Thanks!


#23

Weelll…

It will not successfully log using a GLOBAL because a global will not be updated until the last line of code is completed. Using locals are the only way around that


#24

Updated:


#25

Well done!!

This is a great example of how a more complex code can often streamline the execution. So often, people make the code in a way that is pleasing to the eye, without any regards to the way it processes later…


#26

If you prefer symmetry in your code, the above can be made to look “pretty”… but…
It’s important to note that the change below does not impact the execution in any way.
(it’s purely visual)

Set variable temp = $twcweather.conditions.temperature
Set variable wind = $twcweather.conditions.windSpeed
Set variable phrase = $twcweather.conditions.wxPhraseLong
Log info "Temp is {temp}"
Log info "Wind is {wind}"
Log info "Phrase is {phrase}"
Set variable @globalTemp = {temp}
Set variable @globalWind = {wind}
Set variable @globalPhrase = {phrase}

This variation means that changes to a variable is in three different “paragraphs”, but for me, it is actually easier to see the flow of code and catch any errors if there are any.

Your mileage may vary…


#27

So, I’ve updated my ‘Temperature and Weather Warings’ piston.

Alexa will now announce a Weather Alert.

Also, I had to change the IF of the third section, because if an alert went from ‘something’ to ‘something else’, I was not getting the message or Alexa would not announce.

For example: If the Weather Alert went from ‘NULL’ to ‘Severe Thunderstorm Watch’, I would get the message and Alexa would announce. BUT, if the Weather Alert went from ‘Severe Thunderstorm Watch’ to ‘Severe Thunderstorm Warning’, neither message would happen.

Also, I use ‘playAnnouncement’ for Echo Speaks, because it gives you the announcement tone before speaking. Using just ‘Speak’ did not result in the tone.