在我的文章《改装欧瑞博CT30W添加射频遥控功能》中提到使用remote_transmitter组件重构代码, 让代码更简洁. 但是这里涉及到一个协议解码的问题.
我使用下述代码打印红外遥控器的值
remote_receiver:
- id: irrecv
pin: 5
tolerance: 15%
#unknown_threshold: 12
idle: 10ms
dump: all
它打印出来的值是:
[remote.pronto:231]
Received Pronto: data=
[remote.pronto:233]
0000 006D 0022 0000 015E 00AC 0019 0015 0018 0015 0019 0014 0018 0015 0018 0015 0018 0015 0018 0015 0018 0015 0018 003E 0018 003E 0018 003E 0018 003E 0019 003D 0019 003D 0019 003D 0019 003D 0019 003D 0018 0015 0018 0015 0018 0015
[remote.pronto:233]
0018 0015 0018 0015 0018 0015 0019 0014 0018 0015 0018 003E 0018 003E 0018 003E 0018 003E 0018 003E 0018 003E 0018 003E 0018 0180
[remote.pronto:231]
Received Pronto: data=
[remote.pronto:233]
0000 006D 0002 0000 015E 0056 0018 0180
可以看到它根本识别不出来这个遥控器的协议. 之后我又使用如下代码构造了NEC协议的红外信号
button:
- platform: template
name: Rotate Right
id: clockwise
# friendly_name: 顺时针转动
# Optional variables:
icon: "mdi:rotate-right"
web_server:
sorting_group_id: sorting_group_button
sorting_weight: 0
on_press:
- remote_transmitter.transmit_nec:
transmitter_id: ir_transmitter
address: 0x00ff
command: 0x807f
command_repeats: 1
它依然没有识别出来NEC协议:
[remote.pronto:231]
Received Pronto: data=
[remote.pronto:233]
0000 006D 0022 0000 015B 00AB 0017 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0015 0016 0015 0016 0040
[remote.pronto:233]
0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0015 0016 0040 0016 0040 0016 0040 0016 0040 0016 0180
这就很奇怪了, 这里肯定是NEC信号无疑了, 却还是识别不出来. 我尝试增大了buffer_size
, 减少tolerance
都没用. 咨询了ChatGPT后, 它推荐了个工具IrScrutinizer, 可以用它分析Pronto格式的红外信号值.
分析过程
Pronto是一种红外信号的表示方式, 与之类似的是RAW格式. 把信号值直接粘贴到IrScrutinizer工具中, 可以看到工具也没能识别出来信号的协议
但是在工具的IRP中给出了{38.0k,194,msb}<3,-3|3,-1627u>(9651u,-4523u,A:32,3,-9651u){A=0xff906f}. 把这个序列告诉DeepSeek, DeepSeek很快给出了分析结果. 它认为这个协议应该是一个NEC扩展协议, 使用两个16位数字表示地址码和命令码. 而<地址码><命令码>序列就是后面的{A=0xff906f}.
代码
使用的代码是这个:
button:
- platform: template
name: Rotate Left
id: anticlockwise
# friendly_name : 逆时针转动
# Optional variables:
icon: "mdi:rotate-left"
web_server:
sorting_weight: 1
sorting_group_id: sorting_group_button
on_press:
- remote_transmitter.transmit_nec:
transmitter_id: ir_transmitter
address: 0xff00
command: 0xf609
command_repeats: 1
根据官方文档中的remote_transmitter组件remote_transmitter.transmit_nec中的相关说明, 这里的address
和command
应该使用MSB格式的数据. 所以把0xff906f
换成了地址码0xff00
和命令码0xf609
.