Got this working today with HA 2023.4.2 and a Govee H7121 Air Purifier
First, get your Govee API key from the ‘Govee Home’ App: User - About Us - Request API Key. The key is delivered by mail within seconds.
Next, get the device id by using your API key in a curl command against the govee appliance endpoint:
curl --request GET \
--url https://developer-api.govee.com/v1/appliance/devices/ \
--header 'Content-Type: application/json' \
--header 'Govee-API-Key: 00000000-Your-API-Key-000000000'
Create 3 scripts with the device id from previous step:
script:
office_air_purifier_on:
alias: 'Office Air Purifier: On'
sequence:
- service: rest_command.office_air_purifier
data:
device: AA:BB:CC:DD:EE:FF:AA:BB
model: H7121
cmd_name: turn
cmd_value: 'on'
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: input_boolean.turn_on
target:
entity_id: input_boolean.office_purifier_state
mode: single
office_air_purifier_off:
alias: 'Office Air Purifier: Off'
sequence:
- service: rest_command.office_air_purifier
data:
device: AA:BB:CC:DD:EE:FF:AA:BB
model: H7121
cmd_name: turn
cmd_value: 'off'
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: input_boolean.turn_off
target:
entity_id: input_boolean.office_purifier_state
- service: input_select.select_option
entity_id: input_select.office_air_purifier_mode
data:
option: 'Off'
mode: single
office_air_purifier_mode:
alias: 'Office Air Purifier: Mode'
sequence:
- service: input_select.select_option
entity_id: input_select.office_air_purifier_mode
data:
option: '{% set mapper = {16 : ''Sleep'', 1: ''Low'', 2: ''Medium'', 3: ''High''} %} {{ mapper[office_purifier_mode] }}'
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: rest_command.office_air_purifier
data:
device: AA:BB:CC:DD:EE:FF:AA:BB
model: H7121
cmd_name: mode
cmd_value: '{{ office_purifier_mode }}'
- service: input_boolean.turn_on
target:
entity_id: input_boolean.office_purifier_state
mode: single
icon: mdi:air-purifier
Then, create a new secret (e.g. govee_api_key) with the API key and update your configuration.yaml
rest_command:
office_air_purifier:
url: https://developer-api.govee.com/v1/appliance/devices/control
method: PUT
headers:
Content-Type: application/json
Govee-API-Key: !secret govee_api_key
content_type: 'application/json; charset=utf-8'
payload: '{"device": "{{ device }}","model": "{{ model }}","cmd": {"name": "{{ cmd_name }}","value": "{{ cmd_value }}"}}'
verify_ssl: true
fan:
platform: template
fans:
office_air_purifier:
friendly_name: "Office Air Purifier"
value_template: "{{ states('input_boolean.office_purifier_state') }}"
preset_mode_template: "{{ states('input_select.office_air_purifier_mode') }}"
turn_on:
service: script.office_air_purifier_on
turn_off:
service: script.office_air_purifier_off
set_preset_mode:
service: script.office_air_purifier_mode
data:
office_purifier_mode: >
{% set mapper = {'Sleep' : 16, 'Low': 1, 'Medium': 2, 'High': 3} %}
{{ mapper[preset_mode] }}
speed_count: 4
preset_modes:
- 'Low'
- 'Medium'
- 'High'
- 'Sleep'
Then you just need to create the input_boolean and input_select and restart HA.
input_boolean:
office_purifier_state:
name: Office Purifier State
initial: on
icon: mdi:air-filter
input_select:
office_air_purifier_mode:
name: Office Air Purifier Mode
options:
- "Low"
- "Medium"
- "High"
- "Sleep"
- "Off"
icon: mdi:air-filter
After the restart, you’ll have a few new entities one of which is the glorious fan.office_air_purifier
Also made a pretty awesome little custom:button-card which is working perfectly for the Govee H7121 Air Purifier
- type: 'custom:button-card'
color_type: label-card
styles:
card:
- padding: 0
name:
- border-radius: 0.4em 0.4em 0 0
- padding: 0.1em
- width: 100%
- font-weight: bold
grid:
- grid-template-areas: '"i" "n" "buttons"'
- grid-template-columns: 1fr
- grid-template-rows: 1fr min-content min-content
custom_fields:
buttons:
- background-color: 'rgba(0,0,0,0.2)'
- margin: 0
- padding: 0.3em
color: rgb(67, 73, 82)
name: Office Air Purifier
custom_fields:
buttons:
card:
type: horizontal-stack
cards:
- type: "custom:button-card"
entity: input_select.office_air_purifier_mode
color_type: card
name: Sleep
state:
- value: 'Sleep'
icon: mdi:power-sleep
color: rgb(46, 204, 64)
- value: 'Low'
icon: mdi:power-sleep
color: rgb(67, 73, 82)
- value: 'Medium'
icon: mdi:power-sleep
color: rgb(67, 73, 82)
- value: 'High'
icon: mdi:power-sleep
color: rgb(67, 73, 82)
- value: 'Off'
icon: mdi:power-sleep
color: rgb(67, 73, 82)
style:
- color: var(--icon-off-color)
tap_action:
action: call-service
service: fan.set_preset_mode
service_data:
entity_id: fan.office_air_purifier
preset_mode: Sleep
- type: "custom:button-card"
entity: input_select.office_air_purifier_mode
color_type: card
name: Low
state:
- value: 'Sleep'
icon: mdi:fan-speed-1
color: rgb(67, 73, 82)
- value: 'Low'
icon: mdi:fan-speed-1
color: rgb(46, 204, 64)
- value: 'Medium'
icon: mdi:fan-speed-1
color: rgb(67, 73, 82)
- value: 'High'
icon: mdi:fan-speed-1
color: rgb(67, 73, 82)
- value: 'Off'
icon: mdi:fan-speed-1
color: rgb(67, 73, 82)
style:
- color: var(--icon-off-color)
tap_action:
action: call-service
service: fan.set_preset_mode
service_data:
entity_id: fan.office_air_purifier
preset_mode: Low
- type: "custom:button-card"
entity: input_select.office_air_purifier_mode
color_type: card
name: Medium
state:
- value: 'Sleep'
icon: mdi:fan-speed-2
color: rgb(67, 73, 82)
- value: 'Low'
icon: mdi:fan-speed-2
color: rgb(67, 73, 82)
- value: 'Medium'
icon: mdi:fan-speed-2
color: rgb(46, 204, 64)
- value: 'High'
icon: mdi:fan-speed-2
color: rgb(67, 73, 82)
- value: 'Off'
icon: mdi:fan-speed-2
color: rgb(67, 73, 82)
style:
- color: var(--icon-off-color)
tap_action:
action: call-service
service: fan.set_preset_mode
service_data:
entity_id: fan.office_air_purifier
preset_mode: Medium
- type: "custom:button-card"
entity: input_select.office_air_purifier_mode
color_type: card
name: High
state:
- value: 'Sleep'
icon: mdi:fan-speed-3
color: rgb(67, 73, 82)
- value: 'Low'
icon: mdi:fan-speed-3
color: rgb(67, 73, 82)
- value: 'Medium'
icon: mdi:fan-speed-3
color: rgb(67, 73, 82)
- value: 'High'
icon: mdi:fan-speed-3
color: rgb(46, 204, 64)
- value: 'Off'
icon: mdi:fan-speed-3
color: rgb(67, 73, 82)
style:
- color: var(--icon-off-color)
tap_action:
action: call-service
service: fan.set_preset_mode
service_data:
entity_id: fan.office_air_purifier
preset_mode: High
- type: "custom:button-card"
icon: mdi:power
color_type: card
entity: input_boolean.office_purifier_state
name: Power
tap_action:
action: call-service
service: fan.turn_off
service_data:
entity_id: fan.office_air_purifier
state:
- value: 'off'
color: rgb(255, 220, 0)
- value: 'on'
color: rgb(255, 65, 54)
style:
- color: var(--icon-off-color)
TL;DR: Govee H7121 Air Purifier · ntalekt/homeassistant@ec11422 · GitHub