Last active
December 31, 2024 05:18
-
-
Save peter-dolkens/a6244cfd6fec3f7f26772d51de78d427 to your computer and use it in GitHub Desktop.
Some examples of the fan scripts I've configured for myself and for my parents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# placed at packages/fans.yaml and then included from configuration.yaml with the following lines | |
# | |
# | |
# homeassistant: | |
# packages: !include_dir_named packages | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# placed at packages/fans.yaml and then included from configuration.yaml with the following lines | |
# | |
# | |
# homeassistant: | |
# packages: !include_dir_named packages | |
script: | |
fan_set_speed: | |
alias: "Fan - Set Speed" | |
icon: "mdi:fan" | |
description: "Sets a fan to a given speed" | |
variables: | |
room: room | |
percentage: 0 | |
mode: restart | |
sequence: | |
- service: remote.send_command | |
target: | |
entity_id: remote.rm4_pro | |
data: | |
device: "{{ room }}" | |
command: > | |
{% set percentage_step = state_attr('fan.front_bedroom_fan', 'percentage_step') %} | |
{% set speed_level = ((percentage + 2) / percentage_step) | round(0, 'floor') %} | |
fan_{{ speed_level }} | |
- service: input_number.set_value | |
target: | |
entity_id: "input_number.{{room}}_fan_percentage" | |
data: | |
value: "{{ percentage }}" | |
input_number: | |
front_bedroom_fan_percentage: | |
name: Front Bedroom Fan Speed | |
initial: 17 | |
min: 0 | |
max: 102 | |
step: 17 | |
office_fan_percentage: | |
name: Office Fan Speed | |
initial: 17 | |
min: 0 | |
max: 102 | |
step: 17 | |
input_select: | |
front_bedroom_fan_direction: | |
name: Bedroom Fan Direction | |
icon: mdi:swap-horizontal | |
options: | |
- backward | |
- forward | |
initial: forward | |
office_fan_direction: | |
name: Office Fan Direction | |
icon: mdi:swap-horizontal | |
options: | |
- backward | |
- forward | |
initial: forward | |
light: | |
- platform: template | |
lights: | |
front_bedroom_light: | |
unique_id: front_bedroom_light | |
friendly_name: "Front Bedroom Light" | |
turn_on: | |
service: remote.send_command | |
target: | |
entity_id: remote.rm4_pro | |
data: | |
device: front_bedroom | |
command: light_toggle | |
turn_off: | |
service: remote.send_command | |
target: | |
entity_id: remote.rm4_pro | |
data: | |
device: front_bedroom | |
command: light_toggle | |
office_light: | |
unique_id: office_light | |
friendly_name: "Office Light" | |
turn_on: | |
service: remote.send_command | |
target: | |
entity_id: remote.rm4_pro | |
data: | |
device: office | |
command: light | |
turn_off: | |
service: remote.send_command | |
target: | |
entity_id: remote.rm4_pro | |
data: | |
device: office | |
command: light | |
fan: | |
- platform: template | |
fans: | |
front_bedroom_fan: | |
unique_id: front_bedroom_fan | |
friendly_name: "Front Bedroom Fan" | |
value_template: "{{ states('input_number.front_bedroom_fan_percentage') | default(0) | int > 0 }}" | |
percentage_template: "{{ states('input_number.front_bedroom_fan_percentage') | default(0) }}" | |
direction_template: "{{ states('input_select.front_bedroom_fan_direction') | default('forward') }}" | |
turn_on: | |
service: script.fan_set_speed | |
data: | |
room: front_bedroom | |
percentage: 20 | |
turn_off: | |
service: script.fan_set_speed | |
data: | |
room: front_bedroom | |
percentage: 0 | |
set_percentage: | |
service: script.fan_set_speed | |
data: | |
room: front_bedroom | |
percentage: "{{ percentage }}" | |
set_direction: | |
service: script.fan_direction | |
data: | |
room: front_bedroom | |
direction: "{{ direction }}" | |
speed_count: 6 | |
office_fan: | |
unique_id: office_fan | |
friendly_name: "Office Fan" | |
value_template: "{{ states('input_number.office_fan_percentage') | default(0) | int > 0 }}" | |
percentage_template: "{{ states('input_number.office_fan_percentage') | default(0) }}" | |
direction_template: "{{ states('input_select.office_fan_direction') | default('forward') }}" | |
turn_on: | |
service: script.fan_set_speed | |
data: | |
room: office | |
percentage: 20 | |
turn_off: | |
service: script.fan_set_speed | |
data: | |
room: office | |
percentage: 0 | |
set_percentage: | |
service: script.fan_set_speed | |
data: | |
room: office | |
percentage: "{{ percentage }}" | |
set_direction: | |
service: script.fan_direction | |
data: | |
room: office | |
direction: "{{ direction }}" | |
speed_count: 6 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment