借用前面的一个帖子,如何学会编写下面这种代码,学习哪个工具或语言。
我的主要需求是想写个带一个按键、一个灯的智能插座固件,基于esp12s芯片,实现按键正常、灯光正常,能接入ha,能实现开关按钮,定时按钮。
网上有不少,感觉有些不合需求,还有的是阿杜诺写的,这觉得这种比较简单。麻烦高手告知一下。
substitutions:
device_name: ac-dimmer-01 #设备名称
friendly_name: ac_dimmer_01
led_state_pin: GPIO2 #绿色指示灯引脚
u0txd_pin: GPIO1 #刷机用串口
U0Rxd_pin: GPIO3
esphome:
name: $device_name
comment: 交流调光/调速器。esp-12F模块、DS18B20温度传感器。 #有关此节点的注释文本信息。仅用于在 UI 中显示。
# name_add_mac_suffix: true #设备名字后面添加MAC地址
esp8266:
board: esp01_1m
restore_from_flash: true
preferences:
flash_write_interval: 5min #自定义数据刷新到闪存的频率
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption: #启用API层的传输加密
key: !secret api_key #用于加密的预共享密钥
reboot_timeout: 0s #与客户端(如HA)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
ota:
password: "e52d77214d5c74f9a9b3d44ee2fc678a"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true #快速连接,如果SSID是隐藏的,必须设置为true
reboot_timeout: 0s #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
status_led: #状态指示灯
pin:
number: $led_state_pin
# inverted: true #反转输出状态
captive_portal:
dallas:
- pin: GPIO14
update_interval: 60s
#i2c:
# - id: bh1750_i2c
# sda: $u0txd_pin
# scl: $U0Rxd_pin
# scan: true #启动时搜索I²C地址空间
output:
- platform: ac_dimmer
id: dimmer1
gate_pin: GPIO13 #用于控制可控硅的引脚。
# inverted: true
method: leading pulse
zero_cross_pin: #用于感测交流过零事件的引脚
number: GPIO12
mode:
input: true
# inverted: true
light:
- platform: monochromatic
output: dimmer1
name: "${friendly_name}_Light"
id: "${friendly_name}_Light"
restore_mode: RESTORE_DEFAULT_ON #
on_turn_on:
then:
- light.turn_on:
id: "${friendly_name}_Light"
brightness: 10% #默认亮度
switch:
- platform: restart #重启开关
name: "${friendly_name}_Restart"
icon: mdi:car-esp #自定义图标
- platform: safe_mode
name: "${friendly_name}_SafeMode"
- platform: factory_reset #恢复出厂设置
name: ${friendly_name}_factory
sensor:
- platform: uptime
id: ${friendly_name}_raw_up_time
update_interval: 15min
internal: true
on_raw_value:
then:
- text_sensor.template.publish:
id: ${friendly_name}_uptime_human
state: !lambda |-
int seconds = round(id(${friendly_name}_raw_up_time).raw_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 (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
- platform: wifi_signal #WiFi信号强度
name: "${friendly_name}_WiFi_Signal"
icon: mdi:signal #自定义图标
update_interval: 60s
- platform: dallas
address: 0x6d00000032bb9628
name: "${friendly_name}_Temperature"
# - platform: bh1750
# name: "${friendly_name}_Illuminance"
# i2c_id: bh1750_i2c
# address: 0x23
# update_interval: 30s
- platform: template
name: "${friendly_name}_CpuFreq"
id: "${friendly_name}_CpuFreq"
icon: mdi:cpu-32-bit #自定义图标
lambda: |-
return ESP.getCpuFreqMHz();
unit_of_measurement: "MHz"
update_interval: 10s
- platform: template
name: "${friendly_name}_FreeMemory"
id: "${friendly_name}_FreeMemory"
icon: mdi:memory #自定义图标
lambda: |-
return ESP.getFreeHeap();
filters:
- multiply: 0.001
unit_of_measurement: "KB"
update_interval: 10s
text_sensor:
- platform: template
name: '${friendly_name}_Uptime'
id: ${friendly_name}_uptime_human
icon: mdi:clock-start #自定义图标
- platform: wifi_info
ip_address:
name: ${friendly_name}_IP #IP地址
icon: mdi:ip-network #自定义图标
ssid:
name: ${friendly_name}_SSID
icon: mdi:wifi #自定义图标
mac_address:
name: ${friendly_name}_mac
icon: "mdi:wifi-marker" #自定义图标
|