FreePBX Weather Forecast


(Don) #1

I’m looking to set FreePBX up to give a three day weather forecast I would like for it not to use TTS and instead use the asterisk sound files. If you know how to do this please let me know.


(Simon Telephonics) #2

Did you succeed at setting up the time and temperature script you were previously asking about?


#3

You can get your weather from api.weather.gov, they have qute an extensive vocabulary, but it is finite start with https://api.weather.gov/glossary If your are 'mrican . For example at this point in time

curl -sf "https://api.weather.gov/gridpoints/XXX/NNN,NN/forecast"|jq -r '.properties.periods[0].detailedForecast'

I get

Sunny, with a high near 68. Northeast wind 10 to 15 mph, with gusts as high as 25 mph.

whereas

curl -sf "https://api.weather.gov/gridpoints/XXX/NNN,NN/forecast"|jq -r '.properties.periods[0].shortForecast'

I get

Sunny.

You have these as a basis

curl -sf "https://api.weather.gov/gridpoints/XXX/NNN,NN/forecast"|jq -r '.properties.periods[0]'



{
  "number": 1,
  "name": "This Afternoon",
  "startTime": "2021-03-26T12:00:00-07:00",
  "endTime": "2021-03-26T18:00:00-07:00",
  "isDaytime": true,
  "temperature": 68,
  "temperatureUnit": "F",
  "temperatureTrend": null,
  "windSpeed": "15 mph",
  "windDirection": "NE",
  "icon": "https://api.weather.gov/icons/land/day/skc?size=medium",
  "shortForecast": "Sunny",
  "detailedForecast": "Sunny, with a high near 68. Northeast wind around 15 mph, with gusts as high as 25 mph."
}





and the index, [0] - [13], covers morning and night periods for the next seven days.

curl -sf "https://api.weather.gov/gridpoints/XXX/NNN,NN/forecast"|jq -r '.properties.periods[]|.name+", "+.shortForecast'

renders

This Afternoon, Sunny
Tonight, Clear
Saturday, Sunny
Saturday Night, Clear
Sunday, Sunny
Sunday Night, Clear
Monday, Sunny
Monday Night, Mostly Clear
Tuesday, Sunny
Tuesday Night, Clear
Wednesday, Sunny
Wednesday Night, Mostly Clear
Thursday, Sunny
Thursday Night, Mostly Clear

You could use an associative array to map phrases to sound files and Alison hasn’t yet said them all :slight_smile:

Just for fun, I made my shell prompt look like

:clock1230::full_moon: :sunrise: 6:49am :city_sunrise: 7:10pm :thermometer: 64.89℉ :sweat_drops:39% :wind_face: 6.91(0):arrow_lower_right: :sun_with_face:1% clear sky
Sunny, with a high near 68. Northeast wind around 15 mph, with gusts as high as 25 mph.


(Don) #4

Would it be possible to have the api go out just three days and be more detailed?


#5

Of course, (are you reading along here ?) , use [0:5] as the index and each element you are interested in .

I suggest you man jq


(Don) #6

Is this correct for a 3 day detailed forecast?

curl -sf “https://api.weather.gov/gridpoints/XXX/NNN,NN/forecast”|jq -r ‘.properties.periods[0:5]|.name+", "+.detailedForecast’

How do I set this up in FreePBX do I need to put it in a dial plan?


#7

You need to find your own gridpoints , and ‘map’ the 0:5 back into an array
.properties.periods[0:5]|.[]|.name +", . . .

https://www.weather.gov/documentation/services-web-api

you could wrap it in a shell() command in your dialplan but you need to convert it to audio so an AGI script is a better option i think.


(Don) #8

Is there an example of how to map the 0:5 back into an array and a how to set up the AGI script.


#9

What is your zip code?


(Don) #10

79936


#11
curl -sf "https://api.weather.gov/gridpoints/EPZ/106,54/forecast"|jq -j  '.properties.periods[0:5]|.[]|.name +", the forecast is "+.detailedForecast+". " '

would produce

This Afternoon, the forecast is A slight chance of rain showers between 1pm and 2pm, then a slight chance of showers and thunderstorms between 2pm and 4pm. Mostly sunny, with a high near 64. West northwest wind around 18 mph, with gusts as high as 26 mph. New rainfall amounts less than a tenth of an inch possible.--Tonight, the forecast is Mostly clear, with a low around 41. North northeast wind 8 to 16 mph, with gusts as high as 23 mph.--Sunday, the forecast is Sunny, with a high near 70. East wind 5 to 9 mph.--Sunday Night, the forecast is Mostly clear, with a low around 43. East southeast wind 7 to 10 mph.--Monday, the forecast is Sunny, with a high near 79. South wind 7 to 12 mph.--

I would send that to a TTS of your choice because there are no reasonable sound files to use for that

curl -sf "https://api.weather.gov/gridpoints/EPZ/106,54/forecast"|jq -j  '.properties.periods[0:5]|.[]|.name +", the forecast is "+.shortForecast+". " '

of course more concise. if you want just temperature then

curl -sf "https://api.weather.gov/gridpoints/EPZ/106,54/forecast"|jq -j  '.properties.periods[0:5]|.[]|.name +" "+(.temperature|tostring)+" degrees " '

could get Alison to say “This Afternoon 64 degrees Tonight 41 degrees Sunday 70 degrees Sunday Night 43 degrees Monday 79 degrees” word by word


(Don) #12

Is there anyway to have Alison read that instead of TTS.


#13

No, but you could pay her :wink:


(Don) #14

I’m using the Pat Fleet voice and it has WX words.


#15

But not all of them :slight_smile:


(Don) #16

Is there a way I could record my own words to be played back.


#17

Of course, the glossary has 3129 possibles phrases


(Don) #18

How would I set it up for Alison to read

“This Afternoon 64 degrees Tonight 41 degrees Sunday 70 degrees Sunday Night 43 degrees Monday 79 degrees” word by word


#19

for i in $(curl -sf “https://api.weather.gov/gridpoints/EPZ/106,54/forecast”|jq -j '.properties.periods[0:5]|.[]|.name +" “+(.temperature|tostring)+” degrees " '); do echo $i;done

gets you the list of words to look up.

(Don) #20

So after I get the list of words do I use playback to have her read them?