因为小米的网关老是离线,我把设备换到zigbee2mqtt了,这样一来就没办法用小爱控制了。
各种接入都需要外网访问,比较麻烦。
结合https://bbs.hassbian.com/thread-9628-1-1.html 红外接入的方式。
采用小爱控制小米遥控器,ESPhome接受遥控器信息转发MQTT,MQTT触发自动化的方式实现小爱控制HA设备,当然了,没有状态反馈,实际上状态反馈也不太需要。
把小米的万能遥控器拆开,把ESP12F板子接上去
3.3v位置,GND应该好找
ESPhome配置如下
esphome:
name: irrcv
platform: ESP8266
board: esp12e
wifi:
ssid: "xxxxx"
password: "xxxxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Irrcv Fallback Hotspot"
password: "aE03Sn8tFLRZ"
captive_portal:
# Enable logging
logger:
ota:
password: 'xxxxx'
web_server:
port: 80
mqtt:
broker: 192.168.xxx
username: xxxxx
password: xxxxx
time:
- platform: sntp
id: my_time
timezone: Asia/Shanghai
remote_receiver:
pin:
number: GPIO4
inverted: True
# mode: INPUT_PULLUP
dump: all
on_nec:
then:
- mqtt.publish:
topic: esphome32/irrcv/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: esphome32/irrcv/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.address, x.command);
ESP_LOGI("main", "pana: %s", temp);
return temp;
on_sony:
then:
- mqtt.publish:
topic: esphome32/irrcv/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.data, x.nbits);
ESP_LOGI("main", "sony: %s", temp);
return temp;
on_jvc:
then:
- mqtt.publish:
topic: esphome32/irrcv/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d", x.data);
ESP_LOGI("main", "jvc: %s", temp);
return temp;
on_samsung:
then:
- mqtt.publish:
topic: esphome32/irrcv/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d", x.data);
ESP_LOGI("main", "samsung: %s", temp);
return temp;
on_rc5:
then:
- mqtt.publish:
topic: esphome32/irrcv/ir
payload: !lambda |-
char temp[20];
sprintf(temp, "%d:%d", x.address, x.command);
ESP_LOGI("main", "rc5: %s", temp);
return temp;
我采用的是GPIO4.
刷好之后把万能遥控器装回去。
然后可以找些别人的电视遥控器,随便学习一些按键。
学习完之后在万能遥控器里面按下然后看mqtt收到的数据是什么,更具相应的数据设置自动化。这样HA这边就设定好了。
接下来设置米家。
米家里面需要在智能里面添加手动执行,然后再在小爱里面训练,具体可以看看这个文章
https://www.zhihu.com/answer/455573636
|