Does Nest provide an API for my app to auto-detect/discover a new device being added - nest-api

I created an app using the API instructions at developer.nest.com website. So the app can get a list of existing devices and control them the way I want.
But what if I want the app to do something special anytime I add a new device? Is this possible today? Has anyone done this successfully?

you can listen to updates several different ways. It depends on what you're using: Firebase, Rest Stream, Rest polling, etc.
Basically, you'll need to create a Listener in your code, and after that check on triggered events. You can listen to different levels: structure or the whole account (root level).
If you have a Rest stream, you can check out this curl command to see what's getting triggered in JSON:
1.Open console and Nest developer tool
Run this at the console (root level) with the access token* you have for your client :
curl -L -v "https://developer-api.nest.com?auth=" -H "Accept: text/event-stream”
3.Remove any thermostat from your virtual account.
4.Check the triggered events in the console: you'll have your JSON missing the data for the thermostat you just removed.
5.Now go one level up to the structures: curl -L -v "https://developer-api.nest.com/structures/?auth=" -H "Accept: text/event-stream”
Repeat the same procedure with the virtual devices.
*To get access token for your client go here: https://developer.nest.com/documentation/cloud/how-to-auth
In case you want to check this out on a code level, you can find it in the Nest Sample Code. All of the samples have Listeners which allow you to see any changes happening to the thermostats in the account/structure.
P.S. It's better to use Firebase or Rest Stream if you want those events to be triggered real-time.

Related

Communicating with a remote server via microsoft Teams

Scenario:
I have a remote server which is monitored (via DataDog) and sends out a warning when some anomaly is detected. This warning can be fetched via a webhook. Now I want to connect that webhook (https://docs.datadoghq.com/integrations/webhooks/) with MS Teams (probably via Bot), to receive a warning. Then I want to send a command back to the remote server to resolve the warning.
Technology:
MS Teams, Python flask/Django, remote server
Expected Results:
I can receive a warning from my remote server to MS Teams via a bot. Then send a command back to the remote server. My initial plan is doing this using Python Flask/Django but not tied to a specific language.
Environment:
Remote server is a LINUX based system. we have a internal network that is used within our company, so might need to resolve a firewall problem potentially (idk whole lot about it tho).
Things I have tried:
I just want to see if this is possible or not, so i havent coded up any. But I found some information relevant to our problem:
https://docs.datadoghq.com/integrations/webhooks/
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/create-a-bot-for-teams
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors
One last note, I am not also tied down to Teams bot. Our company also uses Azure Devops, so that is another resource I can use to realize the solution.
Btw, this question was posted on here but was told to post on MSDN, but I couldn't find an appropriate forum. Hence, I am posting on stack overflow instead
As you have limited requirements, you could achieve this without a bot.
MS Teams has income and outgoing webhooks. You could create a Incoming webhook inside a Teams channel. It provides an URL which you could use inside the monitoring remote server and POST the message in JSON format to the webhook url. It will be posted in teams channel like below
For sending message back to the server you need to configure the Outgoing webhook in the channel.

NodeRed: How to get reply from Slack app interactive message

I'm trying to make it so that NodeRed uses a webhook to send an interactive message to a slack app to ask permission to activate something. I can POST to the webhook without any issues from my custom node, but how do I get the reply?
Do I need to use the "http in" node to create an endpoint Slack can use? Is there a way to handle it from the same node that POSTs the message?
Also, I'm running NodeRed locally. Can I use ngrok so that Slack can access the http endpoint (in case I need to use that)?
You can define your own http endpoints that are private to your custom node, this is how nodes that need to do oAuth handle the callback. Also nodes like the serial port node do this to supply information to the config dialog.
Make sure to give the endpoint a unique route so it's unlikely to clash with any other nodes.
You can look at the source for the serial port node here
How you ensure that Node-RED is safely made accessible from the internet should be a separate question.
1) Yes, ngrok works nicely for exposing your local webserver securely to the Internet and Slack. I use it every day for my Slack app development. Keep in mind that if your app can't be reached from the Internet, then also Slack can not reach it.
2) Interactive Messages only work with Slack apps. One reason being that you need to provide the route to your app, so that Slack knows where to send the requests when someone uses your interactive messages (e.g. clicks on a button). But you can use interactive messages with webhooks, as long as both are setup within the same Slack app.
3) Don't believe the "http-in node" approach will work. As said, you need to configure the route to your app for receiving messages from Slack in your Slack appp.

How to disconnect FireBase sockets?

