Honeywell T9 and Setup for OAuth with Refresh Tokens

Long time reader, first time poster…

I was looking for information on how to get my Honeywell T9 integrated with Home Assistant and didn’t find a ton, so I thought I’d post what I cobbled together. It’s been working well for a few weeks.

The main challenges were figuring out how to make the Honeywell API calls with all the right template variables and refreshing/storing the OAuth access and refresh tokens.

First step - sign up for a developer account with Honeywell:
https://developer.honeywellhome.com/

Follow the authentication steps listed and get the initial set of access and refresh tokens.

Second step - Home Assistant setup:

First, I created some input text variables to store the tokens:

input_text:
  honeywellhome_token_refresh:

  honeywellhome_token_access:

Second, I created a command line sensor to retrieve the tokens:

sensor:
  - platform: command_line
    name: HoneywellHomeTokens
    scan_interval: 1780
    command: > 
        curl --location --request POST 'https://api.honeywell.com/oauth2/token'
        --header 'Authorization: Basic [See Honeywell Documentation]'
        --header 'Content-Type: application/x-www-form-urlencoded'
        --data-urlencode 'grant_type=refresh_token'
        --data-urlencode 'refresh_token={{ states('input_text.honeywellhome_token_refresh') }}'
    json_attributes:
      - "access_token"
      - "refresh_token"
      - "expires_in"
    value_template: "{{ now() }}"

Third, I created an automation to store the tokens from the sensor in the input text variables:

automation:
  - id: HoneywellSaveRefresh
    alias: Save Refresh Token to Variables
    trigger:
      - platform: state
        entity_id: sensor.honeywellhometokens
      - platform: homeassistant
        event: start
    action:
      - service: input_text.set_value
        target:
          entity_id: input_text.honeywellhome_token_refresh
        data:
          value: "{{ state_attr('sensor.honeywellhometokens','refresh_token') }}"
      - service: input_text.set_value
        target:
          entity_id: input_text.honeywellhome_token_access
        data:
          value: "{{ state_attr('sensor.honeywellhometokens','access_token') }}"

Couple of comments:

  • The reason I used Now() as the value template on the command line sensor is so that the state would change with each call (and therefore trigger my automation to store the tokens.)
  • I also added a trigger on start because the state trigger doesn’t fire when the sensor initiates after a restart.
  • Set the scan interval on the command line to some value less than the expiry of the refresh token.
  • I spent a while trying to get the REST sensor to work, but ultimately had to use the command line because of the template in the payload.

Once that is setup, manually add a good refresh token to the input text variable. The next time the command line sensor runs, it’ll use it to get new batch of tokens. Once that’s done, you’ll always have a hot and fresh access token for whatever API calls you want to make. This refresh process has been working for a few weeks without issue.

Here’s some more yaml to get some of T9 thermostat values:

sensor:
  - platform: command_line
    name: HoneywellHomeTemps
    scan_interval: 180
    command: > 
        curl --location --request GET 'https://api.honeywell.com/v2/devices/thermostats/[deviceId]/group/0/rooms?apikey=[apikey]&locationId=[locationId]'
        --header 'Authorization: Bearer {{ states('input_text.honeywellhome_token_access') }}'
    json_attributes:
      - "rooms"
      - "deviceId"
    value_template: "{{ now() }}"

  - platform: command_line
    name: HoneywellHomeStatus
    scan_interval: 180
    command: > 
        curl --location --request GET 'https://api.honeywell.com/v2/devices/thermostats/[deviceId]?apikey=[apikey]&locationId=[locationId]'
        --header 'Authorization: Bearer {{ states('input_text.honeywellhome_token_access') }}'
    json_attributes:
      - "vacationHold"
      - "settings"
      - "changeableValues"
      - "operationStatus"
    value_template: "{{ now() }}"

  - platform: template
    sensors:
      thermostat_temp:
        value_template: "{{ state_attr('sensor.honeywellhometemps','rooms')[0]['avgTemperature'] | int }}"
        friendly_name: Thermostat Temp
        unit_of_measurement: "°F"
        device_class: temperature
      upstairs_temp:
        value_template: "{{ state_attr('sensor.honeywellhometemps','rooms')[1]['avgTemperature'] | int }}"
        friendly_name: Upstairs Temp
        unit_of_measurement: "°F"
        device_class: temperature
      thermostat_humidity:
        value_template: "{{ state_attr('sensor.honeywellhometemps','rooms')[0]['avgHumidity'] | int }}"
        friendly_name: Thermostat Humidity
        unit_of_measurement: "%"
        device_class: humidity
      upstairs_humidity:
        value_template: "{{ state_attr('sensor.honeywellhometemps','rooms')[1]['avgHumidity'] | int }}"
        friendly_name: Upstairs Humidity
        unit_of_measurement: "%"
        device_class: humidity
      thermostat_status:
        value_template: >
                    {% if state_attr('sensor.honeywellhomestatus','operationStatus')['mode'] == 'EquipmentOff' -%}
                    Off
                    {% elif state_attr('sensor.honeywellhomestatus','operationStatus')['mode'] == 'cool' -%}
                    Cooling
                    {% elif state_attr('sensor.honeywellhomestatus','operationStatus')['mode'] == 'heat' -%}
                    Heating
                    {%- endif %}
        friendly_name: Thermostat Status
      thermostat_fan_status:
        value_template: "{{ state_attr('sensor.honeywellhomestatus','settings')['fan']['changeableValues']['mode'] }}"
        friendly_name: Thermostat Fan Status

