>> Today we're going
to take a look
at the Auto-Away-Assist-for-Nest-Thermostat project.
This will let your Nest know when you're in another room,
and assist with the Auto-Away feature
so that you don't find yourself in
a situation where the Nest has
determined that you are not
home when you in fact are home.
We're going to accomplish this by
using a Particle Photon Device,
a PIR sensor, and
some free services from Microsoft Azure.
To get started, you'll want to head to aka.ms/nestassist.
Which will bring you to this page,
the GitHub repository for
the Auto-Away-Assist-for-Nest-Thermostat project.
We're going to head over to the link to
the full instructions on
walkthrough guide available at hackster.io.
Now, you might be wondering why I'm building this device.
Because Nest devices are smart.
Right? They are able to determine when
we're home using a variety of different features.
These include motion-sensing,
they also can detect if a,
cellular devices on the same network as the Nest and
they use all these other heuristics
to determine whether you're home.
In practice, that doesn't always work out properly.
There's been numerous occasions where I find myself
upstairs in my office and the AC is turned off,
because the Nest devices have determined,
because either the sensors have not been trigger,
or maybe my cell phone is off, that I'm not home.
Then I find myself sweating in the Texas heat,
it's just not fun.
So, Nest is aware of this issue,
and has created a motion-sensor and monitoring thermostat
that alleviate these problems however,
they only work with the Nest V3 Thermostats.
What we're going to build today though,
will work with any Nest Thermostats
as we're going to interact directly with
the API using our own hardware
to tell Nest that we are in fact home.
So, the first thing we're going to need to do,
is obtain an Oauth Token to access the Nest API.
Now, for security reasons,
I'm not going to walk through these details in the video,
but you would follow through this in
the guide and once completed,
you should have an Oauth Token instructure ID parameter,
which we will be referencing again later on in the video.
Next we're going to construct the hardware.
You can use any compatible Particle device,
I chose the Particle Photon.
You could even use the Particle Core,
or the recently launched Particle Xenon.
Once you've got your device picked out,
simply attach the PIR sensor with the three wires,
and make sure that you have
the data line connected to the D0 pin.
With all that up and connected,
I'm going to go ahead and put my device online,
and I'm going to open up Visual Studio Code,
and open into the Nest motion folder.
From here you'll see the nest-motion.ino firmware,
and I'm going to initiate a task
with "Control" "Shift" "P",
and select "Particle Cloud Flash".
This will flash that Nest motion
I know firmware to the Particle device,
should see any moment now
that it's going to flash magenta,
and then restart running my code.
In a nutshell, all this code does is it looks
at the sensor and when it detects motion,
it publishes an events to the
Particle Cloud then goes into
a deep sleep for
a sleep interval that can be
specified with this constant.
Now, that's great. We're getting motion data,
and publishing that up to Particle.
But we need to get that data over to
Nest in order to really tell our devices that will home.
So, to do that, I'm going to head to
the "Particle Console" and
select "Integrations" and from here,
you would select a new "Azure IoT
Hub Integration" and these are
pretty straightforward to set up,
all it requires is an Azure account.
Then you would create an Azure IoT Hub and add
a shared access policy to allow
the Particle Cloud to communicate with the Azure Cloud.
So, I have one set up already.
That's flashed to the device that we just saw,
and you can see that it is publishing
those motion events up to Particle.
Now, to forward these over to Nest,
what we're going to do is create
an Azure function that really does nothing more than
on a triggered event calls the Nest API using
our appropriate credentials and sets the status to home.
So, to do this, we're going to open up
the set Nest or
the Nest Controller folder within the repo.
Then we're going to look at the SetNestToHome function.
So, inside here there's a local.settings.json file,
and we're going to need to fill in the "Access Token" in
structure ID placeholders with
the values that we obtained from the Nest API.
Then the Event Hub compatible endpoint,
we're going to obtain
that value by heading to our "IoT Hub",
selecting "Built-in end points",
and then grabbing the Event Hub,
compatible endpoint value.
Once you have those, you can go ahead and set them,
and then look at the function.json file.
From here, we just need to change
the event hub name placeholder to
the name of our IoT hub.
So, in this case, mine is named Nest Motion Sensor.
Once we have all of that set up,
we can go ahead and deploy the Azure function
locally to test it before we push it into the Cloud.
So, I'm going to select
this attached to JavaScript functions button
and that's going to kick off
a local deployment of the function.
Once that's up and running,
we can initiate a motion events with the device.
So, I'm just going to stimulate the PIR sensor here.
That should fire an event.
Once that happens, the device will turn off,
and we are now located on
a breakpoint that I've set inside the function itself.
So, you can see here,
this is a great way to test
these things before pushing them up to the Cloud.
Let's just make sure that it works.
So, I've got my Nest manager open,
and you'll see that my current status is set to away.
I'm going to walk through the rest of this function code.
That should trigger, the call to
Nest API and you'll see that it is now flipped to home.
You might even hear the air conditioners
turning on behind me.
So, this is awesome. But it's not the final step.
We have to publish this function up into the Azure Cloud,
so that it can run 24/7,
and then we can flash this code to
a number of devices and deploy them all around
the house and never ever have to worry about
being told that we're not home when we actually are.
So, to do that, right-click the "SetNestToHomeFolder",
and click "Deploy to Function App",
and if you have not already
created an Azure function app,
it's going to ask you to create one.
So, I'm going to use this one that I've already
created the Nest Motion Sensor.
It's going to go ahead and prompt you to deploy,
and that will kick off the task that
begins that deployment to your Azure account.
So, once you've done that deployment,
you can log into your Azure function,
in the Azure portal,
and we're going to test it.
Because we want to make sure that it works so,
inside of this "SetNestToHome folder",
there is a sample.dat file,
and you can just copy the whole contents
of that to your clipboard.
We're going to use this to
test that the function really works.
So, if we click on the "SetNestToHome" function
that was published and click on the "Test Window",
we can paste it into the request body section
and click "Run",
and this will trigger
our function as though it
was triggered with a real event.
You'll see triggered away status set to home.
FunctionSetNest to home succeeded. This is great.
That means that we are ready to rock and roll,
flash devices put them all around the house,
and never ever have to worry about Nest being wrong,
about whether or not we're home again.
So, I hope you enjoyed this tutorial.
Again I want to highlight that,
you can get the hardware for
these devices at particle.io.
All of the services that we've used
here are free on Microsoft Azure.
So, you can set up a free tier IoT hub,
that'll give you up to 8,000
events per month without any charge.
Which is sufficient for
numerous devices around the house,
and also the Azure function which you can trigger up to I
believe it's multiple thousands of
executions before it would incur charges,
and you can solve
this problem with Nest Thermostat not knowing when
you're home simply by
leveraging these technologies in your home,
for around a cost of $20.
So, it's excellent. I hope you've enjoyed this.
So, feel free to leave some messages on the comments
Không có nhận xét nào:
Đăng nhận xét