I am using firebase in NodeJs for getting motion detection events from Nest Camera.
I am connecting using the following code as I need multiple socket connections for each nest user.
this.context = new Firebase.Context();
this.firebaseClient = new Firebase(config.nest.firebaseSocketUrl, this.context);
I want to disconnect a particular socket whenever a user changes its mode to standby or home.
As per firebase documentation, you can use Firebase.goOffline() which is not useful in my case. How can I disconnect a specific firebase socket?
Firebase Engineer here,
I've answered a similar question regarding how Nest and Firebase interact here, but I'll provide a little more color on how you can get data from multiple Nest devices on a single client.
In short, Nest stores data in a structure that looks like:
users
$userID
devices
$deviceID
// info about devices
When you call authWithCustomToken(), you're taken down to the appropriate $userID, and can subscribe to changes on those users' devices. This means you can't really access data across multiple users' devices since by authenticating you "move down the tree" to that user data. There's no way to move up (typically you could call parent(), but this doesn't work in Nest Firebase land).
Since a Firebase realtime database connection takes a single auth token per conncetion, you would have to auth() and unauth() multiple times to do this (going offline and online doesn't really do it, as we'll continue to use the same connection), and I highly suggest you avoid doing this, as it won't scale well.
Instead, you should use the streaming REST API, which allows you to create streaming REST connections, each authenticated with the user token. You can also control when these connections are open/closed. It's a little more work to manage, but if you're aiming for granular control, this is the level of control you're looking for. Some examples are here.
We're working with Nest to create a better experience here, but for now this is what we both recommend.

Asterisk: connect one channel to another with AMI

I've got Asterisk 11.4.0, a remote cloud server and a Node.js server as middleware. When any account tries to make a call, I need information from remote server which external line to use (or even not make this call at all!). Those data can't be calculated directly in Asterisk. Only after cloud's response the call must be proceeded. My action queue looks like this:
Capture the call initiation from Asterisk with AMI on middle server;
Send info to cloud for analysis;
Proceed a call with passed in response external line using AMI (or not proceed at all);
The problem is, I don't know how to make it. I think, when one tries to make a call, I can use WaitExten in dialplan option and capture Newchannel event with middle server, sending all information to cloud. When it responses, I can originate the call, using existing waiting line.
Can you tell me, how can I attach channel to Originate operation, when i pass it as "channel" parameter, Asterisk do not connect this line with called exten.
You need use FastAGI or AGI(fastagi faster but slighly more complex) to control call flow of your channel.
http://www.voip-info.org/wiki/view/Asterisk+FastAGI
In AGI you can get call info, decide where to place it, after that make call using Dial command. Calls will be bridged automaticaly.
http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial
Also you can use Bridge ami action to bridge 2 channels, but that is not how it have be created. Correct way - via Dial.
http://www.voip-info.org/wiki/view/Asterisk+cmd+Bridge
Also you can use in dialplan CURL function to request help via http on external API. That will have same cost as fastagi, but can be simpler for your since you like node.js
If you use Originate ami command, you can add to that command any variables via
"Set" => "variablename=somethign"
PS actually almost anything can be calculated inside asterisk, sure if you have enought knowledge about that. Asterisk have full language(mean you can describe any algorithm in dialplan), have function to request db info etc.
DISCLAIMER: I recommend read asterisk book like "Asterisk the future of telephony" BEFORE creating any design of application with use of asterisk pbx. If you ignore this warning, your app can be unstable and require full rewrite after you put it in production.

How Nest thermostat communicates

I want to build a Raspberry Pi (RPi) based device similar to the Nest Thermostat, except that I want to control light switches. I know I could easily code up a Node.js script on the RPi and then just hook it up to my local router and control it with a PC hooked up to the same router.
But, I want to make it more like a Nest. I want to be able to control 20 (or more) RPis across different subnets through a cloud provider like Heroku.
The Nest thermostat does not require the user to open a port on their router so that the Nest server can communicate with it.
How is Nest able to control customer's thermostats over the web without enabling port forwarding in the customer's router?
Blog post Nest Thermostat API using Node JS and Nest API Update discusses the API
between the thermostat and the nest lab servers. In particular:
The API uses mostly JSON formatted data POSTed to their web servers.
So there is your answer. By periodically POSTing data to the nest web servers using HTTPS, Nest is able to avoid having the user open any ports on their router.
For what it's worth, the unofficial API (in node.js!) from the blog post is available on github: Unofficial Nest API on Node.
I think the thermostat periodically posts a request with the thermostat serial number to nest. It may have timeouts in the http headers set to infinity or more likely, the nest server simply closes the connection after a minute or so if no command for that device has come in. Whenever nest closes the connection the thermostat opens a new one. When a command request comes in with serial number, its a quick lookup to find the thread currently connected to that thermostat. The command is sent in the payload of the current thermostat request, which is executed, the connection is closed, and the thermostat opens a new request to nest .
Take a look at eventSource in the HTML 5 standard. It does everything that is required.

Resources