简体   繁体   English

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

[英]nest api target temperature for both thermostat modes

Is it possible to fetch target temperature for both thermostat mode (cool, heat) in one call ? 一次调用是否可以获取两种恒温器模式(冷,热)的目标温度? For now I have a feeling that I can get target temperature for current thermostat mode and then change thermostat mode to second one and get target temperature for second thermostat mode. 现在,我感觉可以获取当前恒温器模式的目标温度,然后将恒温器模式更改为第二个,并获取第二个恒温器模式的目标温度。

Also the same question for changing target temps. 对于改变目标温度也有同样的问题。 Is it possible to change both target temperature for heat and cool mode in one request ? 是否可以在一个请求中更改供热和制冷模式的目标温度?

Assuming your system can cool and heat, the thermostat has 3 modes: heat, cool, heat-cool. 假设您的系统可以冷却和加热,则恒温器具有3种模式:加热,冷却,加热冷却。

If you are in heat mode or cool mode you can set target_temperature. 如果处于热模式或冷模式,则可以设置target_temperature。 If you are in heat-cool mode you can set target_temperature_low_c & target_temperature_high_c. 如果处于冷热模式,则可以设置target_temperature_low_c和target_temperature_high_c。

You can retrieve all target temperatures in one thermostat call: 您可以在一个恒温器调用中检索所有目标温度:

https://developer-api.nest.com/devices/thermostats/$THERMOSTAT_ID?auth=$AUTH

You can set heat-cool temperatures in one call, but you will need to be in heat-cool mode: 您可以在一个呼叫中设置冷热温度,但是您将需要处于冷热模式:

{"target_temperature_low_c": 19, "target_temperature_high_c": 21}

You can set heat or cool temperature in one call, but you will need to be in heat or cool mode: 您可以在一个呼叫中设置加热冷却温度,但是您需要处于加热冷却模式:

{"target_temperature_c": 20}

You will need to make 2 calls to set the mode and set the temperature(s) if you are not already in an appropriate mode. 如果您尚未处于适当的模式,则需要拨打2个电话来设置模式和设置温度。

It is possible to get all of the thermostat data, even for multiple thermostats in a single API call. 甚至可以在一个API调用中获得多个恒温器的所有恒温器数据。 I just posted an opensource application written in python that does it on BitBucket at: 我刚刚在BitBucket上发布了一个用python编写的开源应用程序,该应用程序位于:

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

The application looks at weather data from weather underground, air quality data from airnow and data from Nest to determine if the user should open or close the windows. 该应用程序查看来自地下天气的天气数据,来自airnow的空气质量数据以及来自Nest的数据,以确定用户是否应该打开或关闭窗户。 I make the API call to Nest, getting all of the data in a single call, and then parse the data in a structure. 我对Nest进行API调用,一次调用即可获取所有数据,然后将其解析为结构。 The application then uses the thermostat hvac mode and the target temperature to see if the user should open the windows. 然后,应用程序使用恒温器暖通空调模式和目标温度来查看用户是否应该打开窗户。

Here is some Python code I pulled out of my application: 这是我从应用程序中提取的一些Python代码:

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")

Once I have the data in the thermostat objects, I can use both the hvac mode and the target temperatures: 一旦将数据保存在恒温器对象中,就可以使用hvac模式和目标温度:

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"

Note that the target temperature for heat and cool mode is the same value: target_temperature_f. 请注意,供热和制冷模式的目标温度是相同的值:target_temperature_f。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM