Last active
August 30, 2024 07:59
-
-
Save hectorzin/56c49a6e1e15cdfe6fbab85df35cf576 to your computer and use it in GitHub Desktop.
Crear interruptores virtuales para manejar bombillas y ventiladores inteligentes
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
light: | |
- platform: template | |
lights: | |
luz_virtual: | |
friendly_name: "Luz virtual" | |
value_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') and is_state('light.luz_ventilador', 'on') %} | |
on | |
{% else %} | |
off | |
{% endif %} | |
level_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') %} | |
{{ state_attr('light.luz_ventilador', 'brightness') | int if state_attr('light.luz_ventilador', 'brightness') is not none else 0 }} | |
{% else %} | |
0 | |
{% endif %} | |
temperature_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') %} | |
{{ state_attr('light.luz_ventilador', 'color_temp') | int if state_attr('light.luz_ventilador', 'color_temp') is not none else 0 }} | |
{% else %} | |
0 | |
{% endif %} | |
turn_on: | |
service: light.turn_on | |
data_template: | |
entity_id: | |
- switch.interruptor_fisico | |
- light.luz_ventilador | |
brightness: > | |
{{ brightness if brightness is defined else (state_attr('light.luz_ventilador', 'brightness') | int if state_attr('light.luz_ventilador', 'brightness') is not none else 255) }} | |
color_temp: > | |
{{ color_temp if color_temp is defined else (state_attr('light.luz_ventilador', 'color_temp') | int if state_attr('light.luz_ventilador', 'color_temp') is not none else 370) }} | |
turn_off: | |
service: homeassistant.turn_off | |
data_template: | |
entity_id: > | |
{% if is_state('fan.ventilador', 'off') %} | |
switch.interruptor_fisico, light.luz_ventilador | |
{% else %} | |
light.luz_ventilador | |
{% endif %} | |
set_level: | |
service: light.turn_on | |
data_template: | |
entity_id: light.luz_ventilador | |
brightness: "{{ brightness }}" | |
set_temperature: | |
service: light.turn_on | |
data_template: | |
entity_id: light.luz_ventilador | |
color_temp: "{{ color_temp }}" | |
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
fan: | |
- platform: template | |
fans: | |
ventilador_virtual: | |
friendly_name: "Ventilador virtual" | |
value_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') and is_state('fan.ventilador', 'on') %} | |
on | |
{% else %} | |
off | |
{% endif %} | |
percentage_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') %} | |
{{ state_attr('fan.ventilador', 'percentage') | int }} | |
{% else %} | |
0 | |
{% endif %} | |
preset_mode_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') %} | |
{{ state_attr('fan.ventilador', 'preset_mode') }} | |
{% else %} | |
none | |
{% endif %} | |
direction_template: > | |
{% if is_state('switch.interruptor_fisico', 'on') %} | |
{{ state_attr('fan.ventilador', 'direction') }} | |
{% else %} | |
none | |
{% endif %} | |
turn_on: | |
- variables: | |
luz_ventilador_original_state: "{{ states('switch.interruptor_fisico') }}" | |
- service: light.turn_on | |
target: | |
entity_id: switch.interruptor_fisico | |
data: {} | |
- repeat: | |
count: 20 | |
sequence: | |
- delay: "00:00:01" | |
- service: homeassistant.turn_on | |
data: | |
entity_id: | |
- fan.ventilador | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ is_state('fan.ventilador', 'on') }}" | |
sequence: | |
- delay: "00:00:01" | |
- condition: template | |
value_template: >- | |
{{ is_state('light.luz_ventilador', 'on') or | |
is_state('light.luz_ventilador', 'off') }} | |
- condition: template | |
value_template: "{{ luz_ventilador_original_state == 'off' }}" | |
- service: light.turn_off | |
target: | |
entity_id: light.luz_ventilador | |
data: {} | |
- stop: "" | |
turn_off: | |
service: homeassistant.turn_off | |
data: | |
entity_id: > | |
{% if is_state('light.luz_ventilador', 'off') %} | |
light.luz_ventilador, fan.ventilador | |
{% else %} | |
fan.ventilador | |
{% endif %} | |
set_percentage: | |
service: fan.set_percentage | |
data_template: | |
entity_id: fan.ventilador | |
percentage: "{{ percentage }}" | |
set_preset_mode: | |
service: fan.set_preset_mode | |
data_template: | |
entity_id: fan.ventilador | |
preset_mode: "{{ preset_mode }}" | |
set_direction: | |
service: fan.set_direction | |
data_template: | |
entity_id: fan.ventilador | |
direction: "{{ direction }}" | |
preset_modes: | |
- "fresh" | |
- "nature" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment