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!