LOGIN  |  REGISTER
Smart Living Made Brilliant!
CASTLEOS FORUM

HomeScripting

A forum for information about scripting with CastleOS. Get samples, suggestions, and other help here

help with my morning wake up weather script Messages in this topic - RSS

Eric Hillen
Eric Hillen
Posts: 14


5/10/2015
Eric Hillen
Eric Hillen
Posts: 14
Hello all,

I know this isn't a program question, its about a script to run so i was hoping some fellow users may have some insight. I am trying to get a script to run every morning that will give me the forecast for the day. with that being said I know nothing about scripting other than what I have learned from other users, youtube tutorials, and stuff from the code forums.

attached below is what I started piecing together, borrowed, and stole... its not finished but i have no idea where to get it going from here.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Web;
using System.Speech.Recognition;
using System.Speech.Synthesis;

namespace WeatherAlarm
{
}


Speechsythensiser WHAT DO I PUT HERE? = new Speechsynthesizer(); <---- so confused....


{
public partial class Form1 : Form
{

string Temperature;
string Condition;
string Humidity;
string WindSpeed;
string Town;
string TFCond;
string TFHigh;
string TFLow;


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

void _recognizer_SpeechRecognizer(object sender, EventArgs e)
{
string speech = e.Result.Text;
switch (speech)
{
case " ":
GetWeather();
SOMETHING? .Speak("The weather in " + Town + " is " + Condition + " at " + Temperature + " degrees. ",... finish this later)


}
}
private void GetWeather()
{

string query = String.Format("http://weather.yahooapis.com/forecastrss?w=23424583");
XmlDocument wData = new XmlDocument();
wData.Load(query);

XmlNamespaceManager manager = new XmlNamespaceManager (wData.NameTable);
manager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNodeList node = wData.SelectNodes("/rss/channel/item/yweather:forecastr", manager);

Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["temp"].Value;

Condition = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["text"].Value;

Humidity = channel.SelectSingleNode("yweather:atmosphere", manager).Attributes[Humidity].Value;

WindSpeed = channel.SelectSingleNode("yweather:wing", manager).Attributes["speed"].Value;

Town = channel.SelectSingleNode("yweather:location", manager).Attributes["city"].Value;

TFCond = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["text"].Value;

TFHigh = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["high"].Value;

TFLow = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["low"].Value;





}



}
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350


5/11/2015
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350
Hey Eric! A couple things...first is you don't need to worry about the Speech synthesizer, just call the ScriptingAPI.Speak method.

That said, the forecast is already built in.. You can just ask it "computer what is today's forecast?" or "computer what is Monday's forecast" etc..

Thanks!

-Chris
edited by ccicchitelli on 5/11/2015
0 link
Eric Hillen
Eric Hillen
Posts: 14


5/15/2015
Eric Hillen
Eric Hillen
Posts: 14
Thanks for the reply chris- as I know my question is not a castle's question and has nothing to do with your software and is strictly C#. I am trying to get the weather forecast as a "alarm" to wake up when my lights turn on.
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350


5/15/2015
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350
Eric Hillen wrote:
I am trying to get the weather forecast as a "alarm" to wake up when my lights turn on.


I'm curious...can you explain that use case some more?
0 link
Eric Hillen
Eric Hillen
Posts: 14


5/16/2015
Eric Hillen
Eric Hillen
Posts: 14
Sure,

Right now I have reoccurring events set up Monday - Friday for 3 different zones (my room and my kids rooms). When the event trip each different zone has its own custom voice announcement along with the lights turning on, reminding my son to take the trash out or my daughter she has softball practice that day, etc etc. I would like to run a script triggered every morning so it will automatically read the forecast for that day also. I know I can just ask the computer for the weather but I never remember until I'm getting out of the shower and have to check my iPhone for the day real quick in the bathroom. I live in NC and this time of year it can be monsoons one day and a breezy 70 the next.
0 link
Eric Hillen
Eric Hillen
Posts: 14


5/16/2015
Eric Hillen
Eric Hillen
Posts: 14
so basically the "event" would trigger the voice announcment to say the basic daily reminders for the specific zone then would execute the script that would read the daily forecast, which I was originally trying to pull from yahoo's developer weatherAPI.
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


5/17/2015
Phil Hawthorne
Phil Hawthorne
Posts: 400
Ie something like Jarvis does: https://www.youtube.com/watch?v=sXH2K2ZlrjQ
0 link
Eric Hillen
Eric Hillen
Posts: 14


5/25/2015
Eric Hillen
Eric Hillen
Posts: 14
Yes exactly! I won't use it to chase hot liberals out of my bed though.
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350


5/27/2015
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350
Hey Eric, how did you make out with the weather? If you're still struggling, let me know, I can probably help.

Thanks,
Chris
0 link
Eric Hillen
Eric Hillen
Posts: 14


6/21/2015
Eric Hillen
Eric Hillen
Posts: 14
Hey Chris,

No I haven't haven't had a chance I get it going. I have been out if the country and the software (trail version) expired. I'll tell you what help me make it work and I'll buy the program! I'm kidding I'll buy it anyway, thanks for the follow up though I do appreciate the software and the time you put into helping the consumers out! Eric
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350


6/21/2015
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350
When you're back in the country shoot us an email and we'll send you a license code to extend your trial smile

Also don't forget the trial only matters from devices 11 to infinity now, the first 10 are free with no time limit or feature limitation.
0 link
Eric Hillen
Eric Hillen
Posts: 14


6/23/2015
Eric Hillen
Eric Hillen
Posts: 14
Hey Chris, That's awesome with the 10 devices now! I'm back in the states and downloading the new version now.

As for the script I'm working on I am still stuck and not really sure where to go next. If you don't mind taking a look at it again and seeing what I'm jacked up on that would be much appreciated! I know you're busy as hell man so if not no worries I'll still buy the software 😜
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


6/24/2015
Phil Hawthorne
Phil Hawthorne
Posts: 400
Eric I'd be keen to hear how you go with this!
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350


6/26/2015
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3350
Eric Hillen wrote:
Hey Chris, That's awesome with the 10 devices now! I'm back in the states and downloading the new version now.

As for the script I'm working on I am still stuck and not really sure where to go next. If you don't mind taking a look at it again and seeing what I'm jacked up on that would be much appreciated! I know you're busy as hell man so if not no worries I'll still buy the software 😜



The API update is going to expose this, so it won't be something you have to custom script, you'll just call the weather object and get the results.


If you want to try to do it in your script manually now, you need to call the url to MSN weather, http://weather.service.msn.com/data.aspx?weadegreetype=F&culture=en-US&weasearchstr=02113&src=outlook and then parse the XML results which include the forecasts (make sure you replace the 02113 zip code with your own).

Thanks!!
0 link
Eric Hillen
Eric Hillen
Posts: 14


6/29/2015
Eric Hillen
Eric Hillen
Posts: 14
Paul- I will keep at it until I get it to work and post the final script on here. At this point I've spent to much time trying to learn this stuff to just drop it now.

Chris- couple of quick questions, 1st, do I have to use MSN? I don't care either way just curious if the software is made a certain way. 2nd, When i try and add a new even to see if the script will run I "Add Event" then set the time and select "Run Script" from the available actions menu. Once I add it in the "current actions" a "voice announcement" shows up. Is the a bug or am i missing how to direct the core services to the script file. I have the file saved in the core services folder since i am not trying to voice command run this script.

For anyone that is curious this is where I am at now. my trail of Visual Studio also expired so I've been working out of note pad so I'm sure its a bit sloppy.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Web;
using CastleOSKinectService;
using System.Speech.Recognition;


namespace WeatherAlarm


{
public partial class Form1 : Form
{

public class MyScript
{
public void Main(string[] args)
{






string Temperature;
string Condition;
string Humidity;
string WindSpeed;
string Town;
string TFCond;
string TFHigh;
string TFLow;


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

void _recognizer_SpeechRecognizer(object sender,

EventArgs e)
{
string speech = e.Result.Text;
switch (speech)
{
case " ":
GetWeather();


ScriptingAPI.Speak("The weather in " + Town + " is " +

Condition + " at " + Temperature + " degrees ");

}



}
private void GetWeather()
{

string query = String.Format

("http://weather.yahooapis.com/forecastrss?w=23424583");
XmlDocument wData = new XmlDocument();
wData.Load(query);

XmlNamespaceManager manager = new

XmlNamespaceManager (wData.NameTable);
manager.AddNamespace("yweather",

"http://xml.weather.yahoo.com/ns/rss/1.0");

XmlNode channel = wData.SelectSingleNode

("rss").SelectSingleNode("channel");
XmlNodeList node = wData.SelectNodes

("/rss/channel/item/yweather:forecastr", manager);

Temperature = channel.SelectSingleNode

("item").SelectSingleNode("yweather:condition",

manager).Attributes["temp"].Value;

Condition = channel.SelectSingleNode

("item").SelectSingleNode("yweather:condition",

manager).Attributes["text"].Value;

Humidity = channel.SelectSingleNode

("yweather:atmosphere", manager).Attributes

[Humidity].Value;

WindSpeed = channel.SelectSingleNode("yweather:wing",

manager).Attributes["speed"].Value;

Town = channel.SelectSingleNode("yweather:location",

manager).Attributes["city"].Value;

TFCond = channel.SelectSingleNode

("item").SelectSingleNode("yweather:forecast",

manager).Attributes["text"].Value;

TFHigh = channel.SelectSingleNode

("item").SelectSingleNode("yweather:forecast",

manager).Attributes["high"].Value;

TFLow = channel.SelectSingleNode

("item").SelectSingleNode("yweather:forecast",

manager).Attributes["low"].Value;





}



}
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


6/29/2015
Phil Hawthorne
Phil Hawthorne
Posts: 400
Eric Hillen wrote:
my trail of Visual Studio also expired so I've been working out of note pad so I'm sure its a bit sloppy.


Hey Eric, assuming you're just using the default Notepad that comes with Windows, I recommend you use something like Notepad++ or Sublime Text Editor. They should give you syntax highlighting so you can spot errors easier.
0 link
Eric Hillen
Eric Hillen
Posts: 14


6/29/2015
Eric Hillen
Eric Hillen
Posts: 14
Thanks Phil, in my search for a new free C# builder I found the Visual Studio was free i just had to click Update license and it starts working again with no problems. It's great it highlights errors and tells me exactly whats wrong, Unfortunately I have no idea what 90% of these errors mean. I am like a monkey looking at a wrist watch...
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


6/29/2015
Phil Hawthorne
Phil Hawthorne
Posts: 400
Eric Hillen wrote:
I am like a monkey looking at a wrist watch...


Haha! When I get my Hub I can't wait to start some of my own scripting. But this will be my first venture into C#, so not sure how its going to go
0 link
Eric Hillen
Eric Hillen
Posts: 14


7/2/2015
Eric Hillen
Eric Hillen
Posts: 14
Chris, So i think I got the script working, but when i go to core services to add it as an "event" when i click open .cs file it adds a "voice announcement" and does not let me find the .CS file. I am trying to run the script from cores ervices script folder as it should act as an alarm, not a voice activated script through the kinect service. Am I doing something wrong here?
0 link
Eric Hillen
Eric Hillen
Posts: 14


7/18/2015
Eric Hillen
Eric Hillen
Posts: 14
Bump for the previous post. Haven't found any other mentions of this problem in for forum.
0 link