# Daily Weather Notifications with OpenWeatherMap and Twilio ☀️

## Метаданные

- **Канал:** n8n
- **YouTube:** https://www.youtube.com/watch?v=QhTsOMvqLuo
- **Дата:** 08.12.2020
- **Длительность:** 23:11
- **Просмотры:** 16,383

## Описание

Let's create your first workflow in n8n. We'll create a workflow which will run every morning at 8 AM and will send an SMS to tell you if you should take a sweater with you.

You can also find a write-up of this tutorial in our docs: https://docs.n8n.io/getting-started/create-your-first-workflow/daily-weather-notifications/

## Содержание

### [0:00](https://www.youtube.com/watch?v=QhTsOMvqLuo) Intro

today we're going to create our very first any n workflow this workflow will check the weather every day and if it's too chilly it'll send you a text message to wear a sweater there's a few prerequisites that we're going to assume you already have set up the first is that you've got n8n up and running which you do right here the second is that you have an open weather map account and this is the application that will check to see the temperature that day and then a twilio account is what will allow you to send the text messaging up and there's a few pieces of information for each so for the open weather map you've got the api key and for the twilio account you have the account sid the authorization token and the phone number so this workflow has five components to it and uh each of these components has a different role so the quick overview cron node will have the actual uh trigger that will start up the workflow the open weather map will go and check the weather if we'll actually add a little bit of logic to the workflow so that you can tell it where to go when different things happen twilio will send the actual uh text message and the no op node will do literally nothing and we'll explain why we do that later on and this is kind of what we expect the final workflow to look like when we're done so let's start with the cron node cron is actually a special type of node and what it does is it will trigger that will allow us to start a workflow based off some sort of external source so the external source here is the time that is on the system at that moment so let's just add a crown trigger so here we've just added the crown time there's three different pieces here that we have to take a look at the mode and then based off the mode changes the hours and minutes so we're going to run this every day perfect and this is the hour of the day so this is the 14th hour so we wanted to do it at the eighth hour according to what we have here and zero minutes so this is saying every day at 8 a. m do something start to trigger so a couple little introductory notes here if this is kind of confusing and you can do this for any node or even credentials you're not really sure what uh to do you can always go down to the open the documentation and you'll find one of these at the bottom of every node and if you click on it just goes it opens up right into what you want to do that's very useful there unfortunately we have our little guide over here we don't need to use that at the moment so we're going to execute this just to see that does something and yep perfect it runs no problem

### [3:05](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=185s) Settings

so we're just going to close that and because this is our trigger i'm just going to put over to the side we actually don't need the start trigger so we're just going to hide it so it's out of our way and not disturbing us now the cron node because it triggers off time it's important for it to trigger off the right time zone as well so we're just going to do a couple things here we're going to save this workflow so this is going to be our check weather workflow and so now that we've saved it opens up another option here called so these are the settings for the workflow itself so if you open up the settings it gives us a bunch of different bits of information we're not going to go into these in detail but if you want you can hover over and it'll show you what each one of these does the one we're going to focus on here is time zone so this is my time zone that i'm in but if you are in a different time zone you can go and maybe we right now because it's a winter you want to be hawaiian time zone you can set it to that but i'm going to leave it as the default this is what my system is set at and it'll always bring up the right time zone so this way it will trigger at the right time if i had to set to say the hawaiian time zone it wouldn't actually trigger at the right time i would be getting it at the wrong time and i'd be saying well i thought this was going to execute at 8 o'clock and it executed at a different time so that's a good little option to remember if you're finding that any of your crown nodes are triggering at the wrong time so go and double check that make sure that that's correct

### [4:45](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=285s) OpenWeatherMap

all right and once we have now that we have the crown node set up properly we're going to open up the next one now here's a little pro tip for you if you have a node highlighted we have this one highlighted here and you click plus it will automatically connect the new node that you select to the one that you've created and just saves you one little step it's not a big deal it's not a ton of time that it saves but it does just make it a little bit quicker so we're going to go to the open weather map now and there's open weather map node we have a bunch of different options here so the first one is credentials are how a system that you're trying to get information from knows that you are who you say you are so we're going to use the open weather map credentials which i've already had set up and let's just take a quick look at those so in the open weather map credentials it's got the credentials name and it's called open weather map credentials you can call it anything you want fred and it'll work just fine it's just a matter of giving it a name that will mean something to you and that you can recognize now the access token here is important this is just a string of characters and numbers that will um represent who you are and you've gathered this from the open weather map um the open weather map account and so this allows you to send information and receive information from that service that will allow you to gather that information properly without it having to ask you in real time who you are so we're just going to save that so a few other things that it wants us to set up here so we've got the uh current weather which is good if everything's coming to metric we're going to go by city name so by default because ndn is based out of berlin germany they have berlin as their city but i don't live in berlin i live in edmonton alberta and so i put evanton in here so we're going to test this node we're just going to execute it and there's a whole bunch of information that comes up in table format and you can kind of browse back and forth to see that i prefer in json mode that's just the way i work on top down and this is giving me a good sense for what's going on so you know minus 1. 21 outside feels like minus 0. 4 uh which believe it or not in edmonton in november is a balmy day it is extremely warm here today so uh we've got all the information we need wonderful we can now close this node up and you'll see that it automatically connected it like that indicated before

### [7:23](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=443s) If Node

so the next node that we're going to take a look at is the if node and the if node is actually a very powerful node it allows us to make decisions around the information that it receives so let's just add the if node in here and even before we go into the data i'm just going to show you the if node and it's a little bit different you'll notice that our other two nodes have single outputs so the dots are always at output and the square is always an input um i guess that's a rectangle not a square so the output here there's two of them we've got a true and a false output whereas these just have a one so when you have a single output this tells you that whatever processing whatever it does whatever it pulls in here in the node outputs just one bit of information but this one branches off so what this says is what depending upon what processing you do inside the node if it is determined that yes that occurred correctly it'll send it out to this uh output if it says that it didn't it's coming correctly it'll send it out this input or output sorry so it's very important that we know you know what we want to do if this is correct and it's not correct so we'll keep that in mind as we're working through our if node so when we get into the if node we've just got the basic set up here right now so what it's doing is going to be comparing information that it has and deciding hey is this right or not so based off what we have in our documentation here our if node we're going to add a condition and we have three different kinds of conditions so uh a boolean which is a yes no um true false zero or one uh number which is just a standard number um and a string which is just a series of characters so we're going to be dealing with numbers here because checking the uh what the temperature feels like

### [9:28](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=568s) Expression

so we've got different values in here so in here for example we can put in a value uh anything we want we can put in because we're looking at number to put in a value it looks like 28 and if we were to run this it said that there's no text data but our output is true because it ran and just did something but what we want to do here is a little bit different we want to go into this variable and we want this to be dynamic because right now this is just static it doesn't change depending upon what we do so every single one of these different fields here you have this little cog and what this cog allows us to do is dynamically apply information to this field so we're going to add an and this brings up our expression editor as you can see here we've got the 28 that we put in before we're not going to use this we're actually going to be pulling information from the open weather map node because that's what we're going to be comparing so you'll see as it's walking us through here in on the web page we can go to nodes the open weather map node and we're going to put the output data so it's the information that is done once it's processed it's going to open that data always comes up as json because it's json data that we're going to be pulling and then we're starting to see some stuff that looks familiar you know we've got clouds our coordinates a bunch of different information here we're going to be going to the main section here and feels like which is what we had before when we click on here it automatically builds out our expression and so if we read through the expression it says you know the open weather map node the json main piece of information and feels like we want to pull that information out and down here we see the result so when this is being executed this is the output that we're going to get based off the information now if the weather changes so the next time it runs because this is going to run every day if it changes then it will reevaluate what this expression is and give you that output so we just close this and you'll notice it automatically puts in that value the operation is the next

### [11:41](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=701s) Operation

piece that we have to take a look at so we can leave it the way it is right now uh because this is actually the one we want but this will give you the option as to how to compare them so uh basically right now this is saying we have smaller selected if the value here is smaller than the value here then execute it so what we want to do is we want to make sure that if the temperature is below 18 degrees celsius right now it's saying if our temperature is below zero degrees celsius looks a little bit uh too chilly we want to be wearing a sweater before that so we're just going to change that to 18. so you see the difference here where we've got the dynamic information it changes the uh view of or the formatting of this field so this field will be dotted with the pinkish or reddish background whereas here we don't have any outline at all and it's just standard gray so we know that this is dynamic and if we go under here you know we've got different values than if we go under the gears here so this doesn't it does not have an expression with it right now so this is more or less what we're trying to find here so this is saying when this dynamic value at which right now is minus 3 is smaller than this value which is 18 then yes this will be true so let's execute this and make sure that this works the way we want and it does notice that the output goes to true and it actually pulls all the information in from the previous node uh this is really beneficial because it allows data to travel through nodes even as it's being processed and you can control it and we just confirm that yes it's minus 3. 97 and so because minus 2. 97 is less than 18 we're true wonderful so this one's working great

### [13:38](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=818s) Twilio Setup

