Plugin: Say The Weather: Update 1.7 Released Feb 3, 2015

So I’ve been looking for a relatively minor project to help get me more accustomed to luup (basics of the syntax, table manipulation, parsing strings, etc.), my choice: plug-in of sorts called “Say The Weather”.

I also think this is a “cool” little project as it bridges the work of multiple authors to create a “new product”…it shows a glimpse of what the community can do from seemingly disparate projects. “Hmmmm…I want Vera to ‘tell me the weather…’ Hey…lolodomo has a Sonos plug in here…and hey…guessed has a Weather plug-in over here…” Neat-o.

Executive Summary: Hear a “natural language” weather report from your Sonos system, DLNA Device, or Imperihome device based on data points gathered from the Wunderground Weather app.

The guiding principals for this plug-in:

  1. Require as little “set-up” as possible and be fully functional.
  2. Make almost all parameters of the SayTheWeather action optional.
  3. Allow an optional certain degree of end-user customizability with the phrases used when creating the weather statement.
  4. Support US and Metric units, for both input parameters and the output statement.

The following apps are needed to make full use of SayTheWeather functionality:

  1. REQUIRED: Wunderground Weather App Versions 1.5 and later of SayTheWeather requires version 1.58 or later of the Wunderground Weather App.

The following are optional render targets. Without at least one render target, you won’t be able to actually hear an audible announcement. You can still generate a text weather statement, however:

  1. OPTIONAL: Sonos App
  2. OPTIONAL: DLNA App
  3. OPTIONAL: Imperihome App

If you are using a render target, you’ll want to make sure that the basic Text to Speech functionality is working prior to trying SayTheWeather.

Vera Version Compatibility: This has been tested with UI7 and UI5. (UI5 for versions 1.7 and later.)

To install: (Install the latest version directly from your Vera via the App Store).

Setup
:
3) Custom UI tabs have been created to manage the default values for the app as well as weather phrases and limits. They are slightly different depending on the UI version of Vera that you are running:
UI7
a) Defaults
b) Weather Alerts
c) Condition Phrases (1) – (Manage and test phrases for first 10 weather conditions)
d) Condition Phrases (2) – (Manage and test phrases for second 10 weather conditions)
e) Temperature Phrases – Manage and test temperature phrases and limits
f) Wind Speed Phrases – Manage and test wind speed phrases and limits

 [u][b]UI5[/b][/u]
 a) Defaults
 b) Weather Alerts
 c) Conditions --  Manage and test phrases for all 20 weather conditions phrases)
 e) Temperature  -- Manage and test temperature phrases and limits
 f) Wind  -- Manage and test wind speed phrases and limits

More details on using the are found in this post.

The “SayTheWeather” action is implemented in the “urn:joeyd-com:serviceId:SayTheWeather1” service. You can call on this action with the advanced scene editor in UI7, or with luup code. The complete syntax of the luup call is:

luup.call_action("urn:joeyd-com:serviceId:SayTheWeather1","SayTheWeather",
       {DontSay = "",
         RenderTargetID= "",
         PrefixStatement="",
         SuffixStatement="",
         IncludeLocation="",
         IncludeCurrentConditions="",
         IncludeForecasts="",
         IncludeAlerts = "",
         Volume="",
         SonosZone="",
         SonosSameVolumeForAll="",
        }
,[DeviceNumber])

Note: DeviceNumber is the device number of your SayTheWeather device…NOT your sonos, DLNA or Imperihome devices.

Technically, all of the parameters are optional. SayTheWeather will look to your default values (on your “Defaults” tab) to use for any parameters that you omit. This way, you can define your own default values up front and then if desired omit them from the action statement. Here are the parameters defined for the SayTheWeather action:

DontSay=“true/false” If DontSay is “true” Sonos is not called on. The weather announcement text is simply written to the
RenderTargetID: The Device ID of the render target. (Imperihome plugin Device ID, or DLNA plugin Device ID…not used for Sonos)
CompleteWeatherStatement state variable and the text is displayed in the “control” tab.

PrefixStatement = “[any text]”. If supplied, this text is read prior to the rest of the weather announcement.
SuffixStatement = “[any text]”. If supplied, this text is read after the rest of the weather announcement.
IncludeLocation=“true / false”. If true, the location of the weather station is announced.
IncludeCurrentConditions=“true / false”. If true, the current conditions are announced.
IncludeForecasts=“01” Specifiy which (if any) forecasts to include. (See below for further explanation).
IncludeAlerts: “changes”,“all”, or “none”. Specifies which weather alerts to include in the announcement. “changes” means that any alert that has either never been spoken, or has changed since it has last been spoken will be included in the announcement.
Volume= [number form 1 to 100]. If specified, sets the volume for the weather announcement. Imperihome does not currently support volume, so the announcement will be played at your device’s current setting.
SonosZone=“[Comma delimited Zone names, or ‘ALL’]” Specifies which sonos zone(s) to play the announcement on.
SonosSameVolumeForAll=“true/false”. If true, instructs sonos to play all zones at the volume specified by the SonosVolume.

