7

The Nest Thermostat device will display on-screen if it's 'cooling' or 'heating'. How do I get this state through the Nest API?

The hvac_mode property seems to simply show what the user's Thermostat is capable of controlling and doesn't change when either cooling or heating occurs.

For now, I'm using a simple but not flawless logic:

if (can_cool && target_temperature < ambient_temperature) --> isCooling
if (can_heat && target_temperature > ambient_temperature) --> isHeating
else --> isDoingNothing

By not flawless, I mean that I've encountered situations where this logic is incorrect. For example, in a given situation where the ambient_temperature is 20 Celsius and the target_temperature is 21 Celsius with can_heat set to true, my UI will say the Thermostat is heating, while it actually isn't.

This is probably because target and ambient temperatures are too close, but I don't know what the threshold is.

Is there another or better way to figure out heating and cooling states?

Rachid Finge Jr
  • 1,171
  • 10
  • 14

4 Answers4

4

As of May 2015, the Nest API now officially reports the hvac_state property. The value will be one of either 'heating','cooling' or 'off'.

New fields in the data model: hvac_state. You'll use hvac_state to learn if the home HVAC system is actively heating, cooling or is off.

Dal Hundal
  • 3,234
  • 16
  • 21
  • Have you been able to actually read this hvac_state? With my real thermostat (SW version 4.5.1) this field is missing and not reported as part of the thermostat data structure. – RawMean Oct 12 '15 at 00:03
  • Yes, I've used it on my real thermostat - mine is also on v4.5.1 – Dal Hundal Oct 12 '15 at 09:35
2

Looking at the API, they don't provide any way of identifying if the thermostat is actually heating. The closest you can get to identify is what you currently have written.

If the device itself is capable of displaying it's heating or cooling, they must have different code or different methods (such as internal electronics) for identifying that.

DoubleYou
  • 1,057
  • 11
  • 25
  • 1
    Not sure what SO's policy is about my following proposal: in this situation I suggest to contact the developers with the question how they do it... – DoubleYou Oct 16 '14 at 23:55
  • 2
    I think this is part of Nest's stategy to hand over enough control for devs to tinker, but not enough to make replacement apps - when you can't view or edit the schedule, or read the current state, or get any kind of API support from Nest themselves, you're fairly harmless. – thesimm Oct 17 '14 at 12:29
0

Sadly you're correct - the API does not reveal this information.

In my application I've implemented the same logic as you, and have noticed the same issue around edge cases. I suspect that there may be a time-element to it when the ambient temperature is just outside of the target temperature by only a degree or less.

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
-1

You need to track the status of Heat On/off in order to calculate properly. I monitor the NEST at 1 hz and store the last state (On or Off) as a variable. once you have this info you can use the following logic and it will be accurate:

if lastStatus.Contains("Off"))
{
    if (temp_current < temp_setpoint)
        status = "Heat On";
    else
        status = "Heat Off";
}
else if (lastStatus.Contains("On"))
{
    if (temp_current > temp_setpoint)
        status = "Heat Off";
    else
        status = "Heat On";
}
// Do the work....
lastStatus=status;

Note: temp_current and temp_setpoint are returned from the REST http post. Good Luck!

dg99
  • 5,456
  • 3
  • 37
  • 49
Ryan
  • 1
  • 2