mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-17 14:26:51 +00:00
Allow setting set_percentage and set_preset_mode of template fan without turning on (#23822)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
fa32b9f54f
commit
a5854a0e71
@ -13,6 +13,8 @@ The `template` platform creates fans that combine integrations and provides the
|
|||||||
ability to run scripts or invoke services for each of the `turn_on`, `turn_off`, `set_percentage`,
|
ability to run scripts or invoke services for each of the `turn_on`, `turn_off`, `set_percentage`,
|
||||||
`set_preset_mode`, `set_oscillating`, and `set_direction` commands of a fan.
|
`set_preset_mode`, `set_oscillating`, and `set_direction` commands of a fan.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
To enable Template Fans in your installation, add the following to your
|
To enable Template Fans in your installation, add the following to your
|
||||||
`configuration.yaml` file:
|
`configuration.yaml` file:
|
||||||
|
|
||||||
@ -146,3 +148,110 @@ When converting a fan with 3 speeds from the old fan entity model, the following
|
|||||||
33 - `low`
|
33 - `low`
|
||||||
66 - `medium`
|
66 - `medium`
|
||||||
100 - `high`
|
100 - `high`
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Helper Fan
|
||||||
|
|
||||||
|
This example uses an input_boolean and an input_number to mimic a fan, and
|
||||||
|
the example shows multiple service calls for set_percentage.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
fan:
|
||||||
|
- platform: template
|
||||||
|
fans:
|
||||||
|
helper_fan:
|
||||||
|
friendly_name: "Helper Fan"
|
||||||
|
value_template: "{{ states('input_boolean.state') }}"
|
||||||
|
turn_on:
|
||||||
|
- service: input_boolean.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: input_boolean.state
|
||||||
|
turn_off:
|
||||||
|
- service: input_boolean.turn_off
|
||||||
|
target:
|
||||||
|
entity_id: input_boolean.state
|
||||||
|
percentage_template: >
|
||||||
|
{{ states('input_number.percentage') if is_state('input_boolean.state', 'on') else 0 }}
|
||||||
|
speed_count: 6
|
||||||
|
set_percentage:
|
||||||
|
- service: input_boolean.turn_{{ 'on' if percentage > 0 else 'off' }}
|
||||||
|
target:
|
||||||
|
entity_id: input_boolean.state
|
||||||
|
- service: input_number.set_value
|
||||||
|
target:
|
||||||
|
entity_id: input_number.percentage
|
||||||
|
data:
|
||||||
|
value: "{{ percentage }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
|
### Preset Modes Fan
|
||||||
|
|
||||||
|
This example uses an existing fan with only a percentage. It extends the
|
||||||
|
percentage value into useable preset modes without a helper entity.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
fan:
|
||||||
|
- platform: template
|
||||||
|
fans:
|
||||||
|
preset_mode_fan:
|
||||||
|
friendly_name: "Preset Mode Fan Example"
|
||||||
|
value_template: "{{ states('fan.percentage_fan') }}"
|
||||||
|
turn_on:
|
||||||
|
- service: fan.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: fan.percentage_fan
|
||||||
|
turn_off:
|
||||||
|
- service: fan.turn_off
|
||||||
|
target:
|
||||||
|
entity_id: fan.percentage_fan
|
||||||
|
percentage_template: >
|
||||||
|
{{ state_attr('fan.percentage_fan', 'percentage') }}
|
||||||
|
speed_count: 3
|
||||||
|
set_percentage:
|
||||||
|
- service: fan.set_percentage
|
||||||
|
target:
|
||||||
|
entity_id: fan.percentage_fan
|
||||||
|
data:
|
||||||
|
percentage: "{{ percentage }}"
|
||||||
|
preset_modes:
|
||||||
|
- "off"
|
||||||
|
- "low"
|
||||||
|
- "medium"
|
||||||
|
- "high"
|
||||||
|
preset_mode_template: >
|
||||||
|
{% if is_state('fan.percentage_fan', 'on') %}
|
||||||
|
{% if state_attr('fan.percentage_fan', 'percentage') == 100 %}
|
||||||
|
high
|
||||||
|
{% elif state_attr('fan.percentage_fan', 'percentage') == 66 %}
|
||||||
|
medium
|
||||||
|
{% else %}
|
||||||
|
low
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
off
|
||||||
|
{% endif %}
|
||||||
|
set_preset_mode:
|
||||||
|
- service: fan.set_percentage
|
||||||
|
target:
|
||||||
|
entity_id: fan.percentage_fan
|
||||||
|
data:
|
||||||
|
percentage: >-
|
||||||
|
{% if preset_mode == 'high' %}
|
||||||
|
100
|
||||||
|
{% elif preset_mode == 'medium' %}
|
||||||
|
66
|
||||||
|
{% elif preset_mode == 'low' %}
|
||||||
|
33
|
||||||
|
{% else %}
|
||||||
|
0
|
||||||
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user