Announcement

Collapse
No announcement yet.

Announce Forecast

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Announce Forecast

    I think (but am not sure) that I posted these two scripts on Blade's message board back when we couldn't talk about him here.

    Enclosed in the attached ZIP are two VB.NET scripts that use the info from Blade's great BLweather plug-in. One simply announces the upcoming forecast via the HS TTS. I run this every morning before we all leave for work / school. The second runs in response to voice recognition, and will announce the forecast for whatever upcoming day you specify via voice. Both of these are modeled after similar scripts for the WeatherXML package that were written by Tom Caldwell and DMurphy here on the board (credit where credit is due!).

    If you happen to have a BetaBrite or similar sign and use my Snevl_bb package, the scripts also post the forecast on the sign for 80 seconds.

    The VR script requires that you put a voice command in the event, and I've provided that info in the header of the script. If I need better instructions I can probably try and write some up.

    Both scripts have been updated per Marty / nightwalker (see discussion below).

    Enjoy!

    Steve
    Attached Files
    Last edited by stevea; January 22, 2011, 06:58 PM. Reason: Fixed attachment

    #2
    Excellent, Steve - thanks...

    Do you happen to know if Blade's weather plug-in will capture warnings and watches to be spoken?
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      Originally posted by rmasonjr View Post
      Excellent, Steve - thanks...

      Do you happen to know if Blade's weather plug-in will capture warnings and watches to be spoken?
      I don't think so. As far as I know (and I haven't upgraded it in a while) Blade's plug-in just provides the forecast info for the next several days.

      Steve

      Comment


        #4
        Steve:

        Nicely done, I have wondered how I was going to get BLWeather to speak the forecast and lo and behold you've done it. I modified it slightly to allow BLRandom to use a random prelude just before the forecast and that's working well.

        I just wanted to say thanks for writing this. Speaking the forecast is one of the few things I'm still using WeatherXML for.
        Marty
        ------
        XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
        Playing with HS3 a bit but it's just play at this point.

        Comment


          #5
          Originally posted by nightwalker View Post
          Steve:

          Nicely done, I have wondered how I was going to get BLWeather to speak the forecast and lo and behold you've done it. I modified it slightly to allow BLRandom to use a random prelude just before the forecast and that's working well.

          I just wanted to say thanks for writing this. Speaking the forecast is one of the few things I'm still using WeatherXML for.
          Marty,

          Thanks for the kind words. Your BLRandom changes sound cool. I posted the source in hopes we could all benefit and maybe contribute (like the old HS days), so maybe you should post your version here. Or, maybe one of us could make it so that the use of BLRandom is configurable (I for one don't have BLRandom, and we shouldn't break the script).

          Steve

          Comment


            #6
            Originally posted by stevea View Post
            Marty,

            Thanks for the kind words. Your BLRandom changes sound cool. I posted the source in hopes we could all benefit and maybe contribute (like the old HS days), so maybe you should post your version here. Or, maybe one of us could make it so that the use of BLRandom is configurable (I for one don't have BLRandom, and we shouldn't break the script).

            Steve
            That's a good idea Steve. I have commented the exact change I made and have left in (but disabled) the line I replaced.

            PHP Code:
            '*************************************************************************
            '
            BL_weather_speak_vr.vb By Steve Anderson (aka Snevlstevea on the 
            '*      Homeseer message board)
            '

            '* Based on the data available, it will either announce the forecast for 
            '
            *    the current day and upcoming evening, or (if later in the daythe
            '*    forecast for the night and upcoming day.
            '

            '* To use: Simple create a new event with whatever trigger you want, and run
            '
            this script.
            '*************************************************************************
            Sub Main(Optional ByVal dummy as string = "")
             Dim fc_day as String = "1"
             Dim fc_nt as String = "1"
             Dim fc_date as String
             Dim fc_day_of_wk as String
             Dim fc_desc as String
             Dim fc_precip as String
             Dim fc_hi as String
             Dim fc_lo as String
             Dim fc_wind as String
             Dim fc_wind_dir as string
             Dim fc_nt_desc as String
             Dim fc_nt_precip as String
             Dim fc_nt_wind_dir as String
             Dim fc_nt_wind as String
             Dim nt as String = "tonight"
             Dim speech as String
             Dim nt_speech as String
             fc_desc = hs.DeviceStringByName("BLWeather Forecast 1 Day Description")
             If fc_desc = "N/A" Then
              fc_desc = hs.DeviceStringByName("BLWeather Forecast 2 Day Description")
              fc_day = "2"
             End If
             fc_nt_desc = hs.DeviceStringByName("BLWeather Forecast 1 Night Description")
             If fc_nt_desc = "N/A" Then
              fc_nt_desc = hs.DeviceStringByName("BLWeather Forecast 2 Night Description")
              fc_nt = "2"
              nt = "tomorrow night"
             End If
             fc_date = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Date")
             fc_date = expand_month(fc_date)
             fc_day_of_wk = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Day")
             fc_precip = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Day Percipitation")
             fc_hi = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Hi Temperature")
             fc_lo = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Low Temperature")
             fc_wind = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Day Wind Speed")
             fc_wind_dir = hs.DeviceStringByName("BLWeather Forecast " & fc_day & " Day Wind Description")
             fc_nt_precip = hs.DeviceStringByName("BLWeather Forecast " & fc_nt & " Night Percipitation")
             fc_nt_wind_dir = hs.DeviceStringByName("BLWeather Forecast " & fc_nt & " Night Wind Description")
             fc_nt_wind = hs.DeviceStringByName("BLWeather Forecast " & fc_nt & " Night Wind Speed")
            '
            --------------------------------------------------------------------------------------------------------------
            ' This added to allow the script to use a BLRandom Group at the beginning of the announcment
             '
            speech "The forecast for "
              
            speech hs.Plugin("BLRandom").RandomizeGroup("Weather Prelude")
            '--------------------------------------------------------------------------------------------------------------
             If fc_day = "1" Then
              speech = speech & ". . today, "
             Else
              speech = speech & "tomorrow, "
             End If
             speech &= fc_day_of_wk & ", " & fc_date & ", is "
             speech &= fc_desc & " with a " & fc_precip & " percent chance of precipitation. The low temperature will be "
             speech &= fc_lo & " degrees, and the high will be " & fc_hi & ". Wind will be out of the " & get_wind_dir(fc_wind_dir) & " at "
             speech &= fc_wind & " miles per hour."
             nt_speech &= "For " & nt & ", the forecast is " & fc_nt_desc & ", with a " & fc_nt_precip & " percent chance of precipitation. "
             nt_speech &= "Wind will be out of the " & get_wind_dir(fc_nt_wind_dir) & " at " & fc_nt_wind & " miles per hour. "
             If (fc_nt = "1") And (fc_day = "2") Then
              speech = nt_speech & " " & speech
             Else
              speech = speech & " " & nt_speech
             End If
             speech = speech.Replace("T-Storm","thunder storm")
             hs.speak(speech,TRUE,"*:*")
             If System.IO.File.Exists(hs.GetAppPath() & "\scripts\Snevl_bb.vben") Then
              hs.RunEx("Snevl_bb.vben","queue_msg","1|A|80|" & speech & "{transition=rotate}")
             End If
            End Sub
            Function get_wind_dir(ByVal dir_abrev as string) as String
             Dim N as Integer = dir_abrev.Length
             Dim i as Integer
             Dim ret_val as String = ""
             For i=0 To N-1
              Dim x as String = dir_abrev.Substring(i,1)
              If x = "N" Then
               ret_val = ret_val & "North "
              ElseIf x = "S" Then
               ret_val = ret_val & "South "
              ElseIf x = "W" Then
               ret_val = ret_val & "West "
              ElseIf x = "E" Then
               ret_val = ret_val & "East "
              End If
             Next
             Return(ret_val.Trim)
            End Function
            Function expand_month(ByVal date_str as String) as String
             date_str = date_str.Replace("Jan","January")
             date_str = date_str.Replace("Feb","February")
             date_str = date_str.Replace("Mar","March")
             date_str = date_str.Replace("Apr","April")
             date_str = date_str.Replace("May","May")
             date_str = date_str.Replace("Jun","June")
             date_str = date_str.Replace("Jul","July")
             date_str = date_str.Replace("Aug","August")
             date_str = date_str.Replace("Sep","September")
             date_str = date_str.Replace("Oct","October")
             date_str = date_str.Replace("Nov","November")
             date_str = date_str.Replace("Dec","December")
             Return(date_str)
            End Function 
            Marty
            ------
            XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
            Playing with HS3 a bit but it's just play at this point.

            Comment


              #7
              Marty,

              I don't really know anything about BLRandom, but from what you said I assume you have configured a "Weather Prelude" list of phrases or something? What I could do is have the script first look for the BLRandom plug-in. If it isn't there, it could just use my default prelude. If it is there, it could try and pull the "Weather Prelude" random phrase. If that is returned empty (which is what I would assume BLRandom would do if you called it with a group name it doesn't have), I could again go to the default.

              That way if someone either doesn't have BLRandom or hasn't set up a "Weather Prelude" group, the script would work as my original. But if the do have BLRandom set up with that group, it would do the random prelude.

              What do you think?

              Steve

              Comment


                #8
                That would be excellent, it would make a single script work for everyone without having to make adjustments. I assume that HomeSeer would send an error of some sort if it did not find either BLRandom or the proper BLRandom Group when called. i suppose you can account for that in the script?

                I use the he** out of BLRandom groups in my speaking events, it makes it so much nicer to not hear the same thing spoken all the time. It almost gives HomeSeer a bit of a personality.
                Marty
                ------
                XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
                Playing with HS3 a bit but it's just play at this point.

                Comment


                  #9
                  Homeseer doesn't throw an error of there is no matching Plug-in, but my script would have to check the return value. I know that part works.

                  I don't know what BLRandom does if you reference a group that doesn't exist. Can you check? For example, if you just change your "Weather Prelude" to "Weather Prelude2" without having a real Weather Prelude2 group, does it just return an empty string?

                  Steve

                  Comment


                    #10
                    Originally posted by stevea View Post
                    Homeseer doesn't throw an error of there is no matching Plug-in, but my script would have to check the return value. I know that part works.

                    I don't know what BLRandom does if you reference a group that doesn't exist. Can you check? For example, if you just change your "Weather Prelude" to "Weather Prelude2" without having a real Weather Prelude2 group, does it just return an empty string?

                    Steve
                    Sure, give me a few minutes and i'll do a quick test.

                    That was easy enough. I expected errors but there were none. The script simply skipped over and did nothing with the BLRandom portion and went right into the forecast. Since I had commented out your original that of course was not spoken either.

                    Here is the beginning of the forecast, from my log, that ran this morning earlier with BLRandom working

                    Speak: and now the weather. . today, Saturday, January 22,

                    And here is what it looked like when I used a BLRandom group that did not exist.

                    Speak: (*:*):. . today, Saturday, January 22
                    Marty
                    ------
                    XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
                    Playing with HS3 a bit but it's just play at this point.

                    Comment


                      #11
                      Ok then Marty. I've updated the attachment to the original post at the start of this thread to include new versions of both scripts with your change in them (and put you down as the author). I just noticed that I messed up and dated the version as 21-Jan, even though it is today.

                      Marty: Please try it and make sure it works as intended with BLRandom.

                      Steve

                      Comment


                        #12
                        Originally posted by stevea View Post
                        Ok then Marty. I've updated the attachment to the original post at the start of this thread to include new versions of both scripts with your change in them (and put you down as the author). I just noticed that I messed up and dated the version as 21-Jan, even though it is today.

                        Marty: Please try it and make sure it works as intended with BLRandom.

                        Steve
                        Hi Steve:

                        I downloaded and gave it a shot, unfortunately it didn't work, exactly. It was kind of a weird thing the BLRandom prelude phrase did get triggered, but it got triggered in the middle of the forecast between tonight and tomorrow's forecast, like this.

                        Speak: (*:*):For tonight, the forecast is Mostly Clear, with a 10 percent chance of precipitation. Wind will be out of the West North West at 9 miles per hour. forget those hacks on T.V. here's the real forecast. . . . tomorrow, Sunday, January 23, is Mostly Sunny with a 0 percent chance of precipitation. The low temperature will be 10 degrees, and the high will be 25. Wind will be out of the West North West at 16 miles per hour.

                        but it was pretty funny listening to it, I heard the wife laughing out in the kitchen while i was testing.
                        Marty
                        ------
                        XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
                        Playing with HS3 a bit but it's just play at this point.

                        Comment


                          #13
                          That does sound like it would be pretty funny.

                          Were you using the VR script, or the regular one?

                          Steve

                          Comment


                            #14
                            Originally posted by stevea View Post
                            That does sound like it would be pretty funny.

                            Were you using the VR script, or the regular one?

                            Steve
                            The regular one, I don't use VR at all.
                            Marty
                            ------
                            XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
                            Playing with HS3 a bit but it's just play at this point.

                            Comment


                              #15
                              Never mind. I forgot that if it is evening (so today's forcast is not valid) I swap the order and do the night (tonight) before the day. I'll fix it and repost.

                              Steve

                              Comment

                              Working...
                              X