And here’s how it all works…This is a sample of the output…a Weather Announcement:

Good morning! Here's the local weather from Shongum, in Randolph, New Jersey. Presently, we are experiencing cloudy conditions with the temperature a very cold 31 degrees. There is a light breeze around 3 miles per hour gusting to a moderate breeze around 15 miles per hour. For the immediate forecast we are expecting partly cloudy skies with very cold temperatures ranging from 28 to 34 degrees. Expect a light breeze around 5 miles per hour. For tomorrow's forecast we are expecting partly cloudy skies with very cold temperatures ranging from 28 to 38 degrees. Expect a light breeze around 5 miles per hour. There is 1 weather alert to report. The first alert is new. A winter weather warning is currently in effect until 7:00 PM tonight. Have a nice day!

The weather announcement is composed of 6 “statements”, in this order (though each of these statements can be turned off depending on the parameters when you call the action):

[prefix] [location] [current conditions] [forecasts][alerts] [suffix]

Here is the luup.call that created the sample announcement:

luup.call_action("urn:joeyd-com:serviceId:SayTheWeather1","SayTheWeather",
       {PrefixStatement="Good Morning!"
         SuffixStatement="Have a nice day!"
         IncludeLocation="true",
         IncludeCurrentConditions="true",
         IncludeAlerts = "ALL",
         IncludeForecasts="01"
        }
,[DeviceNumber])

The prefix and suffix (if supplied) are simply passed to the beginning and of the weather announcement. Because IncludeLocation is “true”, the statement about the location (“Here’s the weather from…”) was included. Because IncludeCurrentConditions is “true”, the “Presently…” statement was included that describes the current conditions.

The IncludeForecasts parameter works a little differently. It is a string of digits that represent which forecasts you want to include (if any) in the weather announcement. These digits correspond to the Weather plug-in’s forecast values. Typically 0 refers to the immediate forecast (today), 1 corresponds to tomorrow, etc. Currently the weather plug-in supports forecasts 0-3. The exact nature of what the numerals represent depend on the weather station you are reporting from. (As does whether or not there is data available for any / all of them).

Example: to only include the immediate forecast (0) and tomorrow’s forecast (1), the IncludeForecasts parameter should be “01”. If you want the forecast only for the “day after tomorrow”, the parameter is “2”. To hear forecasts for all available days, the parameter is “0123”, and so on.

The “Sonos…” parameters are passed to the Sonos plug-in to address the following: “on what zones you want to hear the announcement, at which volume(s), using which TTS engine, and in what language”. For details on how to construct these parameters, please see the Sonos plug-in page. You can specify default values for all of these.


Default Values and Personal Customization of the Weather Statement Phrases:

For an explanation of the UI to manage the default values and phrase customization, see this post here.

Automatic Alerts
SayTheWeather’s weather information is updated automatically whenever the Weather Apps data refreshes. If new weather alert information is received, you can elect to have SayTheWather immediately announce the alert. Refer to this image to go along with the following instructions for alerts:

Default Alert Behavior When Saying The Weather:
This option pertains to the standard weather announcement and how alerts are handled by default. If you choose “ALL”, then all active alerts are read with the weather announcement. “CHANGES” indicates that only those alerts that are new, or have changed since the last time they were read are included. “NONE” indicates that alerts are not to be read with the weather statement.

Auto Alerts If enabled, SayTheWeather will automatically announce weather alerts when they come in, pending active hours.

Active Hours If auto alerts are enabled, they will be said aloud as long as the current time is within the active hours you specify. If an alert occurs during quiet hours, it will be announced automatically when the next active hours start. For example, suppose your active hours are between 7:00 AM and 9:00 AM and again from 5:00 PM to 10:00 PM. If an alert comes in at 2:00 AM, it will not be announced until 7:00 AM.

Changelog:

Dec 21, 2014: 1.0 Released

Dec 22, 2014: 1.1 Released:
Fixed conversion issue. Will also now initialize based on the units selected in in the Weather App
Fixed weather location statement being placed before prefix statement.
Added simplistic JSON file which appears may be required with the latest VERA firmware released (1.7.481) if you want to see the information within the “standard” tabs like “advanced”…