You could also add some commands to control the thermostat - haven’t played with that yet.

Any helpful comments/improvements are welcome!

1 Like

Well idk this is all covered by the existing lyric integration. I have a T9 that admittedly the integration sucked for, but for the last 6 months has been working. The only thing missing is getting the remote temps and occupancy sensors . Have you considered contributing to that project rather than creating another?

This is incredible - just got this working. OAuth was kind of a pain.

Would love there was also functionality to change the temp etc.

Strong work!

Thanks for this. I’ve been able to add some abilities that the other Honeywell integrations don’t have like changing schedules or room priority. I know I can control the schedule through HA/node red, but I prefer to keep as much settings in the thermostat itself in case the server or internet goes down, then nudge it to do what I want with automation.

A problem I’ve been having with your instructions, though, is that if I lose internet for longer than the refresh expiration period, my tokens don’t get updated and and my input_texts go to ‘unavailable’. Any one have similar experiences or a work around? Is it possible to automate the auth2 token grab?

Thanks!

T9’s got a firmware update and now support homekit. The homekit integration does not require apple hardware and is local, no internet needed.

Goto integrations choose homekit add ip and get the homekit code from the unit and your done.

1 Like

I use the homekit integration for most things and used Smart things and all the other Honeywell integrations prior to that. But like I said, they’re all missing functionality that I want them to do that can be done via API calls. I work swing shifts so normal schedules don’t work for me and I need a way to dynamically change the thermostat. Unless someone knows a way to change the room priority, schedules, and all that extra functionality via the homekit, I rather use it. Until then, I need to make this work.

I didn’t know the homekit integration was local; that’s good know and a bit shocking. Kudos to Honeywell. Little things like that means they’ll get my business over others; something a lot of smart home companies haven’t figured out.

I appreciate that bit of info, thanks.

Since homekit is local, I’ve moved all my scheduling to HA. I only need to worry that HA isn’t down. In reality even if HA is down the worst is it is stuck at the low/high set point.

All the addon sensors are broken out with the occupancy(air) sensor as well, so you can set the room priority through automations.

Sure, I get that. But there can still be things that go wrong- router or server issues and all that. Most things don’t matter if it doesn’t work, but I’d still rather use the built in features and tweak that on something like the furnace. Where I live, crap freezes quickly in the winter.

I live in the NE US so I understand the damage freezing temps can do. I even keep a honeywell mechanical button thermostat as a fallback. It is set at 60 in case the t9 just straight out breaks.

I set the main thermostat as the priority, no other remote sensors. Now when I need that room to be the priority I’ll use the thermostat with climate.set_temperature.

Now when I want another area to be the priority I’ll set the thermostat to 65. I had esphome temp sensors all over the boiler already so I added a relay switch. When I want the other area a priority I use the relay to turn on/off the boiler.

Esphome lets me set a fall back automation that the relay will automatically shut off after a set period of time, should HA fail.

To sum up the main thermostat is never set below 65. Should every thing fail the old mechanical will turn on the boiler at 60.

Thanks… I moved to the Homekit integration. Got me everything I needed! I’ll still keep the sensors and automations above - just commented out - in case I need OAuth for anything else.

Yeah… I had that issue too. Every month or two I’d lose my tokens and have to re auth with Honeywell (I just used Postman.) I’m going to give the HomeKit integration that Mikefila suggested a try.

The Homekit integration is good. I do like it and use it for a majority of my automations. A lot better than both the Lyric and SmartThings integrations. It just doesn’t have everything the API has.

Hoping you can help me. I am trying to get my t9 to show up in home assistant. I tried pairing to homekit and that worked great, I can control it from m iPhone with no issues. I remove it from homekit and then try to add the homekit controller in HA and it never shows up. You mention adding the IP for the t9 in HA, where do you do that? maybe that is the piece I am missing? And help would be greatly appreciated!

@Mikefila Disregard this. I was not using host networking in docker. I added the homekit integration and is working now.

Question how did you do this part that you mentioned in an earlier post? I dont see where I can change to room priority, just changing the mode is all that I see available…

All the addon sensors are broken out with the occupancy(air) sensor as well, so you can set the room priority through automations.

Automations in home assistant. Besides not being able to set the room priority, you can’t change the schedule itself either. I have just a barebones schedule in the T9, everything else is in HA.

Since each room sensor is a separate entity, unlike the original integration, you choose the room by setting automations to trigger off the corresponding sensor.

Ok so what you are saying is that you monitor the remote sensor and then take your own action at the tstat. In other words I want cooling at 70 degrees, tstat is at 70 in the hallway, AC is off. Master bedroom is 74, HA automation would nudge the temp down to try to get the room to 70?

I was thinking that you were changing the sensor priority (adding removing sensors etc)

Yes, I do this in nodered though so I can’t help you with yaml. The climate attribute current_temperature: is the temperature shown on the t9 that controls the thermostat. The temperature shown on the device depends on what is set as priority. I just leave it set on the t9 with no additional sensors.

If I want the heat to come up the automation gets that number and adds one. The turn off sequence, I use my minimum set point for the room the t9 is in.

I have 3 Honeywell T10s (same as T9s) and the problem I have is the sensors are sharing unique IDs. It looks like the first one added to each Tstat has the same ID. Same goes for the second, third, etc. So I can’t use my thermostats with HA.

Which integration? homekit or lyric? Have you tried both, is it the same outcome? FWIW I though I read that all uuid are randomly generated and shouldn’t duplicate them.