首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >两种恒温器模式的嵌套api目标温度

两种恒温器模式的嵌套api目标温度
EN

Stack Overflow用户
提问于 2014-10-08 01:55:45
回答 2查看 973关注 0票数 1

是否可以在一次调用中获取两种恒温器模式(冷、热)的目标温度?现在我有一种感觉,我可以获得当前恒温器模式的目标温度,然后将恒温器模式更改为第二个模式,并获得第二个恒温器模式的目标温度。

同样的问题也适用于改变目标温度。是否可以在一次请求中同时更改热模式和冷模式的目标温度?

EN

回答 2

Stack Overflow用户

发布于 2014-10-08 03:49:54

假设你的系统可以冷却和加热,恒温器有3种模式:热,冷,热-冷。

如果您处于热模式或冷模式,则可以设置target_temperature。如果你处于热-冷模式,你可以设置target_temperature_low_c & target_temperature_high_c。

您可以在一个恒温器调用中检索所有目标温度:

代码语言:javascript
运行
复制
https://developer-api.nest.com/devices/thermostats/$THERMOSTAT_ID?auth=$AUTH

您可以在一个调用中设置冷热温度,但您需要处于冷热模式:

代码语言:javascript
运行
复制
{"target_temperature_low_c": 19, "target_temperature_high_c": 21}

您可以在一个调用中设置heat cool温度,但您需要处于heat cool模式:

代码语言:javascript
运行
复制
{"target_temperature_c": 20}

如果您尚未处于适当的模式,则需要进行2次呼叫来设置模式和温度。

票数 2
EN

Stack Overflow用户

发布于 2014-10-28 11:09:25

可以获得所有的恒温器数据,甚至可以在单个API调用中获得多个恒温器的数据。我刚刚在BitBucket上发布了一个用python编写的开源应用程序,它可以做到这一点:

https://bitbucket.org/dwalton64_/window-watcher

该应用程序查看来自地下天气的天气数据、来自airnow的空气质量数据和来自Nest的数据,以确定用户是否应该打开或关闭窗口。我对Nest进行API调用,在一次调用中获得所有数据,然后在一个结构中解析数据。然后,应用程序使用恒温器hvac模式和目标温度来查看用户是否应该打开窗口。

以下是我从应用程序中提取的一些Python代码:

代码语言:javascript
运行
复制
nestUserUrl = "https://developer-api.nest.com/?auth=" + auth_token
nest_user_file = urllib2.urlopen(self.nestUserUrl)
nest_user_json = json.loads(nest_user_file.read())

# copy thermostat data out of the json from Nest
thermostat_data = []
for tstat_id in nest_user_json['devices']['thermostats']:
     thermostat_data.append(nest_user_json['devices']['thermostats'][tstat_id])

# create thermostat objects containing the thermostat data we want to access
thermostats = []
for tstat in thermostat_data:
    thermostats.append(
          NestThermostat(tstat['ambient_temperature_f'], tstat['device_id'],
                         tstat['hvac_mode'],
                         tstat['is_online'], tstat['last_connection'],
                         tstat['name'],
                         tstat['software_version'], tstat['structure_id'], 
                         tstat['target_temperature_f'],
                         tstat['target_temperature_high_f'],                       
                         tstat['target_temperature_low_f']))

class NestThermostat():
    def __init__(self, ambient_temperature_f, device_id, hvac_mode, is_online,
                 last_connection, name, software_version, structure_id,
                 target_temperature_f, target_temperature_high_f, target_temperature_low_f):
        self.ambient_temperature_f = ambient_temperature_f
        self.device_id = device_id
        self.hvac_mode = hvac_mode
        self.is_online = is_online
        self.last_connection = last_connection
        self.name = name
        self.software_version = software_version
        self.structure_id = structure_id
        self.target_temperature_f = target_temperature_f
        self.target_temperature_high_f = target_temperature_high_f
        self.target_temperature_low_f = target_temperature_low_f

    def print_current_temp_f(self):
        print("Thermostat " + self.name + " measures a current temperature of " + str(
            self.ambient_temperature_f) + " degrees F")

    def print_target_temp_f(self):
        print("Thermostat " + self.name + " is set to " + str(self.target_temperature_f) + " degrees F")

一旦我在恒温器对象中有了数据,我就可以使用hvac模式和目标温度:

代码语言:javascript
运行
复制
email = ""
for thermostat in thermostats:
    email += "For the thermostat " + thermostat.name + ":\n"
     if thermostat.hvac_mode == 'cool':
         if myWeather.temp_f < thermostat.target_temperature_f:
             open_windows = True
             email += " - It is cool outside (" + str(myWeather.temp_f) + " Deg F). \n"
         else:
             email += " - It is too hot outside to have the windows open. \n"
         email += " - Thermostat is set at " + str(thermostat.target_temperature_f) + \
                  " Deg F\n"

     if thermostat.hvac_mode == 'heat-cool':
         if thermostat.target_temperature_high_f > myWeather.temp_f > thermostat.target_temperature_low_f:
             open_windows = True
             email += " - Thermostat is set to heat-cool and it's comfortable out (" + \
                              str(myWeather.temp_f) + " Deg F). \n"
         elif myWeather.temp_f >= thermostat.target_temperature_high_f:
             email += " - The thermostat is set to heat-cool and it is hot outside (" + \
                      str(myWeather.temp_f) + " Deg F). \n"
         else:
             email += " - The thermostat is set to heat-cool & it is cold outside (" + \
                      str(myWeather.temp_f) + " Deg F). \n"
         email += " - The thermostat is set to cool at " + \
                  str(thermostat.target_temperature_high_f) + " Deg F\n"
         email += " - The thermostat is set to heat at " + \
                  str(thermostat.target_temperature_low_f) + " Deg F\n"

     if thermostat.hvac_mode == 'heat':
         if myWeather.temp_f > thermostat.target_temperature_f:
             open_windows = True
             email += " - The thermostat is set to heat and it is warm outside (" + \
                      str(myWeather.temp_f) + " Deg F). \n"
         else:
             email += " - The thermostat is set to heat and it is cool outside (" + \
                      str(myWeather.temp_f) + " Deg F). \n"
         email += " - Thermostat is set at " + str(thermostat.target_temperature_f) + \
                  " Deg F\n"

     email += "\n"

注意,热模式和冷模式的目标温度是相同的值: target_temperature_f。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26242165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档