本帖最后由 bugensui 于 2023-12-30 22:34 编辑
ota完善更新固件
刚刚刷完基础固件后,先不要拔出usb适配器,可以先ota更新下固件代码(主要是功能模块,ha默认新建的esp代码是基础代码),当然接入底盒里,接好线后,通过wifi直接ota更新也是可以的,就是怕没有刷成功,在装上去之前更新比较保险。
打开ha——加载项——esphome——web ui,进去主页,找到刚刚的设备,点击EDIT,在captive_portal :后面追加如下代码(代码已附),另外ap的账号和密码自己可以修改,方便设备连接不上wifi时,启用ap连接重新选择连接上wifi。下面代码的含义主要是:开通ip网页直接控制设备(可以不用ha控制),esp主板的一些温度,ip,信号,然后控制灯和继电器这些。
web_server:
port: 80
sensor:
- platform: uptime
id: uptime_s
update_interval: 5s
- platform: internal_temperature
name: "sonoff-minir4_Temperature"
text_sensor:
- platform: version
name: version
- platform: wifi_info
ip_address:
name: "sonoff-minir4 ip"
icon: mdi:ip
ssid:
name: ssid
icon: mdi:wifi
- platform: template
name: "Uptime"
lambda: |-
int seconds = (id(uptime_s).state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
icon: mdi:clock-start
update_interval: 5s
status_led:
pin:
number: GPIO19
inverted: true
output:
# Physical relay on GPIO
- platform: gpio
pin: GPIO26
id: relay_1
light:
- platform: binary
id: light_1
name: "chufang_lamp"
icon: mdi:ceiling-light-multiple-outline
restore_mode: restore_default_off
output: relay_1
binary_sensor:
- platform: status
name: "sonoff-minir4 Status"
- platform: gpio
pin: GPIO00
id: button
filters:
- invert:
- delayed_off: 50ms
on_press:
- light.toggle:
id: light_1
- platform: gpio
name: s1
pin: GPIO27
id: s1
filters:
- invert:
- delayed_off: 50ms
on_press:
then:
- light.turn_on:
id: light_1
on_release:
then:
- light.turn_off:
id: light_1
复制代码
然后选择保存,再点右上角的INSTALL(安装更新固件),然后选择第一个在线更新固件。固件更新完会有提示,然后点击右下角的stop退出页面,再到ha的esphome集成里,找到该设备,看下功能有没有更新,如果正常更新了,就可以拔掉usb了,准备后续接线进86盒的工作了。