差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
| developmentboard:esphome_smart_light_bulb [2024/11/30 02:10] – admin | developmentboard:esphome_smart_light_bulb [2024/12/18 14:41] (当前版本) – admin | ||
|---|---|---|---|
| 行 30: | 行 30: | ||
| **Yaml File:** | **Yaml File:** | ||
| + | |||
| + | substitutions: | ||
| + | |||
| + | name: " | ||
| + | |||
| + | friendly_name: | ||
| + | |||
| + | project_name: | ||
| + | |||
| + | project_version: | ||
| + | |||
| + | light_restore_mode: | ||
| + | |||
| + | color_interlock: | ||
| + | |||
| + | esphome: | ||
| + | |||
| + | name: " | ||
| + | |||
| + | name_add_mac_suffix: | ||
| + | |||
| + | project: | ||
| + | |||
| + | name: " | ||
| + | |||
| + | version: " | ||
| + | |||
| + | preferences: | ||
| + | |||
| + | flash_write_interval: | ||
| + | |||
| + | esp8266: | ||
| + | |||
| + | board: esp8285 | ||
| + | |||
| + | restore_from_flash: | ||
| + | |||
| + | globals: | ||
| + | |||
| + | - id: my_global_mode | ||
| + | |||
| + | type: bool | ||
| + | |||
| + | restore_value: | ||
| + | |||
| + | initial_value: | ||
| + | |||
| + | logger: | ||
| + | |||
| + | api: | ||
| + | |||
| + | ota: | ||
| + | |||
| + | safe_mode: false | ||
| + | |||
| + | wifi: | ||
| + | |||
| + | ap: {} | ||
| + | |||
| + | interval: | ||
| + | |||
| + | - interval: 1s | ||
| + | |||
| + | then: | ||
| + | |||
| + | - lambda: |- | ||
| + | |||
| + | static uint32_t cnt = 0; | ||
| + | |||
| + | static int flag = 0; | ||
| + | |||
| + | static ESPPreferenceObject pref = global_preferences→make_preference(23332500UL, | ||
| + | |||
| + | if((flag == 1) && (network:: | ||
| + | |||
| + | { | ||
| + | |||
| + | flag = 0; | ||
| + | |||
| + | ESP.restart(); | ||
| + | |||
| + | } | ||
| + | |||
| + | if(cnt == 0){ | ||
| + | |||
| + | cnt++; | ||
| + | |||
| + | uint32_t val = 0; | ||
| + | |||
| + | pref.load(& | ||
| + | |||
| + | val+=1; | ||
| + | |||
| + | pref.save(& | ||
| + | |||
| + | global_preferences→sync(); | ||
| + | |||
| + | if(val >= 3){ | ||
| + | |||
| + | my_global_mode→value() = false; | ||
| + | |||
| + | } | ||
| + | |||
| + | }else if(cnt < 5){ | ||
| + | |||
| + | cnt++; | ||
| + | |||
| + | if(cnt == 5){ | ||
| + | |||
| + | uint32_t val = 0; | ||
| + | |||
| + | pref.save(& | ||
| + | |||
| + | global_preferences→sync(); | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | if(!my_global_mode→value()){ | ||
| + | |||
| + | if(cnt == 1){ | ||
| + | |||
| + | char a[] = " | ||
| + | |||
| + | char b[] = " | ||
| + | |||
| + | wifi_wificomponent→clear_sta(); | ||
| + | |||
| + | wifi_wificomponent→save_wifi_sta(a, | ||
| + | |||
| + | wifi:: | ||
| + | |||
| + | wifi_wificomponent→set_ap(wifi_wifiap); | ||
| + | |||
| + | wifi_wificomponent→set_ap_timeout(5000); | ||
| + | |||
| + | flag = 1; | ||
| + | |||
| + | rgbww_rgbwwlightoutput→set_color_interlock(false); | ||
| + | |||
| + | } | ||
| + | |||
| + | static int state = 0; | ||
| + | |||
| + | auto call = id(my_light).turn_on(); | ||
| + | |||
| + | call.set_transition_length(1000); | ||
| + | |||
| + | call.set_brightness(1.0); | ||
| + | |||
| + | if (state == 0) { | ||
| + | |||
| + | call.set_rgb(1.0, | ||
| + | |||
| + | call.set_cold_white(0.0); | ||
| + | |||
| + | call.set_warm_white(0.0); | ||
| + | |||
| + | } else if (state == 3) { | ||
| + | |||
| + | call.set_rgb(0.0, | ||
| + | |||
| + | } else if (state == 5) { | ||
| + | |||
| + | call.set_rgb(0.0, | ||
| + | |||
| + | } else if (state == 7) { | ||
| + | |||
| + | call.set_color_brightness(0.0); | ||
| + | |||
| + | call.set_cold_white(1.0); | ||
| + | |||
| + | call.set_warm_white(0.0); | ||
| + | |||
| + | } else if (state == 9) { | ||
| + | |||
| + | call.set_cold_white(0.0); | ||
| + | |||
| + | call.set_warm_white(1.0); | ||
| + | |||
| + | } else if (state == 11) { | ||
| + | |||
| + | call.set_color_brightness(1.0); | ||
| + | |||
| + | call.set_rgb(0.0, | ||
| + | |||
| + | call.set_cold_white(0.0); | ||
| + | |||
| + | call.set_warm_white(0.0); | ||
| + | |||
| + | } | ||
| + | |||
| + | call.perform(); | ||
| + | |||
| + | state += 1; | ||
| + | |||
| + | if (state == 12) | ||
| + | |||
| + | { | ||
| + | |||
| + | my_global_mode→value() = true; | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | web_server: | ||
| + | |||
| + | port: 80 | ||
| + | |||
| + | captive_portal: | ||
| + | |||
| + | binary_sensor: | ||
| + | |||
| + | - platform: status | ||
| + | |||
| + | name: " | ||
| + | |||
| + | sensor: | ||
| + | |||
| + | - platform: uptime | ||
| + | |||
| + | update_interval: | ||
| + | |||
| + | name: " | ||
| + | |||
| + | button: | ||
| + | |||
| + | - platform: restart | ||
| + | |||
| + | name: " | ||
| + | |||
| + | output: | ||
| + | |||
| + | - platform: esp8266_pwm | ||
| + | |||
| + | id: red_output | ||
| + | |||
| + | pin: GPIO12 | ||
| + | |||
| + | - platform: esp8266_pwm | ||
| + | |||
| + | id: green_output | ||
| + | |||
| + | pin: GPIO14 | ||
| + | |||
| + | - platform: esp8266_pwm | ||
| + | |||
| + | id: blue_output | ||
| + | |||
| + | pin: GPIO5 | ||
| + | |||
| + | - platform: esp8266_pwm | ||
| + | |||
| + | id: cold_white_output | ||
| + | |||
| + | pin: GPIO4 | ||
| + | |||
| + | - platform: esp8266_pwm | ||
| + | |||
| + | id: warm_white_output | ||
| + | |||
| + | pin: GPIO13 | ||
| + | |||
| + | light: | ||
| + | |||
| + | - platform: rgbww | ||
| + | |||
| + | name: " | ||
| + | |||
| + | restore_mode: | ||
| + | |||
| + | red: red_output | ||
| + | |||
| + | green: green_output | ||
| + | |||
| + | blue: blue_output | ||
| + | |||
| + | cold_white: cold_white_output | ||
| + | |||
| + | warm_white: warm_white_output | ||
| + | |||
| + | cold_white_color_temperature: | ||
| + | |||
| + | warm_white_color_temperature: | ||
| + | |||
| + | color_interlock: | ||
| + | |||
| + | id: my_light | ||
| + | |||
| + | text_sensor: | ||
| + | |||
| + | - platform: wifi_info | ||
| + | |||
| + | ip_address: | ||
| + | |||
| + | name: " | ||
| + | |||
| + | disabled_by_default: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ---- | ||