I have my 2 of my 3 fans up and running in Home assistant. Last one isn’t supported yet.
The boxes in red are the bond elements.
Here are the scripts needed to adjust input booleans and call commands to control the fans so it will remember it’s state.
#Bond Fan Controls
script:
bond_fan_on:
sequence:
- condition: template
value_template: "{{ is_state('input_boolean.' + fan + '_state', 'off') }}"
- service: script.bond_fan_set_speed
data_template:
fan: "{{ fan }}"
speed: "{{ states('input_select.' + fan + '_speed') }}"
bond_fan_off:
sequence:
- condition: template
value_template: "{{ is_state('input_boolean.' + fan + '_state', 'on') }}"
- service: input_boolean.turn_off
data_template:
entity_id: "{{ 'input_boolean.' + fan + '_state' }}"
- service_template: "{{ 'rest_command.' + fan + '_pwr' }}"
bond_fan_set_speed:
sequence:
- condition: template
value_template: "{{ is_state('input_boolean.' + fan + '_state', 'off') or not is_state('input_select.' + fan + '_speed', speed) }}"
- condition: template
value_template: "{{ speed in(states.input_select[fan+'_speed'].attributes.options) }}"
- service: input_boolean.turn_on
data_template:
entity_id: "{{ 'input_boolean.' + fan + '_state' }}"
- service: input_select.select_option
data_template:
entity_id: "{{ 'input_select.' + fan + '_speed' }}"
option: "{{ speed }}"
- service_template: >
{% if speed == 'low' %}
{{ 'rest_command.' + fan + '_spd_low' }}
{% elif speed == 'medium' %}
{{ 'rest_command.' + fan + '_spd_medium' }}
{% elif speed == 'high' %}
{{ 'rest_command.' + fan + '_spd_high' }}
{% endif %}
lr_fan_light_adjust:
sequence:
- delay: 00:00:01
- service: rest_command.lr_fan_light_toggle
The last script I use is for a fan where power turns off the light and if I want the fan off and the light on. If the light is on and the fan powers off this turns it back on. The 1 second delay is to allow bond to send the off command first.
Here are the rest commands I am using to control them.
rest_command:
lr_fan_light_toggle:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/5e68e953/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_spd_low:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/7dfe8fee/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_spd_medium:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/2e2492b2/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_spd_high:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/60e0d6c8/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_pwr:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/65e454ae/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_spd_breeze:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/323eb661/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
lr_fan_light_dimmer:
url: http://<bond IP>/v2/devices/<lr_fan ID>/commands/75479e79/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
mbr_fan_light_toggle:
url: http://<bond IP>/v2/devices/<mbr_fan ID>/commands/0000003f/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
mbr_fan_spd_low:
url: http://<bond IP>/v2/devices/<mbr_fan ID>/commands/00000033/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
mbr_fan_spd_medium:
url: http://<bond IP>/v2/devices/<mbr_fan ID>/commands/00000039/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
mbr_fan_spd_high:
url: http://<bond IP>/v2/devices/<mbr_fan ID>/commands/00000036/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
mbr_fan_pwr:
url: http://<bond IP>/v2/devices/<mbr_fan ID>/commands/0000003c/tx
method: PUT
headers:
content_type: 'application/json'
'BOND-Token': !secret bond_token
payload: '{}'
Lastly the automations that drive it all.
#Bond-o-mations
automation:
- alias: "Living Room Fan Light On"
trigger:
platform: state
entity_id: input_boolean.lr_fan_light
from: "off"
to: "on"
action:
- service: rest_command.lr_fan_light_toggle
- alias: "Living Room Fan Light Off"
trigger:
platform: state
entity_id: input_boolean.lr_fan_light
from: "on"
to: "off"
action:
- service: rest_command.lr_fan_light_toggle
- alias: "Living Room Fan Light Adjust"
trigger:
platform: state
entity_id: input_boolean.lr_fan_state
from: "on"
to: "off"
action:
- service_template: >
{% if is_state('switch.living_fan_light', 'on') %}
script.lr_fan_light_adjust
{% else %}
script.nothing
{% endif %}
- alias: "Master Bedroom Fan Boolean Toggle"
trigger:
- event_data:
args:
click_type: single
command: click
device_ieee: <zigbee button>
event_type: zha_event
platform: event
action:
- service: input_boolean.toggle
entity_id: input_boolean.mbr_fan_light
- alias: "Master bedroom Fan Light On"
trigger:
platform: state
entity_id: input_boolean.mbr_fan_light
from: "off"
to: "on"
action:
- service: rest_command.mbr_fan_light_toggle
- alias: "Master bedroom Fan Light Off"
trigger:
platform: state
entity_id: input_boolean.mbr_fan_light
from: "on"
to: "off"
action:
- service: rest_command.mbr_fan_light_toggle
The “Master Bedroom Fan Boolean Toggle” is a xioami aqara switch that I use as a physical light button so I can have home assistant remember the state if pressed and toggle the light. The “Living Room Fan Light Adjust” will turn the light back on if I power of the fan if it is on. If not it calls a script that just waits 1 second and does nothing. I also have automations to adjust fans when I leave and come home and when I got to sleep as well as just being able to control them from home assistant on my phone or computer.
This was a fun learning project for me and I hope it helps someone else with home assistant.
Edit: I would have just changed the number in the rest commands in home assistant for the various speeds but the YAML code didn’t seem to like that in home assistant so I did individual commands.