Dec 31, 2014: 1.2 Released:
Fixed an additional conversion issue.
Added UI to enable much easier management and testing of phrases and default settings.
Added button to default device that “Says The Weather” with the default settings set by the user.
This version was approved for App Store release and can be installed from the app store as of Jan 5, 2015.

Jan 19, 2015: 1.5 Released:
Added support for Weather Alerts
Fixed an issue affecting those with temperature or humidity sensors that were not related to the weather app.
Fixed an issue when you tried to say an alert / weather to a sonos zone that was not set-up as a device. This is no longer required.

Feb 3, 2015: 1.7 Released:
Added support for UI5
Added support for DLNA and Imperihome render targets.

Feb 10, 2015: 1.8 Released:
Fixed periodic “chirping” issue with Sonos when automatic alerts were enabled but there were no alerts to be said.

JoeyD - one of your “metric friends” here ;D

Plugin seems to be working fine with a couple of hacks here and there, so thanks for the effort !!

Here is a metric set up:

T_MIN_DEFAULT[1]="-273"  --"frigid"
T_MIN_DEFAULT[2]="-10"   --"extremely cold"
T_MIN_DEFAULT[3]="0"     --"very cold"
T_MIN_DEFAULT[4]="5"     --"cold"
T_MIN_DEFAULT[5]="10"    --"chilly"
T_MIN_DEFAULT[6]="15"    --"cool"
T_MIN_DEFAULT[7]="20"    --"pleasant"
T_MIN_DEFAULT[8]="25"    --"warm"
T_MIN_DEFAULT[9]="30"    --"hot"
T_MIN_DEFAULT[10]="35"   --"very hot"
T_MIN_DEFAULT[11]="40"   --"extremely hot"
W_MIN_DEFAULT[1]="0"    --"calm winds"
W_MIN_DEFAULT[2]="5"    --"a light breeze"
W_MIN_DEFAULT[3]="20"   --"a moderate breeze"
W_MIN_DEFAULT[4]="40"   --"a strong breeze"
W_MIN_DEFAULT[5]="50"   --"near gale force winds"
W_MIN_DEFAULT[6]="60"   --"gale force winds"
W_MIN_DEFAULT[7]="90"   --"severe storm level winds"
W_MIN_DEFAULT[8]="120"  --"hurricane force winds"

You can get imperial or metric from the Weather Underground plugin, which could be used to set up the defaults:

local UNITS_METRIC = “1”
local UNITS_IMPERIAL = “0”

service=“urn:upnp-micasaverde-com:serviceId:Weather1”
variable=“Metric” value=“1”

so may be these functions wouldn’t be required? I’ve not looked at how they are used closely but I disabled them by returning RAW_VALUE rather than theOutput in each case.

convertTempToInput
convertWindSpeedToInput

convertTempToOutput
convertWindSpeedToOutput

I haven’t documented the units set up…sorry about that! Here’s how it should work.

Note…my code goes under the assumption that the Weather Underground app always stores the weather data in US units. (Do you know if that is correct or not?) I know there is a switch in the weather app to display in different units, but it looked to me like the data was always stored in US.

Having said that…

You shouldn’t have to “hack” the code for it to work. If you must, then I’m doing it wrong. :slight_smile:

There are 2 state variables in SayTheWeather plug in that you can manipulate for use with metric units. One variable dictates the units that the lower bound values are stored in. (So if you prefer to enter them in Metric, you can.) The other variable dictates what the weather is reported / said as. You can mix and match these. So if you don’t want to mess with changing the limits, you can simply change the reporting units, and you’re done.

  1. METRIC_or_IMPERIAL_params: if you change this variable to “METRIC,” then you must re-enter the values in KPH and degrees C. (As you did directly via code…but you can do this via the exposed state variables.)

  2. METRIC_or_IMPERIAL_say: if you change this variable to “METRIC”, then SayTheWeather will report the weather in metric units. Note, it does not matter what units the parameters are stored in. You can store your limits in US or Metric, and report the weather in US/Metric, independent of how you set the limits.

Does that make sense? I know a more proper UI to manage the variables would help. I’ll put one together over the next week or so. But again, you shouldn’t need to go into the code to use different units.

The “Convert…” functions are there to ensure the proper conversion of the data between how they are stored and how they are reported. So it makes sense that you “don’t need them” if you are reporting the weather in the same units that they are stored in.

FYI, I did find a bug that was causing the “station location statement” to be placed before the prefix statement. An updated implementation file is attached here to correct that.

