gpt4 book ai didi

ubuntu - 我的 Nest 能否测试本地设备是否存在,以确定我是否在家?

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:14 25 4
gpt4 key购买 nike

我有一个 Nest学习恒温器。我认为它会尝试在我离开时使用运动传感器或类似传感器“自动检测”。无论如何,它都不是很准确,更重要的是,它的算法并不透明。

相反,我认为有更好的方法来判断我是否在屋子里......

Nest 在与我的手机相同的子网中提取 IP 地址。

我愿意:

  • 告诉 Nest 我手机(和我妻子的手机)的 IP 地址
  • 要求 Nest 定期(可能每 10 或 15 分钟)ping 这些 IP 地址以进行在线测试
  • 让 Nest 根据这些客观测试更新自己的主场/外场核算机制

这可能通过 Nest API 实现吗? ?

这是否违反了任何 Nest API Prohibitions

这样的客户是否已经存在?

最佳答案

实际上,我想出了如何使用 Nest API 来准确地做到这一点。效果很好!

我创建了一对 Python 脚本,/usr/bin/nest-home/usr/bin/nest-away,它们是 uhome 的一部分我已经上传到 Ubuntu 的包。还有 /usr/bin/uhome 脚本,它处理我的第一个问题——读取 IP/MAC 地址的输入列表,遍历它们以查看是否有任何可 ping 通的,并且基于根据结果​​,标记我们是在家还是在外。

与 Nest 对话的真正魔力在于 3 个后续 API 调用:

  1. 登录并建立授权 token
  2. 检索结构 ID
  3. 更新结构的 away bool 值

完成下面的脚本,或者你可以在 LaunchpadGithub 中找到它。

#!/usr/bin/python
#
# nest-home, nest-away
#
# Copyright 2014 Dustin Kirkland <dustin.kirkland@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import requests
import time
import urllib
import urllib2
import sys
import json
import yaml

# login
with open(os.path.expanduser("~") + "/.uhome/nest.yaml", "r") as stream:
credentials = yaml.load(stream)
#headers = {"user-agent": "Nest/1.1.0.10 CFNetwork/548.0.4", "X-nl-protocol-version": "1"}
headers = {"X-nl-protocol-version": "1"}
response = requests.post("https://home.nest.com/user/login", credentials)
response = json.loads(response.content)
transport_url = response["urls"]["transport_url"]
userid = response["userid"]
headers["Authorization"] = "Basic " + response["access_token"]
headers["X-nl-user-id"] = userid
# get structure id
request = urllib2.Request(transport_url + "/v3/mobile/user." + userid, headers=headers)
response = urllib2.urlopen(request).read()
response = json.loads(response)
structure_id = response["structure"].keys()[0]
# set away, if necessary
currently_away = response["structure"][structure_id]["away"]
if "away" in sys.argv[0] and not currently_away:
data = '{"away_timestamp":' + str(time.time()) + ',"away":true,"away_setter":0}'
new_away = "True"
elif not "away" in sys.argv[0] and currently_away:
data = '{"away_timestamp":' + str(time.time()) + ',"away":false,"away_setter":0}'
new_away = "False"
else:
data = ""
new_away = str(currently_away)
if data:
structure_url = transport_url + "/v2/put/structure" "." + structure_id
request = urllib2.Request(structure_url, data, headers)
try:
urllib2.urlopen(request).read()
except urllib2.URLError:
print "Put operation failed"
print "Nest updated --> away=" + new_away
else:
print "No need to update Nest --> away=" + new_away

关于ubuntu - 我的 Nest 能否测试本地设备是否存在,以确定我是否在家?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27528271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com