output:
- platform: esp8266_pwm
pin: GPIO2 #D4
frequency: 15000 Hz
id: pwm_output
fan:
- platform: speed
id: fan_speed
output: pwm_output
speed_count: 100
name: "${device_name} 开关"
number:
- platform: template
icon: "mdi:fan"
id: speed_input
name: "${device_name} 风速"
lambda: |-
return id(fan_speed).speed;
step: 1
min_value: 30
max_value: 100
unit_of_measurement: "%"
update_interval: 1s
set_action:
then:
- fan.turn_on:
id: fan_speed
speed: !lambda "return x;"
- component.update: fanmode
- component.update: sensor_fanspeed
select:
- platform: template
icon: "mdi:fan"
name: "${device_name} 模式"
id: fanmode
update_interval: 1s
lambda: |-
if(id(fan_speed).speed <= ${speed_low})
return std::string("Low");
else if(id(fan_speed).speed == ${speed_med})
return std::string("Medium");
else if(id(fan_speed).speed >= ${speed_full})
return std::string("Full");
else
return std::string("Custom");
set_action:
then:
- lambda: |-
auto call = id(fan_speed).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(speed_input).state);
call.perform();
- component.update: speed_input
- component.update: sensor_fanspeed
options:
- Low
- Medium
- Full
- Custom
button:
- platform: template
icon: "mdi:fan-speed-1"
name: "${device_name} Low"
id: fanlow
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_low}"
- platform: template
icon: "mdi:fan-speed-2"
name: "${device_name} Med"
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_med}"
- platform: template
icon: "mdi:fan-speed-3"
name: "${device_name} Full"
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_full}"
- platform: restart
name: "${device_name} 初始化"
sensor:
- platform: template
id: sensor_fanspeed
icon: "mdi:fan"
name: "风扇速度"
lambda: |-
return id(fan_speed).speed;
update_interval: 1s
accuracy_decimals: 0
unit_of_measurement: "%"
- platform: dht
pin: GPIO4 #D2
temperature:
name: "${device_name} Temperature"
humidity:
name: "${device_name} Humidity"
model: AUTO_DETECT
update_interval: 5s #获取频率
可以显示挡位 |