(Edit…the latest version of all files will be attached to the first post.)

Looks like I goofed here. I just had another look at the weather app…and it does indeed change the values that are stored when the US/Metric switch is thrown. Looks like last time I hastily did not refresh my browser to see the changes. So I will have a little more work to do to ensure the units all work out properly. Thanks for catching that!

I’ll also follow your suggestion that upon initial creation of the device, I will make the defaults for SayTheWeather to coincide with whatever units they have chosen for the weather app, and use your conversions.

So word of warning to my metric friends (that is…anyone currently using the weather app with metric units)…I’ll need to update the plug-in to work properly.

Version 1.1 is attached to the first post which should address the issues raised by a-lurker, including the default metric set-up if your Weather App is currently set to metric units.

Note that you can independently change the units of the weather app at any time. SayTheWeather will handle all needed conversions. (So if you change the units of your weather app, you do not also need to change any parameters, or settings in SayTheWeather unless you want to.)

@a-lurker

“T_MIN_DEFAULT[1]=”-273" --“frigid”

You’re Canadian, aren’t you? Actually, I take that back, if you were Canadian then it should have read:

“T_MIN_DEFAULT[1]=”-273" --“beach weather”

i noticed in the weather underground app that it will accept weather alerts. Is there a way to make a scene trigger when a weather alert comes in and then say the weather statement over the sonos speaker.

That is not part of the current plug in, but I don’t see why I couldn’t code that in. I’ll put it on my to do list. :). I would think that you would want some kind of parameters around when to say the alert / weather though. For example, if an alerts comes in at 2:00 AM, you probably don’t want it said until some specified time.

Future Updates:

Just as an FYI, I am planning on adding the following enhancements…in this order:

  1. UI. I am going to add some tabs and customize the UI for saving phrases and default values. Included will be a “test” button so you can see how the weather announcement would look with end user changes to the phrases. Update: This is done and released with version 1.2.

  2. Add support for weather underground “alerts”.

  3. Add support to replace the other words in the announcement that are currently hard coded in English to allow users the possibility of constructing complete forecasts in another language

  4. add support for multiple phrases per setting. For example, be able to enter multiple descriptions for “snow”, and then have SayTheWeather randomly choose one. This is just to help things from being too monotonous.

EDIT: I changed the order in which I will tackle future updates. Adding support for multiple phrases per setting (now number 4) will be best handled with custom javascript UI rather than the limited “flash” type UI. Before I attempt that, I will need to educate myself on javascript and the Vera UI7 javascript API.

That is a great idea, kind of like a quiet time for the alert.

Version 1.2 has been published. (The first post in this thread has been updated.)

Aside from a couple bug fixes, the biggest news is that there is now UI to control the default settings and the customized phrases instead of having to navigate the “Advanced” tab manually. See attachments for screenshots of some of the UI Tabs. The following UI7 Tabs are now available to utilize:

EDIT: There seems to be an issue with the forums accepting new attachments. I will post the screenshots as soon as that issue is addressed by the forum administrators.

