『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 679|回复: 0

[求助] 大佬帮忙看看这段esphome的代码是什么功能?

[复制链接]

18

主题

424

帖子

1913

积分

金牌会员

Rank: 6Rank: 6

积分
1913
金钱
1489
HASS币
0
发表于 2023-5-17 13:03:03 | 显示全部楼层 |阅读模式
一个固件写了esphome的万能红外遥控
我想实现在万能接收到红外信号时触发ha的自动化
论坛有大佬写了mqtt方式的教程
https://bbs.hassbian.com/thread-13759-1-4.html
不过我的环境使用mqtt老是出问题

搜索到下面的代码

# Read codes from IR remote
remote_receiver:
  pin:
    number: GPIO22
    inverted: True
    mode: INPUT_PULLUP
  dump: all
  on_nec:
  - homeassistant.service:
      service: script.my_ir_remote
      data:
        address: "0x0FF"
      data_template:
        command: "{{ cmd_hex_string }}"
      variables:
        cmd_hex_string: !lambda |-
            char buf[12];
            buf[11] = 0;
            sprintf(buf,"0x%X",x.command);
            ESP_LOGI("main", "Sending IR remote command to hass: %s", buf);
            return std::string(buf);

刷入固件后接收到红外信号时在esphome的log里可以看到下面内容

[12:52:55][I][main:105]: Sending IR remote command to hass: 0xDD22
[12:52:58][I][main:105]: Sending IR remote command to hass: 0xDD22
[12:53:01][I][main:105]: Sending IR remote command to hass: 0xDD22
[12:53:04][I][main:105]: Sending IR remote command to hass: 0xDC23

=============================================================
向 hass 发送 IR 遥控命令:0xDC23
看翻译是信号传到了ha 不知道是不是这么理解
可是我在ha里找不到相关的服务
大佬们指点下是怎么回事
或者有其他方式的也请大佬一起发出来
感激不尽















回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-3 13:53 , Processed in 0.696705 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表