Skip to content

A python script for Home Assistant that control fan speed with Fan Template and Broadlink.

License

Notifications You must be signed in to change notification settings

iml885203/HA-FanSpeedControl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HA-FanSpeedControl

hacs_badge Donate

A python script for Home Assistant that control fan speed with Fan Template and Broadlink.

Document

How it work

The script automatically call broadlink service when you set fan speed.

Example

if your fan speed range is 1~12.

example1: call increase fan 4 times when you set fan speed from 1 to 5.

example2: call decrease fan 3 times when you set fan speed from 5 to 2.

example3: call decrease fan 2 times when you set fan speed from 2 to 12.

Installation

enable python_script for your HomeAssistant.

  • Add to configuration.yaml: python_script:
  • Create folder <config>/python_scripts
  • restart HomeAssistant

Find Fan Speed Control on HACS automation category.

Or you can copy the Python script in to your <config>/python_scripts directory.

Script arguments

key required type description
fan_speed true string speed from fan template
fan_speed_entity_id true string
fan_entity_id true string
fan_speed_count true integer
service_domain true string
service true string
service_data_increase true object
service_data_decrease true object

Config Example

set_percentage on template fan

set_percentage:
  - service: python_script.fan_speed_control
    data_template:
      fan_speed: "{{ percentage }}"
      fan_speed_entity_id: 'input_number.status_fan_speed'
      fan_entity_id: 'fan.bedroom_fan'
      fan_speed_count: 12
      service_domain: 'remote'
      service: 'send_command'
      service_data_increase:
        entity_id: remote.broadlink
        device: fan
        command: increase
      service_data_decrease:
        entity_id: remote.broadlink
        device: fan
        command: decrease

Template Fan config

input_boolean:
  status_fan_power:
    name: 'Fan Power'

input_number:
  status_fan_speed:
    name: 'Fan Speed'
    min: 0
    max: 100

input_select:
  fan_osc:
    name: 'Fan osc'
    options:
      - 'True'
      - 'False'
fan:
  - platform: template
    fans:
      bedroom_fan:
        friendly_name: "myFan"
        speed_count: 12
        value_template: "{{ states('input_boolean.status_fan_power') }}"
        percentage_template: "{{ states('input_number.status_fan_speed') | int }}"
        oscillating_template: "{{ states('input_select.fan_osc') }}"
        turn_on:
          - condition: state
            entity_id: input_boolean.status_fan_power
            state: 'off'
          - service: remote.send_command
            data:
              entity_id: remote.broadlink
              device: fan
              command: toggle
          - service: input_boolean.turn_on
            entity_id: input_boolean.status_fan_power
        turn_off:
          - condition: state
            entity_id: input_boolean.status_fan_power
            state: 'on'
          - service: remote.send_command
            data:
              entity_id: remote.broadlink
              device: fan
              command: toggle
          - service: input_boolean.turn_off
            entity_id: input_boolean.status_fan_power
        set_percentage:
          - service: python_script.fan_speed_control
            data_template:
              fan_speed: "{{ percentage }}"
              fan_speed_entity_id: 'input_number.status_fan_speed'
              fan_entity_id: 'fan.bedroom_fan'
              fan_speed_count: 12
              service_domain: 'remote'
              service: 'send_command'
              service_data_increase:
                entity_id: remote.broadlink
                device: fan
                command: increase
              service_data_decrease:
                entity_id: remote.broadlink
                device: fan
                command: decrease
        set_oscillating:
          - condition: state
            entity_id: input_boolean.status_fan_power
            state: 'on'
          - service: remote.send_command
            data:
              entity_id: remote.broadlink
              device: fan
              command: oscillate
          - service: input_select.select_next
            entity_id: input_select.fan_osc

Debug

add logger to your configuration.yaml

logger:
  default: warn
  logs:
    homeassistant.components.python_script.fan_speed_control.py: debug

Screenshot

image

Custom ui

image

Todos

  • Refactor arguments, like: remove not used argument service
  • Find some way to get entity.state and fan speed not by arguments




About

A python script for Home Assistant that control fan speed with Fan Template and Broadlink.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages