fan:
- platform: speed
id: "${friendly_name}_fan"
output: pwm_output
speed_count: 100
name: "${device_name} 开关"
output:
- platform: esp8266_pwm
pin: GPIO0
frequency: 15000 Hz
id: pwm_output
number:
- platform: template
icon: "mdi:fan"
id: ${friendly_name}_speed_input
name: "${device_name} 风速"
lambda: |-
return id(${friendly_name}_fan).speed;
step: 1
min_value: 1
max_value: 100
unit_of_measurement: "%"
update_interval: 1s
set_action:
then:
- fan.turn_on:
id: ${friendly_name}_fan
speed: !lambda "return x;"
- component.update: ${friendly_name}_fanmode
- component.update: ${friendly_name}_sensor_fanspeed
select:
- platform: template
icon: "mdi:fan"
name: "${device_name} 模式"
id: ${friendly_name}_fanmode
update_interval: 1s
lambda: |-
if(id(${friendly_name}_fan).speed <= ${speed_low})
return std::string("Low");
else if(id(${friendly_name}_fan).speed == ${speed_med})
return std::string("Medium");
else if(id(${friendly_name}_fan).speed >= ${speed_full})
return std::string("Full");
else
return std::string("Custom");
set_action:
then:
- lambda: |-
auto call = id(${friendly_name}_fan).turn_on();
if(x == "Low")
call.set_speed(${speed_low});
else if(x == "Medium")
call.set_speed(${speed_med});
else if(x == "Full")
call.set_speed(${speed_full});
else
call.set_speed(id(${friendly_name}_speed_input).state);
call.perform();
- component.update: ${friendly_name}_speed_input
- component.update: ${friendly_name}_sensor_fanspeed
options:
- Low
- Medium
- Full
- Custom
button:
- platform: template
icon: "mdi:fan-speed-1"
name: "${device_name} Low"
on_press:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_low}"
- platform: template
icon: "mdi:fan-speed-2"
name: "${device_name} Med"
on_press:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_med}"
- platform: template
icon: "mdi:fan-speed-3"
name: "${device_name} Full"
on_press:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_full}"
- platform: restart
name: "${device_name} 初始化"
sensor:
- platform: template
id: ${friendly_name}_sensor_fanspeed
icon: "mdi:fan"
name: "风扇速度"
lambda: |-
return id(${friendly_name}_fan).speed;
update_interval: 1s
accuracy_decimals: 0
unit_of_measurement: "%"
- platform: dht
model: DHT11
pin: GPIO2
temperature:
on_value_range:
- below: 25.0
then:
- fan.turn_off: ${friendly_name}_fan
- above: 25.0
below: 30.0
then:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_low}"
- above: 30.0
below: 35.0
then:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_med}"
- above: 35.0
then:
- fan.turn_on:
id: ${friendly_name}_fan
speed: "${speed_full}"
name: "${friendly_name}_temp"
humidity:
name: "${friendly_name}_Humidity"
update_interval: 10s
|