Scripts / Templates to get a Dyson AM06 working via Home Assistant (and HomeKit Bridge)

Hi all, I spent the last few hours getting my Dyson AM06 working via a Broadlink RM4 Pro

I thought I’d share my scripts below, as I didn’t have much luck when searching for existing integrations

So long as you don’t use the remote, this should provide full HA functionality - the timer function isn’t implemented.

script:
  dyson_set_speed:
    alias: "Dyson Fan - Set Speed"
    icon: "mdi:fan"
    description: "Sets a Dyson fan to a given speed"
    variables:
      fan: dyson_am06
      percentage: 0
      percentage_step: 10
    mode: single
    sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: "{{ percentage > 0 }}"
          sequence:
          - choose:
            - conditions:
              - condition: template
                value_template: "{{ (states('input_number.' + fan + '_percentage') | int) < percentage }}"
              sequence:
              - service: remote.send_command
                target:
                  entity_id: remote.rm4_pro
                data:
                  device: "{{ fan }}"
                  command: "fan_up"
                  num_repeats: "{{ ((percentage - (states('input_number.' + fan + '_percentage') | int)) / percentage_step) | round(0, 'floor') | int }}"
                  delay_secs: 0.2
            default:
            - service: remote.send_command
              target:
                entity_id: remote.rm4_pro
              data:
                device: "{{ fan }}"
                command: "fan_down"
                num_repeats: "{{ (((states('input_number.' + fan + '_percentage') | int) - percentage) / percentage_step) | round(0, 'floor') | int }}"
                delay_secs: 0.2
          - service: input_number.set_value
            target:
              entity_id: "input_number.{{fan}}_percentage"
            data:
              value: "{{ percentage }}"
          - service: input_boolean.turn_on
            target:
              entity_id: "input_boolean.{{fan}}_state"
        default:
        - service: script.dyson_turn_off
          data:
            fan: "{{ fan }}"
  dyson_turn_off:
    alias: "Dyson Fan - Turn Off"
    icon: "mdi:fan-off"
    description: "Turns a Dyson fan off"
    variables:
      fan: dyson_am06
    mode: single
    sequence:
    - choose:
      - conditions:
        - condition: template
          value_template: "{{ states('input_boolean.' + fan + '_state') == 'on' }}"
        sequence:
          - service: remote.send_command
            target:
              entity_id: remote.rm4_pro
            data:
              device: "{{ fan }}"
              command: "power_off"
    - service: input_boolean.turn_off
      target:
        entity_id: "input_boolean.{{fan}}_state"
    - service: input_boolean.turn_off
      target:
        entity_id: "input_boolean.{{fan}}_oscillating"
  dyson_turn_on:
    alias: "Dyson Fan - Turn On"
    icon: "mdi:fan"
    description: "Turns a Dyson fan on"
    variables:
      fan: dyson_am06
    mode: single
    sequence:
    - choose:
      - conditions:
        - condition: template
          value_template: "{{ states('input_boolean.' + fan + '_state') == 'off' }}"
        sequence:
          - service: remote.send_command
            target:
              entity_id: remote.rm4_pro
            data:
              device: "{{ fan }}"
              command: "power_on"
    - service: input_boolean.turn_on
      target:
        entity_id: "input_boolean.{{fan}}_state"
  dyson_set_oscillating:
    alias: "Dyson Fan - Set Oscillating"
    icon: "mdi:arrow-oscillating"
    description: "Sets the osciallating status of a Dyson fan"
    variables:
      fan: dyson_am06
      oscillating: false
    mode: single
    sequence:
    - service: input_boolean.toggle
      target:
        entity_id: "input_boolean.{{fan}}_oscillating"
    - service: input_boolean.turn_on
      target:
        entity_id: "input_boolean.{{fan}}_state"
    - choose:
      - conditions:
        - condition: template
          value_template: "{{ (states('input_boolean.' + fan + '_oscillating') == 'on') == oscillating }}"
        sequence:
          - service: remote.send_command
            target:
              entity_id: remote.rm4_pro
            data:
              device: "{{ fan }}"
              command: "oscillate"

input_number:
  dyson_am06_percentage:
    name: Dyson AM06 Fan Speed
    initial: 0
    min: 0
    max: 100
    step: 10
    unit_of_measurement: "%"
    icon: "mdi:fan"

input_boolean:
  dyson_am06_oscillating:
    name: Dyson AM06 Oscillating
    initial: "false"
    icon: "mdi:arrow-oscillating"
  dyson_am06_state:
    name: Dyson AM06 State
    initial: "off"
    icon: "mdi:fan"

fan:
  - platform: template
    fans:
      dyson_am06:
        unique_id: dyson_am06
        friendly_name: "Dyson AM06"
        value_template: "{{ (((states('input_boolean.dyson_am06_state') == 'on') | int) * (states('input_number.dyson_am06_percentage') | default(0) | int)) > 0 }}"
        percentage_template: "{{ states('input_number.dyson_am06_percentage') | default(0) | int }}"
        oscillating_template: "{{ states('input_boolean.dyson_am06_oscillating') == 'on' }}"
        turn_on:
          service: script.dyson_turn_on
          data:
            fan: dyson_am06
        turn_off:
          service: script.dyson_turn_off
          data:
            fan: dyson_am06
        set_percentage:
          service: script.dyson_set_speed
          data:
            fan: dyson_am06
            percentage: "{{ percentage }}"
        set_oscillating:
          service: script.dyson_set_oscillating
          data:
            fan: dyson_am06
            oscillating: "{{ oscillating }}"
        speed_count: 10
1 Like