DIY低成本ESPHome二合一86旋钮开关
简介
玩ESPHome时发现了旋钮传感器,突发奇想,是不是可以DIY一个旋钮开关。看看品牌的旋钮开关动辄上百的,于是淘宝找了找材料。
硬件
材料清单
开关面板不推荐我发的型号质量一般,可以找找其他质量稍好的
名称 |
型号 |
数量 |
链接 |
360度编码器模块 |
- |
1 |
购买 |
ESP-12S模块 |
- |
1 |
购买 |
315MHZ/433MHZ弹簧天线 |
信号不佳可买 |
1 |
购买 |
40P彩排杜邦线 |
母对母 21CM |
1 |
购买 |
AMS1117-3.3 稳压电源芯片降压IC |
AMS1117-3.3 |
1 |
购买 |
220转5V AC-DC降压模块输出 |
5V700mA |
1 |
购买 |
灯光调节器旋钮式开关面板 |
- |
1 |
购买 |
金属膜电阻 1/4W 1% 五色环 100千欧 100K |
可以不买从其他电路板找 |
1 |
购买 |
DIY
1、焊接
刷机焊接:注意把IO0和GND短路,RX,TX与编程器TX、RX反接
电源焊接
线路焊接
注意电阻焊接的位置,一定要焊接一个电阻,否则会有开关乱跳问题
2、刷机
刷机教程可以参考之前帖子视频
3、安装
软件
ESPHome
旋钮相关连接
esphome:
name: esp12s_demo
platform: ESP8266
board: esp12e
wifi:
ssid: "#WIFI名称#"
password: "#WIFI密码#"
captive_portal:
logger:
api:
password: '#api密码#'
services:
- service: send_raw_command
variables:
command: int[]
then:
- remote_transmitter.transmit_raw:
code: !lambda 'return command;'
ota:
password: '#ota密码#'
web_server:
port: 80
# 旋钮GPIO(左右转)
sensor:
- platform: rotary_encoder
name: "esp12s_demo_rotary_encoder"
pin_a: 12
pin_b: 13
# 旋钮按下GPIO
binary_sensor:
- platform: gpio
pin: 14
name: "esp12s_demo_switch"
Node-RED
[
{
"id": "9eba36dd.43cf28",
"type": "tab",
"label": "旋钮",
"disabled": false,
"info": ""
},
{
"id": "295516e5.00099a",
"type": "server-state-changed",
"z": "9eba36dd.43cf28",
"name": "主卧旋钮-按下",
"server": "58e79fdb.2d76d",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "binary_sensor.esp12s_demo_switch",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 150,
"y": 320,
"wires": [
[
"8130d24b.c8486"
],
[
"8130d24b.c8486"
]
]
},
{
"id": "8130d24b.c8486",
"type": "api-current-state",
"z": "9eba36dd.43cf28",
"name": "主卧吸顶灯状态",
"server": "58e79fdb.2d76d",
"version": 1,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "light.master_ceil",
"state_type": "str",
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"blockInputOverrides": false,
"x": 380,
"y": 320,
"wires": [
[
"2aa414d4.df309c"
]
]
},
{
"id": "2aa414d4.df309c",
"type": "switch",
"z": "9eba36dd.43cf28",
"name": "转换",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 550,
"y": 320,
"wires": [
[
"72cb5e2.f4e74a"
],
[
"dd76d0ed.e7109"
]
]
},
{
"id": "dd76d0ed.e7109",
"type": "api-call-service",
"z": "9eba36dd.43cf28",
"name": "打开灯",
"server": "58e79fdb.2d76d",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "light.master_ceil",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 710,
"y": 380,
"wires": [
[]
]
},
{
"id": "72cb5e2.f4e74a",
"type": "api-call-service",
"z": "9eba36dd.43cf28",
"name": "关闭灯",
"server": "58e79fdb.2d76d",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_off",
"entityId": "light.master_ceil",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 710,
"y": 260,
"wires": [
[]
]
},
{
"id": "8e932f35.3d2b1",
"type": "server-state-changed",
"z": "9eba36dd.43cf28",
"name": "主卧旋钮旋转",
"server": "58e79fdb.2d76d",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "sensor.esp12s_demo_rotary_encoder",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 150,
"y": 540,
"wires": [
[
"9a7a924d.11674"
]
]
},
{
"id": "105df0ff.3e258f",
"type": "api-call-service",
"z": "9eba36dd.43cf28",
"name": "调节亮度",
"server": "58e79fdb.2d76d",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "light.master_ceil",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 700,
"y": 540,
"wires": [
[]
]
},
{
"id": "9a7a924d.11674",
"type": "change",
"z": "9eba36dd.43cf28",
"name": "处理亮度",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"data\":{\"brightness_pct\"number(payload)*10}}",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 540,
"wires": [
[
"105df0ff.3e258f"
]
]
},
{
"id": "58e79fdb.2d76d",
"type": "server",
"name": "Home Assistant",
"legacy": false,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": false
}
]
最后
这个DIY最后自己也没用起来,因为NR这块写的比较简单,调整Yeelight时速度一快就控制超时,希望高手优化下,而且应该还可以有更多玩法,希望大家给给意见