Announcement

Collapse
No announcement yet.

[VB.NET] my.Alert 0.2

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

    [VB.NET] my.Alert 0.2

    Discussion Thread

    Quick Note: While this post looks long and scary, this script is extremely easy to use. It's only this large because I included as much documentation as possible, so don't let the length of this post scare you away!

    About
    my.Alert is a small, easy to use, but powerful script which allows you to respond to changes on a website.

    It relies on regular expressions in order to narrow down the scope, which also means that there will be many uses for this script. Don't let this scare you away, see below for simple examples.

    In fact, it can also be used to do some basic screen scraping, all without having to know .NET programming or having to write a single line of code. You could store all this data in a device string, so you could incorporate that data into your touchscreen layouts.

    You can play sound files, trigger events, control devices and send e-mail notifications, all based on simple or complex changes. The script accounts for the dynamic nature of HTML, but if you aren't familiar with regular expressions, then check the resource links below, or ask for help in the discussion thread, and we'll help you build the right 'formula' (this is the fun part, so don't hesitate to ask for help at all!).

    Some example scenarios
    • Check school/event cancellations.
    • Watch your favorite stock prices.
    • Track price changes on your favorite eCommerce site.
    • Monitor hot deal forums for certain items.
    • Monitor CNN/MSN breaking news.
    • Watch eBay auctions, Etsy sales, etc.
    • Monitor changes to websites.
    • Check spaceweather.
    • Monitor prices of your favorite Android application.
    • Remote control your house via a secret keyword posted on a public forum/site.
    • Watch for changes to your UPS/FedEx tracking info.
    • Notify you when a large earthquake has happened in an area your family or friends live in.


    As you can tell, there is so much you can do, all without having to know a single thing about .NET programming.

    Download
    You can download the latest version here. Please do not post this script anywhere else, Doing so will make it impossible to track/support bugs/changes.

    Installation instructions
    1. Download the script (myAlert.vb.txt), and copy it to the Scripts directory. RENAME the script to myAlert.vb (remove the .TXT extension).
    2. Create a file in the Homeseer\Config directory named 'my.Alert.ini' (see below for more info about this file).
    3. Copy & Paste one of the example profiles below into the my.Alert.ini file.
    4. Create an event, and go to the Action tab.
    5. Use the 'Add Action' dropdown menu to select 'Run Script'
    6. In the Action List, go to the 'Existing Script' field, and select myAlert.vb from the list.
    7. Switch to 'Advanced View' (towards the right of the screen, red button) and use the following 'Optional Parameters':
      ("monitor","LOGLEVEL@PROFILE_NAME")
    8. Update & Save the event.
    9. You need to create a profile now, instructions can be found below.


    Script parameters
    Right now, there are only 2 script parameters. The LOGLEVEL, and the profile name. The LOGLEVEL parameter may contain one of the following values:
    • 0 = None
    • 1 = Errors
    • 2 = Info
    • 3 = Verbose (Use with caution, this level will generate large amounts of data!)


    Profile parameters
    The my.Alert.ini configuration looks like a typical INI file, and may contain many profiles. Each profile has multiple parameters:
    • URL: This is a required parameter. This should be the COMPLETE URL, including port number, etc. You can also use variables in this field, e.g.: {{String10}} inserts D10's device string, while {{Value10}} inserts D10's device value. This opens up many possibilities such as being able to specify a UPS tracking # via the web/touch interface, and the script will automatically pick it up and report changes. Currently only String and Value are valid variables.
    • RegExSearch: This is a required parameter. Specify the search pattern in the .NET RegEx format.
    • RegExReplace: Useful in some scenarios where you need grab the back referenced data.
    • Event: The name of the event to trigger.
    • Email: E-mail address to notify if there is a match.
    • DeviceString: Specify device code (e.g., Y11), and the device string will be updated.
    • DeviceToggle: Specify device code (e.g., Y11), and the device will be toggled.
    • DeviceOn: Specify device code (e.g., Y11), and the device will be turned on.
    • DeviceOff: Specify device code (e.g., Y11), and the device will be turned off.
    • Run: Execute command/batch file.
    • Speak: Make an announcement.
    • Media: Specify full path to the file you want to play (WAV, MP3, ...) when a change has occurred.
    • HTML: Set to 'True' (without quotes) if you want to preserve the HTML code. Set to 'False' by default.


    Regular Expressions Resources

    my.Alert Events


    my.Alert Event Configuration Example


    Version History

    version 0.4 (12132012): added support for {{:}} variables, added Run, Speak, DeviceOn, DeviceOff and DeviceToggle commands. Improved error trapping and minor bug fixes.
    version 0.3 (12102012): added HTML option, use when you want to grab & display HTML code (set to False by default).
    version 0.2 (12032012): added support for event control and implemented minor fixes.
    version 0.1 (11212012): created my.Alert.


    Discussion Thread
    Last edited by electron; December 14, 2012, 03:55 PM.
    HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
    (aka xplosiv)
    Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat

    #2
    Discussion Thread

    Version History

    12/17/2012: Added NFL Profile.
    12/14/2012: Updated MSN.com Breaking News profile.
    12/13/2012: Added UPS tracking profile.
    12/12/2012: Added USPS & Space Weather profiles.
    12/11/2012: Added CNN Breaking News profile.


    Profile examples

    Looking for more examples to add, so if you have any suggestions, please post them in the discussion thread, and I will add them here, thanks!

    Environmental

    Temperature
    Simple example showing how to retrieve a single value from weather.com, in this case the temperature. Enter your ZIP code on the site, then copy the url to the URL value.
    HTML Code:
    [weather]
    URL=http://www.b.weather.com/weather/right-now/New+York+NY+10001
    RegExSearch=<span class="wx-value" itemprop="temperature-fahrenheit">(?<temp>[^<]*)
    RegExReplace=temp
    Forecast
    Grabs the current forecast for your zipcode (the first line). Uses weather.gov to retrieve information. Go to the website, enter your zipcode, and grab the URL from the results page to use your local data. I personally use this profile to store the forecast in a device string, which then gets included in the 'good morning' routine.
    HTML Code:
    [forecast]
    URL=http://forecast.weather.gov/MapClick.php?lat=40.75368539999999&lon=-73.9991637&site=all&smap=1&searchresult=New%20York%2C%20NY%2010001%2C%20USA
    RegExSearch=<li class="row-odd"><span class="label">.*?</span>(.*)</li>
    RegExReplace=1
    DeviceString=Y11
    Lake temperature via USGS
    Retrieve the lake temperature from the USGS website.
    HTML Code:
    [laketemp]
    URL=http://waterdata.usgs.gov/ia/nwis/uv?06604200
    RegExSearch=degrees Celsius[\s\S]*instantaneous value:\s(?<temp>[0-9]{1,3}\.[0-9])\s
    RegExReplace=temp
    Earthquakes
    Monitor the USGS website for new major earthquakes. Extremely useful if you have family in earthquake prone areas.
    HTML Code:
    [earthquake]
    URL=http://earthquake.usgs.gov/earthquakes/feed/csv/1.0/hour
    RegExSearch=Region\s\S.*?,.*?,\?,".*?",.*?"(?<location>.*?)"
    RegExReplace=location
    Space Weather
    Retrieves space weather information from NOAA's space weather site. Note that this profile uses the HTML option, so you can display the NOAA table directly in your homeseer web interface.
    HTML Code:
    [spaceweather]
    URL=http://www.swpc.noaa.gov/SWN/index.html
    RegExSearch=(?<spaceweather><table width="360"[^>]*>[\S|\s]*</table>)
    RegExReplace=
    HTML=True
    News

    CNN Breaking News
    This profile will trigger when CNN.com posts breaking news on their website. A tribute to the original CNN Breaking News script I wrote many years ago
    HTML Code:
    [cnnbreakingnews]
    URL=http://www.cnn.com/.element/ssi/www/breaking_news/3.0/banner.html
    RegExSearch="content":\s*"(?<cnnbreakingnews>.*)",
    RegExReplace=cnnbreakingnews
    CNN Headlines
    Latest CNN headlines, HTML enabled, so you can display them via Homeseer Web.
    HTML Code:
    [cnn]
    URL=http://www.cnn.com
    RegExSearch=<div class="cnn_mtt1content">\s\S.*(?<cnnheadlines><ul class="cnn_bulletbin">.*)</ul>
    RegExReplace=cnnheadlines
    HTML=True
    MSN Breaking News
    This profile will trigger whenever MSN.com posts breaking news.
    HTML Code:
    [msnbreakingnews]
    URL=http://www.msn.com/
    RegExSearch=<div id="breaking".*BREAKING NEWS:.*?<p>(?<news>.*?)</p>
    RegExReplace=news
    Price Watch

    eBay
    Searches for the price listed on an eBay auction. Simply change the URL to the auction you wish to watch. NOT tested with Buy it now and other types of auctions.
    HTML Code:
    [eBay]
    URL=http://www.ebay.com/itm/SAGETV-HD200-MEDIA-STREAMER-/281032935879
    RegExSearch=<span id="w1-15-_bidPrice" itemprop="price">(.*?)</span>
    RegExReplace=
    Stock
    Simple example showing how to monitor a stock value. Go to Google Finance, enter your symbol and grab the URL (or change the stock symbol manually in the sample URL).
    HTML Code:
    [AAPL]
    URL=http://www.google.com/finance?q=NASDAQ:AAPL
    RegExSearch=<span id="ref_22144_l">(?<number>[0-9]+\.[0-9]{2})</span>
    RegExReplace=number
    Google Play Store
    Just another silly example showing how you can monitor specific data. In this case, when the price changes, an action would trigger.
    HTML Code:
    [SwiftKey]
    URL=https://play.google.com/store/apps/details?id=com.touchtype.swiftkey
    RegExSearch=<span class="buy-button-price">(?<price>\$[0-9]+(\.[0-9]{2})?)\s
    RegExReplace=price
    Miscellaneous

    IP Address
    Grab your IP address from whatismyip.com. *Works with most sites, including http://cocoontech.com/services/ip.php. *Useful in combination with the Email notification.
    HTML Code:
    [IP]
    URL=http://www.whatismyip.com/
    RegExSearch=(?<ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))
    RegExReplace=ip
    DeviceString=Y10
    Twitter
    Grab the most recent tweet from a twitter feed. *All you have to do is replace the URL value.
    HTML Code:
    [twitter]
    URL=https://twitter.com/NASAVoyager
    RegExSearch=<p class="js-tweet-text">(?<tweet>[\S\s][^<\/p].*)
    RegExReplace=tweet
    USPS Tracking
    Retrieve latest tracking status from USPS.com. All you have to change is the tracking # in the URL
    HTML Code:
    [usps]
    URL=https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=420130769102923868001021363615
    RegExSearch=input type="hidden" id="LabelSummaryDetails[0-9]*" value="(?<status>.*)"
    RegExReplace=status
    UPS Tracking
    Retrieve latest tracking status from UPS.com. All you have to change is the tracking # in the URL
    HTML Code:
    [ups]
    URL=http://wwwapps.ups.com/WebTracking/track?trackNums=1Z4F37F10336150844&track.x=Track
    RegExSearch=Last Location[\s\S]*?<dd>(?<status>[^<]*)
    RegExReplace=status
    NFL Team Scores
    Retrieve latest NFL scores from Yahoo.com. All you have to change is the team name in the URL
    HTML Code:
    [NFL]
    URL=http://sports.yahoo.com/nfl/teams/buf
    RegExSearch=<div class="team-matchup">[\S\s]*?</div>
    RegExReplace=
    Discussion Thread
    Last edited by electron; December 17, 2012, 01:28 PM.
    HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
    (aka xplosiv)
    Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat

    Comment


      #3
      Discussion Thread
      Last edited by electron; December 4, 2012, 07:55 AM.
      HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
      (aka xplosiv)
      Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat

      Comment


        #4
        Profiles Updated

        I posted the profile examples directly in this thread, and added a few more examples. If you have any interest in displaying/processing web based data with your Homeseer software, you really should give this a try!
        HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
        (aka xplosiv)
        Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat

        Comment


          #5
          Posted 0.4, which introduces variables (e.g, automatically track UPS packages using a certain device string as the source for the tracking #), more actions and I also included more example profiles.
          HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
          (aka xplosiv)
          Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat

          Comment

          Working...
          X