1) Control. (See screenshot.) The “control” tab has a single button to “Say The Weather” utilizing your default settings. The text of the announcement is also displayed. Note that on the dashboard, only the button is displayed, not the text.

  1. Defaults : (see screenshot.) This is where you can set the default settings for the Say The Weather app. If you omit any arguments from your Luup “call_action” call, (or the Advanced Editor in the scene creator), Say the Weather will look to these default values to use. The UI is self explanatory for most items. Note that when you first install Say The Weather, defaults are pre-populated: the units are based on the units (US or Metric) that have been specified in your weather app. Some comments:
    a) “Say forecasts” is a string of numbers specifying which (if any) forecasts to include in the announcement. For example, “0” indicates to say only the current (today’s) forecast. “01” specifies the current and tomorrow’s forecast is to be included, etc.
    b) Do Not Say: If “true”, then the announcement will not be made audibly over Sonos. Only the text of the announcement will be generated.

  2. Condition Pharses : (see screenshot). There are two tabs to manage the condition phrases. (10 conditions on each tab). Here you specify the “phrase” to be used with condition.
    a) When making changes, fill in the text boxes for any changes you want to make and then press the “Save Changes” button. (any text boxes that you leave blank will leave the existing phrase unchanged when you click “Save Changes”.
    b) You can fill in values in the Test Phrase section and click on the “Test” button to see how your phrases will look when incorporated into a weather announcement.

  3. Temperature Phrases: (see screenshot). Works similarly to the condition phrases, only in addition to changing the phrase, you can also change the limit at which that phrase goes into effect. (For example, you can make the phrase “sweltering hot” apply to temperatures at or above 98 degrees if you wish. There are 11 temperature phrases / set points you can modify.

  4. Wind speed phrases. Works the same way as temperature phrases, only there are 8 phrases / set-points to modify.

By changing the values of the condition, temperature, and wind speed phrases, it’s possible to give your weather announcer a little “personality”. It can create weather statements such as:

Good morning! Here's the local weather from Shongum, in Randolph, New Jersey. Presently, we are experiencing winter wonderland like conditions with the temperature a chilly but not paralyzing 31 degrees. There is a light breeze around 3 miles per hour. For the immediate forecast we are expecting wonderfully clear skies with almost spring like temperatures ranging from 40 to 50 degrees. Expect "hold on to your hat winds" around 20 miles per hour. Have a nice day!

I have version 1.2 currently pending approval for the mios app store. Not sure how this all works since the current app store is for UI5 and I have UI7…but we’ll see if it gets approved.

Version 1.2 has been officially released and is now available from the app store.

Version 1.3 is not far behind and will incorporate severe weather alerts.

Just a few general comments on alerts and how they will work. (And attached are a couple screenshots from the Weather Alert set-up tab, and the control tab.)

  1. Alerts will be defined by the alert “phenomenon type” and the “significance.” For example, a “Winter Weather Warning” is an alert that is composed of the phenomenon “Winter Weather” and “significance” of “Warning.”

  2. The complete details of the alert can be paragraphs long. While this information is gathered in the weather app, I will NOT be passing that data to be “said” over sonos. It would take enos to say and would drive you mad. :slight_smile: So the alert you hear will be essentially something like “There are 2 weather alerts to report. The first alert is new. A winter weather warning is currently in effect until 7:00 PM tonight. The second alert is an update. A wind chill advisory is currently in effect until Tuesday at 8:45 AM.”

  3. The goal is to only provide audible alerts once when the alert is first issued, and then only if and when the significance changes. (For example, from an “advisory” to a “warning.”). I will not have the app make an audible announcement if only the timing changes. (Though I may ultimately give the user the option to enable this.)

  4. If an alert is issued during “quiet hours” or while you have automatic alerts disabled, it will be spoken once quiet hours are over or you enable automatic alerts (assuming the alert is still in effect.)

  5. You will be able to hear “all” of the alerts that are currently in effect at any time with a luup command or via a button on the control dashboard.

The coding for all of the above is in place with exception for the “quiet hours”. If anyone has suggestions on how they would like to see that implemented, let me know. I am considering the following:

  1. Tie it to the concept of UI7 “modes” (Home / Away / Night / Vacation). (Allow the user to specifiy which modes to remain “quiet.”) Though since I don’t believe UI5 utilizes the concept of modes, I’m probably not going to go this route.

  2. Specify 2 or 3 time periods per day to be “active”. For example: Active from 7:00 AM to 10:00 AM and 3:00 PM to 10:00 PM.

  3. Any other suggestions?

I get a communications error every time I try and use this any ideas how to fix that?

Before we try and troubleshoot can you verify:

  1. Are you using UI5 or UI7?
  2. Version of Sonos plug-in that you have installed.
  3. Version of Wundergroud Weather app you have installed.
  4. Without using “Say the Weather”, you can successfully use the text to speech feature of the Sonos plug-in?

Thanks!

[quote=“JoeyD, post:16, topic:184835”]Before we try and troubleshoot can you verify:

  1. Are you using UI5 or UI7?
  2. Version of Sonos plug-in that you have installed.
  3. Version of Wundergroud Weather app you have installed.
  4. Without using “Say the Weather”, you can successfully use the text to speech feature of the Sonos plug-in?

Thanks![/quote]

I’m using UI5, sonos plug in version 1.3, weather underground version 1.57. The text to speech function is working correctly on all devices. When i click the button from the devices page it says lua failure. If i click it from within the device it says device communication failure.

Thanks. I have not tested this with UI5 but I’m not sure why that should make a difference I’m not home at the moment but I’ll put together a modified implementation file with some log writes that can help us find the issue.

One more question…when you click the button from within the device, does the text of the forecast appear to the right of the button? (Or do you just get the communication error message, and that’s it?)

Attached is an updated implementation file into which I have inserted several log writes throughout the Say The Weather action. Please apply this to your Vera. and report back on the log entries that you see after pressing the button. (You could just filter on levels 01, 02, and 50 and that should be sufficient something like

 tail -f LuaUPnP.log | grep "^01\|^02\|^50"

If none of this makes any sense to you (have never viewed log files before) let me know.