Overview

Skill Level: Beginner

Automatic announcement of the local, airport or remote weather condition on a time basis (hourly) without calling - Hey Google or Alexa whats the weather here or at the Airport. This is part (1) of a couple of blogs around weather. Enjoy!

Ingredients

  • Raspberry Pi / or any Computer
  • Node-RED installed
  • Bluemix account
  • Bluemix space with Node-RED,IoT and TTS services
  • Personal Weather Station (optional)
  • Weather UnderGround / Darksky API Key

Step-by-step

  1. Objective

    I have a couple of goals with this project. First I wanted the Local and Airport weather boardcasted to ChromeCast/Alexa every hour automaticly without me prompting the devices. Secondly I needed a local and cloud Dashboard with the IoT plattform connection, so i could have a single view of temperature data of my sensors from different locations. As bounus I also wanted to use the ChromeCast/Alexa as Doorbell for my Appartment so I would be notified when somebody is at the door. And Lastly I want a IFTTT integration so that I can trigger manual weather accountments. At the end I like to save the temerature data especially the one of my local sensors and use Watson for some predictions.

    In this part we just focus on the local setup eg. getting the weather information and send it to Google/Alex and visualize the data in a Node-RED Dashboard maybe a little more lets see.

    Here an Overview about our Project

    Overview

    Short Overview Video

  2. Node-RED Setup

    For the 1st part we will need a Raspberry PI or any other computer – setup with nodejs/npm and Node-RED installed.

    You can find the installation procedure here.

    Once you got your PI with Node-RED ready make sure to note down your PI’s IPaddress. You will need also the IPAddress of your Cast Devices as well. Depending on your router you may want to assign static/fixed IP address of these devices. For more information google or check here.

    Fire up your Node-RED (best is to install it as a services). You will need to add some packages to the your Node-RED install. The plugins can be installed via the palette manager see Burger Menu on the top right corner of your Node-RED Editor (Manager Palette).

    Here the list of plug-ins which are used in the Node-RED flows and following Steps (there a lot of other plugins which work similarly –¬† if you like them better; you just need to adjust the flows if you decided to use a different plugin for Alexa or ChromeCast plugin for example). Here the list I used.

    1. node-red-contrib-chromecast
    2. node-red-node-watson
    3. node-red-contrib-scx-ibmiotapp
    4. node-red-contrib-alexa-remote2
    5. node-red-dashboard

    Once you have the packlages installled you can import my flows from github here.

    Github

    Import the weather dataflow. There are 3 flows for different weather data source. I have a Personal Weather Station (PWS) on my balcony, which I connected to Weather Underground. Wundergound will give you an API that allows you get weather data from pretty much everywhere including your PWS of course;).

    If you do not have a PWS use the darksky flow. You will need to sign up at https://darksky.net/dev/account – is free. Of course you can use any other open weather api services like:

    • OpenWeatherMap
    • Weatherbit
    • AccuWeather
    • Dark Sky
    • Weather2020
    • Wunderground

    See my github for the different flows and details

    Here a quick Video

     

     

     

  3. Weather Data

    Once you imported weatherdata.flow you should adjust the API,Chromecast IP and Raspberry PI address in the flow. We will setup Alexa in the next step.

    The top of the flow should look like the image below – click on the function to adjust the values. Here the link to the full flow.

    Screen-Shot-2019-11-29-at-11.51.38-AM

    here the urls for my local weather with API keys of the various data resources.

    Wunderground – my PWS

    https://api.weather.com/v2/pws/observations/current?stationId=ITORONTO277&format=json&units=e&apiKey=cd9345030afd47e69345030afde7e6a9

    DarkSky

    https://api.darksky.net/forecast/3bb84459e7c76e4c4d81cabe2e7448a0/43.66,-79.40?exclude=minutely,hourly,daily,alerts,flags&units=auto

    Weather Company

    https://52bf91de-4789-4c1f-9dba-17345c93b115:iOg7d8QEWW@twcservice.mybluemix.net/api/weather/v1/geocode/43.66/-79.40/observations.json?language=en-US

    You will need to adjust the APIKEYS and LAT/LON to get your specific weather information etc depending which weather source you use. Note: My API-KEY probably will not work after a while due to limitation, so please get your own, but to get your started feel free to use mine.

    If you fire the flow or plugin the urls in a browser you should see something like for Wunderground / DarkSky

    GetWeatherDataResultScreen-Shot-2019-12-01-at-10.31.03-AM

    Note: The structure is different depending on the url/flow you use. I will include all the flows in github for the three different weather sources.

    To keep is simple I will just focus on the darksky in the next steps.

     Here a quick Video.

     

  4. Broadcast the local weather to Alexa and ChromeCast

    Below the JSON “transformator” icon (see flow form last step) you should a flow which looks like the picture below. To configure Alexa open the Alexa Init node and add the local IP address of your Pi or computer. Once you deployed the changes – the Alexa init node will show a message. like “open https://l<YOURIP>:3456″ . Put the url into a new browser Tab – you will be redirect you to the Amazon logon page enter your username/password. After the authentication you can go back to Node-RED and you should see a “Ready” on the Alexa Icons.

    ChromeCast/Alex config

     

    Try to execute the each of the flows like the Hello test to see/hear a message on your ChromeCast/Google Home. The ChromeCast code in the function is pretty staight forward. We use google Text to Speech / translate function and cast the mp3 locally to our device.

    url = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Local temperature is now '+ global.get("localtemp") +" degree's !"
    msg.payload = {
    ip_address: flow.get("CHROMECAST"),
    ip: flow.get("CHROMECAST"),
    url: url,
    contentType: 'audio/mp3'
    }
    return msg;

    For Alexa the function is even simpler – here we just need the String in the msg.payload. And Alexa plugin with do all the work e.g Text to Speech and casting.

    msg.payload = msg.payload + ", the local temperature is "+localtemp+" degrees"

    If you have both ChromeCast and Alexa try both or just the one you have. Please note –¬† if Alexa is idle for a while you may need to reauthenticate again.

    Here a quick Video

  5. Adding additional weather location

    In the previous step we got the local weather data via Lat/Lon eg a location from darksky close to my neighbourhood. Please change the Lat/Lon parameter to something you interested in e.g your city / home location. The next flow we will get a second location. I personaly like to know what the conditions are at the Airport and compare them with my local weather. Below is basically the same flow replicated with the location (lat/lon) of the Toronto Airport. Again change it to the Airport location you interested in.

    Get the Airport Weather

    here the code which bascially combines the local and airport data and creates a string for our boardcast.

    var d = new Date();
    d.toLocaleString(); // -> "2/1/2013 7:37:08 AM"
    d.toLocaleDateString(); // -> "2/1/2013"
    time = d.toLocaleTimeString('en-US');
    nowArray = time.split(':');
    time = nowArray[0]+':'+nowArray[1];
    ampm = nowArray[2].split(' ');
    time = nowArray[0]+':'+nowArray[1]+" "+ampm[1];

    msg.payload = "It is now " + time

    global.get("localtemp")

    //msg.payload ={}/
    ///msg.payload.temp = msg.observation.temp
    localtemp = Math.round(global.get("localtemp-ds"))
    airporttemp = Math.round(global.get("airporttemp-ds"))
    airportweather = global.get("airportweather-ds")
    cloudCoverPhrase=airportweather.myphrase
    gust=Math.round(airportweather.mygust)

    msg.payload = msg.payload + ", the local temperature is "+localtemp+" degrees , the Airport temperature is " + airporttemp + ", and "+cloudCoverPhrase + " with wind gusts of "+gust + " kilometer per hour. "
    node.warn(msg.payload )

    flow.set("weathertext",msg.payload)
    url = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q='+msg.payload
    msg.payload = {
    ip_address: flow.get("CHROMECAST"),
    ip: flow.get("CHROMECAST"),
    url: url,
    contentType: 'audio/mp3'
    }
    return msg;

    Result is something like:

    It is now 9:50 PM, the local temperature is -1 degrees , the Airport
    temperature is -2,  and its Overcast with wind gusts of 15 kilometers per hour.

    Here a quick Video

     

     

  6. Using Watson Text to Speech (optional)

    The next flow is about using Text to Speech РI wanted a different voice when the weather is boardcasted to ChromeCast.  Here the flow which uses the Watson Service.  The way this works at momment is that I create a mp3 file using Watson Speech to Text and then Safe it on the PI. The flow as a http endpoint (/sayit) which i then send to Chromecast. You will need to sign up at https://cloud.ibm.com/ once you signed my recommendation is to create a Node-RED instance, IoT Service and the Text to Speach Service. The Node-RED instance and IoT Instance will be use later for the Twilio and IFTTT integration. Here the link to the flow.

    Watson Test to Speech

    The flow pretty much repeats the same as the preview flow except for Text to Speech part which create the mp3 file that gets saved onto the PI. The Boardcast function is using the enpoint to send the mp3 file to Chromecast.

    msg.payload = {
    ip_address: flow.get("CHROMECAST"),
    ip: flow.get("CHROMECAST"),
    url: "http://"+flow.get("LOCALIP")+":1880/sayit",
    contentType: 'audio/mp3'
    }
    return msg;

    You can send mp3 files, videos and images etc. I have not found a flow/plugin/example which allows the same for Alexa unless you build a skill. Chromecast can  to broadcast pretty much everything locally which is handy e.g to use it a old school clock or doorbell so you cast sounds to Chromecast as you need it.

     Here a quick Video

  7. Weather Dashboard (local)

    Since we have Node-RED locally installed would make sense to create a dashboard to display on a TV or Screen. I have my PI connected to a little 7 inch LCD screen.  There are serveral different PI LCD Kits with case and touch LCD screens available. It make it a nice little living room Weather Station dashboard. Below is my simple Dashboard.

    I added some images from the public Highway Cameras and a local image area. Here the link to the flow

    Dashboard

    Below the flow for the local weather dashboard. The Local image is from my PWS you can use and local camera feed from your home or internet if you like. Since I like the data also on the cloud  I send the information via IoT to my IBM cloud enviroment where I collect weather data from different location and create one big consolidated Dashboard and do some analyis. Here my flow which displays the data and fowards them to the cloud.

    Local Weather Dashboad

     

    Here a quick Video

  8. IFTTT Integration for Alexa and ChromeCast

    In order to trigger the Alexa or ChromeCast to boardcast manualy. Like “Alexa – trigger my weather” or “Hey Google whats’ my weather” we will need to integrate a IFTTT with Alexa via webhook. You can find details in this recipe or in the video below. Basically we setup a pharse in IFTTT send it to our Node-RED cloud instance and than forward to our local Node-RED via MQTT to trigger the weather announcements.

    Here the cloud flow. You see 2 webhooks/ http endpoints setup which are used in IFTTT to post to the instance. Here the link to the flowsIFTTT form the cloud

    In IFTTT it looks like the image below. The URL is basically your Node-RED instance plus the endpoints. Note that the json format did not work for me in the post … I stayed with the content type text. I also added a url parameter just in case I have more Alexa/Goolge phrases and need to select different flows.

    IFTTT WebHook

    Here the Result see video form more details.

    Google Alexa IFTTT recipe

    Here the local IFTTT flow which basically just checks if its from Google or Alexa…fun is to have Alexa answer the Google Request and vise versa

    Local  IFTTT flow

    Here a short Video guiding you through the steps.

  9. Finish

    I hope this is usefull. Please leave a comment or ask questions if you run into problems. I will add the doorbell instructions shortly to the developer recipes and maybe more. Stay tuned … cheers Markus

Join The Discussion