so that's saying that would have gone out the true note so great it's true now what do we do with it well this is where the twilio node comes in so for those of you who don't know twilio is a service that lets you send text messaging lets you send um even work with voicemail and voice as well and all controlled by the api so here we have the uh interface for the twilio node again much like the open weather map node and you'll see this is very common that almost every service like this has some sort of credentials that you need to set up you need to have an account set up and it needs to know who you are so we're going to use the twilio credentials and you'll see here they're a little bit different than the open weather map credentials that we had um we've actually got two bits of information we've got the account sid and we've got the authorization token and that information is available to the twilio node so that they can talk with the twilio service and again if you're not sure how to deal with credentials right here you can click on that and that will pop up information for you so we're going to leave these two settings as they are as they're basically the only settings that we've got um the from we've already got this we've pulled it from our twilio account so we're just going to paste it in here again i apologize we have to blur this out but that is um that's the way uh this works so i would also like to mention that um if you're on a trial account for twilio um you could only enter a registered or a verified phone number in the to field here so i need to give my own personal uh phone number here uh otherwise it will not work it'll fail so i put my number in here then wonderful and then let's look off it you'll notice so anything actually that you see here with these red triangles that means that before we can run this workflow we need to make sure that these are cleared up because even if we're outside of here and try to run the workflow we're going to get an error and in fact i can even quickly demonstrate that you see here it says that we've got an error so if i were to try to execute this node we get the error down here and it tells you exactly it's very helpful tells you where exactly the error is and you can see here that the error is in here and when you click into here you see right here is where the error is so if you follow the red triangles it'll take you in general right to where you need to be in order to fix the problem so here we are with the uh the message we're going to add an expression here as well because we want this to be kind of dynamic give us a little bit of information so we've uh got in here a the option to go and just grab what we have here for the data so this automatically allows us to copy and paste in an expression which is kind of neat because that way we can easily share these expressions and share what um what information shows up here so this shows you that you don't necessarily just like in the previous note put in specific information that related to only the dynamic information you can format this and make this work anyway you want so for example if i were to build this up manually i would go to my nodes open weather map nodes my output data json main and there's my feels like gig gives us the exact same information that we had here as you can see but i just manually went and found it through there and then i can i could easily put this to say the exact same thing here so if i uh we're typing here we're a sweater today it is such uh of course the degree symbol is always hard to do something's gonna cheat and copy it as you can see we can manually reproduce that as well but we can change it to whatever we want uh you can say something i like let's see even put my typo in there you can even go in here and say it's a tad chili at a third degree celsius you may want grab a sweater so again you can make it say and do whatever you want on your own so we'll leave it our own little custom one here and so if we execute this node again here's all the output data so as you'll see this information is just specific to the twilio node so a little side note there's a couple of different um things around some of the notes some of them will transfer the data through and some will not so as we saw earlier twilio or sorry the open weather map node and the if node they will transfer the information through but the twilio node does not and actually one of the other nodes the set node you get to choose whether it will transfer the information through or not so just a little something to keep in mind so this all ran properly but let's make sure that it actually got through so here's my phone and this is my little uh account where it pulls information from twilio you see that i've already before said hello from n8n from the trilio account uh so when we run this hit execute this comes up nice and clear and then you will see there it is except from the twilio trial account and this is the exact wording that we had put out before and this is so proving that hey this works perfectly fine so we're just going to pop that over there just gonna minimize that again so uh the last one that we're gonna do is the no lock node and uh so the no op node like i was

### [20:26](https://www.youtube.com/watch?v=QhTsOMvqLuo&t=1226s) NoOp Node

saying before is a little bit funny and when i first saw him like why in the world would we do this is a node that literally does nothing absolutely nothing at all other than it exists so the no op node actually has a couple of purposes not with the actual workflow when it runs on its own or running as a service um it's very useful for a couple of reasons especially when you're developing um so this tells me a couple of things one it tells me that i've actually dealt with this and it's not something that's waiting to be done in the future it's complete you can also use it to help you troubleshoot so this tells you the little ones here tell me hey each one of these nodes has executed a single time but this one has not so that's confirming that this is true and this works properly if it were false this would show a one on it the third thing that actually just came up the other day that i found is under settings you can use this to make comments so this would have fired if it were false for example and we just say to explain the flow and there's a little comment which is really useful anybody who's done any uh development knows that comments will save your bacon later on because i guarantee you three months from now you're going to come back to this node and go what did that node do again i haven't a clue but you can take a look at your no op node and the comment and go oh yeah that's right that's what that does so very helpful from that perspective a couple little tips here when you're done creating a workflow before you try to execute it or anything along those lines make sure you save saving is very important the other piece is that while this is set up now and working we've tested it a little bit it actually doesn't work yet we haven't actually activated and that's the key this needs to be activated right up here and when you activate this and just you know as we said before you should be saving it but this will automatically save it for you so yes activate and save so now it will run in the background every day at 8 00 am my time in my time zone this will execute and check the weather and if it's too chilly outside it'll send me a text message hopefully that was helpful hopefully there was something that you found useful and we've got another one of these coming up in the near future thanks a lot

---
*Источник: https://ekstraktznaniy.ru/video/15958*