1-common-esp8266-2m
#FRIENDLY NAMING
#Entity name is a combination of the [friendly name and component name]
#Entity ID is derived from the [entity name with the device name prepended]
#Example:
#
#esphome:
# name: "livingroomdesk"
# friendly_name: "Living room desk"
#
#sensor:
# name: "Temperature"
#
#The entity will be named Living room desk Temperature and will default to having an entity ID of sensor.livingroomdesk_temperature.
#
#LEGACY NAMING
#Entity name is the component name
#Device name is not prepended to the entity name
#Entity ID is derived solely from the entity name
#Example:
#
#esphome:
# name: "livingroomdesk"
#
#sensor:
# name: "Temperature"
#
#The entity will be named Temperature and will default to having an entity_id of sensor.temperature.
#注释:使用esphome:friendly_name节点之后,在homeassistant中对esphome的name和id重新定义:
# 1. Entity name的格式为[friendly_name] + ' ' + [各个组件的name]
# 2. Entity id的格式为[esphome的name] + '_' + [各个组件的name]
# 3. Device name的格式[friendly_name] + ' ' + [mac地址后6位]
# 3. esphome的name名称中不能有'_'。
# 举例:
#如果yaml中如下配置:
# node_name: plug-lenovo
# node_name_friendly: "Lenovo.SHD-SPL0-001"
# esp设备的mac地址: 807d3a74dba8
# name_add_mac_suffix: true ---node_name后面添加mac地址后6位
# yaml中某一个组件(switch、sensor、light等)的name: switch-relay0
# 那么在homeassistant中:
# Entity name: [Lenovo.SHD-SPL0-001 74dba8 switch-relay0]
# Entity id: [switch.plug_lenovo_74dba8_switch_relay0]
# Device name: [Lenovo.SHD-SPL0-001 74dba8 switch-relay0]
#因此如果使用name_add_mac_suffix: true的模式编译的固件,同时使用了friendly_name,就可以保证homeassistant中Entity id的唯一性。
#用途:批量删除同一型号的设备再重新添加,只要不改变esphome yaml中的节点名称和组件名称,Entity id不会变化,所有用到这个Entity id的自动化或者脚本都不需要变动,便于维护。
#如果不使用这种方式,删除再重新添加之后,Entity id是乱序的,homeassistant会给相同的esphome_id添加'_1', '_2', '_3'这样的后缀,设备多了就无法维护了。
#插排电源按钮
binary_sensor:
- platform: gpio
#name: button-Power Key Real
id: id_power_key
internal: true
pin:
number: ${button_pin}
inverted: true
mode:
input: true
pullup: true
#插排电源按钮单击、长按功能
on_multi_click:
#长按5s以上,重置为出厂模式,进入配网状态
- timing:
- ON for at least 5s
then:
- logger.log: "Long press."
- switch.turn_on: id_factoryreset_with_energy_counter
invalid_cooldown: 0s
#双击
- timing:
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at least 0.2s
then:
- logger.log: "double click."
invalid_cooldown: 0s
#单击
- timing:
- ON for at most 0.3s
- OFF for at least 0.2s
then:
- logger.log: "single click."
- switch.toggle: id_power_key_logic
invalid_cooldown: 0s