本帖最后由 zro22 于 2023-6-17 22:04 编辑
是这样的,我买了个万能遥控器,包含了红外,蓝牙,射频433和315。对,我也买了个这个帖子说的几百块的遥控器
https://bbs.hassbian.com/thread-14172-1-1.html
然后用ESP32做了一个RF桥,负责接收射频信号然后把码转给MQTT。
为了方便写自动化,创建了一个blueprint,具体内容就是侦测MQTT的topic,判断topic里面的码,开关对应的灯。blueprint写好之后,配置自动化,只需要选择码加上对应的设备就可以了。
算是学习了一下blueprint的编写,中间还趟了几个坑,或者不叫坑,是摸索的过程。
整个blueprint如下(这个是单码控制单/多灯,我实际用是四码控制四/多灯)
东西一旦写好实际很简单,大家一看就懂,但是写的过程很痛苦,一点点看示例,debug。
比如最开始value_a没有指定类型,结果跟踪debug发现 playload是 11111 value_a是'11111'导致判断为0不执行。
还有开始只写了switch.turn_on 发现无法turn_on light,所以加了一个light_turn_on。
发在论坛权当是一个备份吧,不然过几天又忘了怎么写。
我的RF码是aabb0或者aabb1 0代表关 1代表开,如果你的码不是这样,就需要分别定义开和关的码。
blueprint:
name: mqtt topic to trigger switch or light 4 cnt
description: create 4 rf bridge or other mqtt topic value to control light or switch
domain: automation
input:
mqtttopic:
value_a:
selector:
number:
light_a:
selector:
entity:
domain:
- light
- switch
multiple: true
trigger:
platform: mqtt
topic: !input mqtttopic
action:
- variables:
payload: "{{ trigger.payload }}"
value_a: !input value_a
- choose:
- conditions:
- "{{ payload == value_a*10 }}"
sequence:
- service: switch.turn_off
data:
entity_id: !input light_a
- service: light.turn_off
data:
entity_id: !input light_a
- conditions:
- "{{ payload == value_a*10+1 }}"
sequence:
- service: switch.turn_on
data:
entity_id: !input light_a
- service: light.turn_on
data:
entity_id: !input light_a
如下是四路的
blueprint:
name: mqtt topic to trigger switch or light 4 cnt
description: create 4 rf bridge or other mqtt topic value to control light or switch
domain: automation
input:
mqtttopic:
value_a:
selector:
number:
value_b:
selector:
number:
value_c:
selector:
number:
value_d:
selector:
number:
light_a:
selector:
entity:
domain:
- light
- switch
multiple: true
light_b:
selector:
entity:
domain:
- light
- switch
multiple: true
light_c:
selector:
entity:
domain:
- light
- switch
multiple: true
light_d:
selector:
entity:
domain:
- light
- switch
multiple: true
trigger:
platform: mqtt
topic: !input mqtttopic
action:
- variables:
payload: "{{ trigger.payload }}"
value_a: !input value_a
value_b: !input value_b
value_c: !input value_c
value_d: !input value_d
- choose:
- conditions:
- "{{ payload == value_a*10 }}"
sequence:
- service: switch.turn_off
data:
entity_id: !input light_a
- service: light.turn_off
data:
entity_id: !input light_a
- conditions:
- "{{ payload == value_a*10+1 }}"
sequence:
- service: switch.turn_on
data:
entity_id: !input light_a
- service: light.turn_on
data:
entity_id: !input light_a
- conditions:
- "{{ payload == value_b*10 }}"
sequence:
- service: switch.turn_off
data:
entity_id: !input light_b
- service: light.turn_off
data:
entity_id: !input light_b
- conditions:
- "{{ payload == value_b*10+1 }}"
sequence:
- service: switch.turn_on
data:
entity_id: !input light_b
- service: light.turn_on
data:
entity_id: !input light_b
- conditions:
- "{{ payload == value_c*10 }}"
sequence:
- service: switch.turn_off
data:
entity_id: !input light_c
- service: light.turn_off
data:
entity_id: !input light_c
- conditions:
- "{{ payload == value_c*10+1 }}"
sequence:
- service: switch.turn_on
data:
entity_id: !input light_c
- service: light.turn_on
data:
entity_id: !input light_c
- conditions:
- "{{ payload == value_d*10 }}"
sequence:
- service: switch.turn_off
data:
entity_id: !input light_d
- service: light.turn_off
data:
entity_id: !input light_d
- conditions:
- "{{ payload == value_d*10+1 }}"
sequence:
- service: switch.turn_on
data:
entity_id: !input light_d
- service: light.turn_on
data:
entity_id: !input light_d
|