当前位置:网站首页>esphome自制红外遥控器接入HA,用来控制灯光,开关等,可使用任意遥控控制
esphome自制红外遥控器接入HA,用来控制灯光,开关等,可使用任意遥控控制
2022-07-22 19:29:00 【分享大师】
目录
项目背景
最近看中智能小夜灯的项目,通过淘宝几块钱购买人体感应小夜灯(使用外壳),然后机子画板子加入esp8266联网控制,接入homeassistant,做智能控制。
目前以实现以下功能:
- 红外人体侦测
- ld2410微波侦测
- 环境光亮度侦测
- 夜灯控制
- RGB彩灯控制
- dht11温湿度读值(不准)
- 红外发射与接收
既然已经实现红外发射与接收,那么有没有可能通过这个设备,做为普通红外遥控转接信号来控制已接入homeassistant的其他设备呢?

实现过程
网上论坛大神已提供相关代码,原作者帖子
实现步骤:
- 红外(或者315 433射频)遥控器发射信号
- 接收头接收到信号后给到ESP
- ESP交给MQTT
- HA里面根据MQTT内容执行相应的自动化
仅验证红外部分,实测可用:
- 使用esphome来识别红外遥控按键代码[main:094]: nec: 1886437949:0
[20:26:22][D][remote.pronto:229]: Received Pronto: data=0000 006D 0001 0000 0003 06C3
[20:26:23][I][main:094]: nec: 1886437949:0
[20:26:23][D][remote.pronto:229]: Received Pronto: data=0000 006D 0001 0000 0002 06C3
[20:26:23][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AD 00AB 0018 003F 0019 06C3
[20:26:24][I][main:094]: nec: 1886437949:0
[20:26:24][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AD 00AB 0019 003E 0018 06C3
[20:26:31][D][remote.pronto:229]: Received Pronto: data=0000 006D 0001 0000 0001 06C3
[20:26:35][I][main:094]: nec: 1886413469:0
[20:26:35][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AE 00AA 0019 003E 0018 06C3
[20:26:37][I][main:094]: nec: 1886413469:0
[20:26:37][D][remote.pronto:229]: Received Pronto: data=0000 006D 0001 0000 0003 06C3
[20:26:37][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AE 00AA 0018 003F 0018 06C3
[20:26:38][I][main:094]: nec: 1886413469:0
[20:26:38][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AE 00AA 0019 003E 0018 06C3
[20:26:40][I][main:094]: nec: 1886413469:0
[20:26:40][D][remote.pronto:229]: Received Pronto: data=0000 006D 0003 0000 00AF 00A9 0018 003F 0019 06C3建立自动化例子
alias: num4 toggle ir_conf
trigger:
- platform: mqtt
topic: ir_conf/senso/ir
payload: '1886413469:0'
action:
- service: switch.toggle
data:
entity_id: switch.wall_switch_left_158d0xxxx使用红外遥控来验证

参考代码
附上esphome代码:
esphome:
name: ir_conf
esp8266:
framework:
version: 2.7.4
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.1.178
#static_ip: 192.168.1.10
# Set this to the IP address of the router. Often ends with .1
gateway: 192.168.1.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0
#DNS1: 192.168.31.1
# Enable fallback hotspot (captive portal) in case wifi connection fails
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Light Xiaoyedeng"
password: "MynRqBY96AUC"
captive_portal:
# remote_receiver:
# id: rcvr
# pin:
# number: D5
# inverted: true
# # mode:
# # input: true
# # pullup: true
# dump: #all
# - nec
# - raw
mqtt:
broker: !secret broker
username: !secret mqtt_name
password: !secret mqtt_password
discovery: true
remote_receiver:
pin:
number: D5
inverted: True
mode: INPUT_PULLUP
dump: all
on_nec:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.address, x.command);
ESP_LOGI("main", "nec: %s", temp);
return temp;
on_panasonic:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.address, x.command);
ESP_LOGI("main", "nec: %s", temp);
return temp;
on_sony:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.data, x.nbits);
ESP_LOGI("main", "nec: %s", temp);
return temp;
on_samsung:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.data, x.nbits);
ESP_LOGI("main", "nec: %s", temp);
return temp;
on_jvc:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d", x.data);
ESP_LOGI("main", "nec: %s", temp);
return temp;
on_rc5:
then:
- mqtt.publish:
topic: ir_conf/sensor/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.address, x.command);
ESP_LOGI("main", "nec: %s", temp);
return temp;
边栏推荐
- 《STL适配器》stack和queue
- Gom引擎Key.lic配套的X-FKGOM授权启动
- HCDE城市闭门会南京站成功举办
- 【MATLAB项目实战】基于SPI指数的某地区地区干旱时空特征分析
- Codeforces Round #808 (Div. 2) C,D Codeforces Round #809 (Div. 2) C
- 华为昇腾比赛资料
- CV target detection model sketch (1)
- Interviewer: how to solve the problem of a large number of requests for data that does not exist in redis, which affects the database?
- In the name of "upgrade", talk about the core technology of cloud native data warehouse analyticdb
- 100 行代码透彻解析 RPC 原理
猜你喜欢
随机推荐
ABAP ALV steps
《STL容器篇》-List模拟实现(三种反向迭代器)
怎么让自己在how old robot显得年轻?我看起来几岁更年轻方法技巧
Demo19- (to be updated)
Basic concepts of relational database
CV target detection model sketch (1)
MyCms 自媒体商城 v3.5 发布,新增免费插件
Interviewer: how to solve the problem of a large number of requests for data that does not exist in redis, which affects the database?
TCP四次挥手
GB28181流媒体服务LiveGBS使用和二次开发中常见问题总结
ipv4无internet访问权限怎么办?ipv4无internet访问权限解决方法(图文详解)
How to calculate the time-consuming code gracefully? (glory Collection Edition)
实现OPC UA publish/subscribe单次发送
Mktdt03 of Shanghai stock exchange quotation document analysis
在 MySQL 中使用枚举的陷阱一定要注意!
STL adapter stack and queue
科学计算与仿真-高斯牛顿法的非线性最小二乘问题简单介绍与应用
ABAP语法基础5
Pikachu shooting range SQL injection search injection clearance steps
LiveGBS-摄像机网页低延时无插件直播实现









