下面的示例是实现将继电器状态、全局变量保存到存储器,断电也不会丢失。
esphome:
name: "xxxxx"
esp8266:
board: esp01_1m
restore_from_flash: true #开启保存数据到flash的功能
preferences:
flash_write_interval: 10s #每10秒保存写一次数据到flash
switch:
- platform: gpio
pin: GPIO5
name: "Relay"
id: relay1
restore_mode: RESTORE_DEFAULT_OFF #重启后从flash读取数据恢复继电器状态,如果无法恢复,就设置为关闭状态
globals:
- id: my_global_update_count
type: int
restore_value: true #重启后从flash读取全局变量的值
initial_value: '0'
|