标签:# <标签:0 x00007fc3f7872388 >

也许我误解了你的要求,但是你所需要做的就是修改字典的内容。例如,更改以下内容:

“DF9BE1”:[‘remote-1a’,‘上’,'假'],“DF9BE2”:[‘remote-1b’,‘上’,'假'],“DF9BE4”:[‘remote-1c’,‘上’,'假'],“DF9BE8”:[‘remote-1d’,‘上’,‘假’),

:

“DF9BE1”:[' remote-1 ',”按钮”,“假”),“DF9BE2”:[‘remote-1’,”按钮B”,“假”),“DF9BE4”:[‘remote-1’,‘按钮C’,'假'],“DF9BE8”:[‘remote-1’,”按钮D ', '假'),

然后只需修改现有的MQTT Sensor,以侦听适当的主题(我假设是这样的主题家庭/ remote1),并删除已经存在的value_template。

—平台:mqtt名称:'Remote1' state_topic: 'home/ Remote1' expire_after: 2

你是合适的 - 这确实工作并使山脉彻底削减。非常感谢!

你好,

我使用这个python脚本很多次,但我不知道从多少次我有这个错误:

2020-05-07 15:42:52信息(mainthread)[homeassistant.components.automation]执行[sys] demux rf传感器2020-05-07 15:42:52信息(mainthread)[homeassistant.components.automation] [Demux RF传感器:运行脚本2020-05-07 15:42:52信息(Mainthread)[homeassistant.components.automation] [sys] demux rf传感器:执行步骤呼叫服务2020-05-07 15:42:52错误(mainthread)[homeassistant.components.automation] [sys] demux rf传感器:执行脚本错误。POS 1的Call_Service意外错误:错误呈现数据模板:undefinedError:'dict对象'没有属性'rfreceived'回溯(最近调用最后一个):file“/usr/src/homeassistant/homeassistant/helpers/template.py”,第222行,在Async_Render返回编译编译。render(kwargs).strip()文件“/usr/local/lib/python3.7/site-packages/jinja2/environment.py”,line 1090,rense self.environment。hange_exception()文件“/usr/local/lib/python3.7/site-packages/jinja2/environment.py”,第832行,在hange_exception reraise中(* rewrite_traceback_stack(source = source))文件“/ usr / local / lib/ python3.7/site-packages/jinja2/_compat.py“,第28行,在reraise提升值.with_traceback(tb)文件”<模板>“,第1行,顶级模板代码文件”/ usr / local/lib/python3.7/site-packages/jinja2/sandbox.py“,line 407,在getattr value = getattr(obj,属性)jinja2.exceptions.undefindedError:'dict对象'在处理过程中没有属性'rfreceive'以上例外,另一个例外CURRED:回溯(最近调用最后一个电话):文件“/usr/src/homeassistant/homeassistant/helpers/service.py”,第132行,在async_prepare_call_from_config template.render_complex(conf conf [conf_service_data_template],变量)文件“/ usr / src中/homeassistant/homeassistant/helpers/template.py“,第71行,render_complex return {key:render_complex(项目,变量)为key,项目中的项目.Items()}文件”/ usr / src / homeassistant / homeassistant / excomeassistant / expersist/template.py“,第71行,在 return {key:render_complex(项目,变量)for key.items()}文件”/usr/src/homeassistant/homeassistant/helpers/template.py“,第73行,在render_complex返回值中.Async_render(变量)文件”/usr/src/homeassistant/homeassistant/helpers/template.py“,第224行,在Asysync_render raint teptionError(err)homeassistant.exceptions.templateError:undefinedError:'dict对象'没有属性'rfreceived'上述例外是以下例外的直接原因:traceback(最近的呼叫last):文件“/usr/src/homeassistant/homeassistant/helpers/script.py”,第153行,在_async_step self,f“_async_ {cv.determine_script_action(self._action)} _步”文件“/ usr / src /homeassistant/homeassistant/helpers/script.py", line 623, in _async_call_service_step *self._prep_call_service_step(), blocking=True, context=self._context File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 252, in _prep_call_service_step return async_prepare_call_from_config(self._hass, self._action, self._variables) File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 135, in async_prepare_call_from_config raise HomeAssistantError(f"Error rendering data template: {ex}") from ex homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'dict object' has no attribute 'RfReceived' 2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived' 2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived' 2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived' 2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived' 2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] Executing [SYS] DEMUX RF Sensor 2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Running script 2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Executing step call service 2020-05-07 15:53:23 INFO (SyncWorker_17) [homeassistant.components.python_script] Executing rfbridge_demux.py: {'payload': '0x14000C'}

这是我的自动化:

- alias: '[SYS] DEMUX RF Sensor'触发器:rfbridge_demux data_template: payload: '{{trigger.payload_json.RfReceived.Data}}'

这是我的脚本:

d = {# Codici RF / Tasmota e / OMG # Codici sensori magnetici每Tasmota“0 x4ad50a”:[‘portone’,‘上’,'真的'],“0 x4ad50e”:[‘portone’,‘了’,'真的'],“0 x4ad506”:[‘portone_bat’,‘上’,‘假’),# 0 x4a820a:[‘fin_sala’,‘上’,'真的'],“0 x4a820e”:[‘fin_sala’,‘了’,'真的'],“0 x4a8206”:[‘fin_sala_bat’,‘上’,‘假’),#“0 xd9140a”:[‘fin_bagnop’,‘上’,'真的'],“0 xd9140e”:[‘fin_bagnop’,‘了’,'真的'],“0 xd91406”:[‘fin_bagnop_bat’,‘上’,‘假’),# 0 x5c5a0a:[‘fin_bagnog’,‘上’,'真的'],“0 x5c5a0e”:[‘fin_bagnog’,‘了’,'真的'],“0 x5c5a06”:[‘fin_bagnog_bat’,‘上’,‘假’),# 0 x44350a:[‘fin_camera_vale’,‘上’,'真的'],“0 x44350e”:[‘fin_camera_vale’,‘了’,‘真正的’),“0 x443506”:[‘fin_camera_vale_bat’,‘上’,‘假’),# 0 xd8040a:[‘fin_camera_cri’,‘上’,'真的'],“0 xd8040e”:[‘fin_camera_cri’,‘了’,'真的'],“0 xd80406”:[‘fin_camera_cri_bat’,‘上’,‘假’),# 0 x3f7d0a:[‘fin_cucinap’,‘上’,'真的'],“0 x3f7d0e”:[‘fin_cucinap’,‘了’,'真的'],“0 x3f7d06”:[‘fin_cucinap_bat’,‘上’,‘假’),#“0 xd85c0a”:[‘fin_cucinag’,‘上’,'真的'],“0 xd85c0e”:[‘fin_cucinag’,‘了’,'真的'],“0 xd85c06”:[‘fin_cucinag_bat’,‘上’,‘假’),# 0 x4aae0a:[‘fin_camera_letto’,‘上’,'真的'],“0 x4aae0e”:[‘fin_camera_letto’,‘了’,'真的'],“0 x4aae06”:[‘fin_camera_letto_bat’,‘上’,'假']}p = data.get(“有效载荷”)如果p不是没有:如果p在d.keys ():service_data ={“主题”:“家庭/ RF433 /{}”.format (d [p][0]),“有效载荷”:“{}”.format (d [p][1]),“qos”:0,“保留”:“{}”.format (d [p] [2])}: service_data ={“主题”:“home /未知”,“有效载荷”:“{}”.format (p)、“qos”:0,“保留”:“假”}记录器。warning(' Received unknown RF command: {}'.format(p)) hasss .services. services调用('mqtt', 'publish', service_data, False)

脚本重新发送MQTT消息也和所有工作良好,但我不想删除这个错误。

有些人也有这个错误吗?

下面是经过编辑的日志摘录,显示了自动化的正常执行,其中它接收正确格式的数据,并将接收到的值传递给python_script。

15:53:23 Executing [SYS] DEMUX RF Sensor 15:53:23 [SYS] DEMUX RF Sensor: Running script 15:53:23 [SYS] DEMUX RF Sensor: Running script 15:53:23 [SYS] DEMUX RF Sensor: Executing step call service 15:53:23 INFO Executing rfbridge_demux.py: {'payload': '0x14000C'}

下面是一个经过编辑的摘录,显示了一个不正常的自动化执行。

15:42:52 execution [SYS] DEMUX RF Sensor 15:42:52 [SYS] DEMUX RF Sensor: Running script 15:42:52 [SYS] DEMUX RF Sensor: Running script 15:42:52 [SYS] DEMUX RF Sensor: execution step call service 15:42:52 ERROR [SYS] DEMUX RF Sensor: ERROR Executing script。错误渲染数据模板:UndefinedError: 'dict object' has no attribute 'RfReceived'

在自动化过程中出现错误。有时它接收的数据不是所需的格式,也就是说它缺少RfReceived属性。

错误渲染数据模板:UndefinedError: ' dict object '没有属性'rfreceived'

似乎有些时候当话题电视/ temp /结果接收的消息不是预期格式(即缺少RfReceived属性)。它无法具有此格式:

{“RFRECEIVED”:{“同步”:14110,“低”:480,“高”:1380,“数据”:“12345E”,“RFKEY”:“无”}}

我不知道为什么会发生这种情况。我所能提供的就是修改自动化,以便它拒绝缺少RFRECeived属性的消息。

- alias: '[SYS] DEMUX RF Sensor'触发器:- platform: mqtt topic: tele/temp/RESULT condition: - condition: template value_template: > {{trigger. name: '[SYS] DEMUX RF Sensor'定义了Payload_json和trigger.payload_json。RfReceived是defined and trigger.payload_json.RfReceived.Data is defined }} action: - service: python_script.rfbridge_demux data_template: payload: '{{trigger.payload_json.RfReceived.Data}}'

嗨...寻求一些帮助。我已配置脚本但收到错误。
找不到错误。

rfbridge_demultiplexer:执行脚本错误。数据模板:UndefinedError: ' trigger '是未定义的

这是建议的自动化:

—alias: 'rfbridge_demultiplexer'触发器:—platform: mqtt topic: tele/RF_Bridge/RESULT action:—service: python_script。rfbridge_demux data_template: payload: '{{trigger.payload_json.RfReceived.Data}}'

你的版本是这样的吗?如果没有,请寄给我以便我检查。
另外,您是否配置了python_script根据其整合指令

我肯定我错过了一些简单的东西,我的天赋已经耗尽了。

我一直在使用Demux,以获得巨大的成功,并在新机器上重建了我的HA实例。

现在我的射频桥消息都没有被HA看到。

我可以看到MQTT Explorer和Mosquitto中的消息在其他MQTT设备上运行良好。

这是我所拥有的和一些二进制传感器配置的例子。伟德国际官方app下载苹果版自从迁移到新机器后,这些内容都没有经过编辑。

- 别名:'rfbridge_demultiplexer'触发器: - 平台:mqtt主题:tele / garage_rf_bridge /结果 - 平台:mqtt主题:tele / rf_bridge_west /结果 - 平台:mqtt主题:tele / rf_bridge_east /结果 - 平台:mqtt主题:tele / rf_bridge_stable/结果 - 平台:MQTT主题:Tele / RF_Bridge_1st_Floor / Result Action: - 服务:Python_script.rfbridge_demux data_template:poyload:'{{trigger.payload_json.rfreceived.data}}'
d = {D3226E:[‘garage_motion’,‘上’,'假'],“51 f65a”:[‘telegraph_pole_garage’,‘上’,'假'],“119 b0a”:[“garage_door”,“上”,“真正的”),“119 b0e”:[‘garage_door’,‘了’,‘真正的’),“715 fff”:[‘gym_motion’,‘上’,'假'],“9 f150a”:[‘garage_motion_2’,‘上’,'假'],“49732 e”:[“courtyard_gates”,“上”,“真正的”)、“497327”:[‘courtyard_gates’,‘了’,‘真正的’),2479 ee:(“catflap”,“上”,“真正的”)、“2479 e7”:[‘catflap’,‘了’,‘真正的’),“85 d80a”:[“oskaflap”,“上”,“真正的”)、“85 d80e”:[‘oskaflap’,‘了’,'真的'],“F9010A”:[‘back_door’,‘上’,'真的'],“F9010E”:[‘back_door’,‘了’,‘真正的’),“91 f60a”:[“gym_door”,“上”,“真正的”)、“91 f60e”:[‘gym_door’,‘了’,‘真正的’),# 545 f10的:[‘back_door_motion’,‘上’,‘假’),71 bdee:(“front_door”,“上”,“真正的”)、“71 bde7”:[‘front_door’,‘了’,'真的'],“C5790A”:[“冰箱”,“对”,“真正的”),“C5790E”:[“冰箱”,“从”,“真正的”),“A68B23”:[“信箱”、“上”,“假”)、“142186”:[‘stable_motion’,‘上’,'假'],“54 f65a”:[‘north_east_pir’,‘上’,'假'],“45 f64a”:[‘north_central_pir’,‘上’,'假'],“4 df64a”:[‘north_west_pir’,‘上’,‘假’),“49 f64a”:[‘garage_north_pir’,‘上’,'假'],“59 f65a”:[‘pergola_pir’,‘上’,'假'],“6 df66a”:[‘courtyard_pir’,‘上’,'假'],“61 f66a”:[‘south_central_pir’,‘上’,'假'],“AA0D0A”:[‘south_central_pir_2’,‘上’,'假'],“850 e0a”:[‘south_east_pir’,‘上’,'假'],“780 e0a”:[‘firepit_pir’,‘上’,'假'],“32 f63a”:[‘carpark_pir’,‘上’,‘假’),64 f66a:[‘driveway_1_pir’,‘上’,'假'],“42 f64a”:[‘driveway_2_pir’,‘上’,'假'],“545 f10”:[‘firepit_2_pir’,‘上’,'假'],“3 ef63a”:[‘garage_west_pir’,‘上’,'假'],“85 e9ee”:[“gun_cabinet_door”,“上”,“真正的”),“85 e9e7”:[‘gun_cabinet_door’,‘了’,'真的'],“54 f65f”:[‘north_east_pir_battery’,‘上’,‘假’),“45 f64f”:[‘north_central_pir_battery’,‘上’,'假'],“4 df64f”:[‘north_west_pir_battery’,‘上’,'假'],“49 f64f”:[‘garage_north_pir_battery’,‘上’,'假'],“59 f65f”:[‘pergola_pir_battery’,‘上’,'假'],“6 df66f”:[‘courtyard_pir_battery’,‘上’,'假'],“61 f66f”:[‘south_central_pir_battery’,‘上’,‘假’),“AA0D0F”:[‘south_central_pir_2_battery’,‘上’,'假'],“850 e0f”:[‘south_east_pir_battery’,‘上’,'假'],“780 e0f”:[‘firepit_pir_battery’,‘上’,'假'],“32 f63f”:[‘carpark_pir_battery’,‘上’,'假'],“64 f66f”:[‘driveway_1_pir_battery’,‘上’,'假'],“42 f64f”:[‘driveway_2_pir_battery’,‘上’,'假'],“545 f1f”:[‘firepit_2_pir_battery’,‘上’,‘假’),“3 ef63f”:[‘garage_west_pir_battery’,‘上’,'假'],“861 b2f”:[‘courtyard_gates_battery’,‘上’,'假'],“71 bdef”:[‘front_door_battery’,‘上’,'假'],“85 e9ef”:[‘gun_cabinet_door_battery’,‘上’,'假'],“2479 ef”:[‘catflap_battery’,‘上’,'假'],“85 d80f”:[‘oksaflap_battery’,‘上’,'假'],“A74723”:[‘awning_vibration’,‘上’,‘假’),“A7472F”:[‘awning_vibration_battery’,‘上’,'假'],“51 f65f”:[‘telegraph_pole_garage_battery’,‘上’,'假'],“9 f150f”:[‘garage_motion_2_battery’,‘上’,'假'],“C5790F”:[‘fridge_battery’,‘上’,'假'],“D3226F”:[‘garage_motion_battery’,‘上’,'假'],“F9010F”:[‘back_door_battery’,‘上’,‘假’),“A68B2F”:[‘letterbox_battery’,‘上’,'假']}p = data.get(“有效载荷”)如果p是不没有:如果p在d.keys (): service_data ={“主题”:“home /{}”.format (d [p][0]),“有效载荷”:“{}”.format (d [p][1]),“qos”:0,“保留”:“{}”.format (d [p] [2])}: service_data ={“主题”:“home /未知”,“有效载荷”:“{}”.format (p)、“qos”:0,“保留”:“假”}记录器。warning(' Received unknown RF command: {}'.format(p)) hasss .services. services调用('mqtt', 'publish', service_data, False)
-平台:mqtt name: 'Garage Door' state_topic: 'home/garage_door' device_class: Door - platform: mqtt name: 'home/gym_door' state_class: 'home/gym_motion' off_delay: 3 device_class: Motion

MQTT设置已在Tasmota配置中适当更改。

如果你能给我建议,我将不胜感激。

我假定您已经使用MQTT Explorer来确认您的射频桥正在发布到它们各自的主题:

Tele / Garage_RF_Bridge /结果Tele / RF_Bridge_West /结果Tele / RF_Bridge_east /结果Tele / RF_Bridge_Stable /结果Tele / RF_Bridge_1ST_Floor /结果

我建议你:

  1. 使用开发者工具>状态确认状态automation.rfbridge_demultiplexer.如果当前为,则打开它
  2. 使用开发者工具>服务确认python_script.rfbridge_demux是可用的服务。如果它不存在,请正确仔细检查已安装Python_script集成。

我只知道这肯定是一些对我来说不明显的东西。现在安装。

非常感谢。

当你换到一台全新的机器上时这很容易被忽略。


编辑

谢谢你提到你发明了一台新机器。如果您忽略了这个细节,那么调试这个问题就会花费更多的时间和精力。

1就像

现在都在工作。再次感谢。

1就像

谢谢!!!作品伟大,真的很容易遵循说明。:+1:

1就像

向它添加了更多的python

如果p不是none:如果p在d.keys()中:service_data = {'主题':'home / {}'。格式(d [p] [0]),'有效载荷':'{}'。格式(d [p] [1]),'qos':0,'保留':'{}'。格式(d [p] [2])} else:bla_bla =“'{}':[' -  +-  +  -  +  -  +','上','真/假'],“。格式(p)b_sensor =”binary_sensors \ n  - 平台:mqtt \ n名称:'新二进制传感器名称'\ n nation_topic:'home /  -  +  -  +  -  +  -  +'\ n device_class:doot \ n off_delay:1“.format(p)hass.services.call('persistent_notification','create',{'message':'{} \n \ n复制上面的代码\ n将其粘贴到rfbridge_demux.py \ n \ n {}'中。格式(bla_bla,b_sensensor),'title':'new rf code'})service_data = {'主题':'home/未知','有效载荷':'{}'。格式(p),'qos':0,'保留':'false'} hass.services.call('mqt','publish',service_data,false)

如果不知道RF代码,它会为您创建通知
在右sh格式,所以你可以复制/粘贴它。

图像

希望它能帮助到别人

如果你有塔斯莫塔红外线,那你就是脑子短路了

只要改变话题和有效载荷

到红外协议

—alias: 'IR_Bridge Data'触发器:—platform: mqtt topic: tele/IR/RESULT action:—service: python_script。rfbridge_demux data_template: payload: '{{trigger.payload_json.IrReceived}}'

你可以在python脚本中使用相同的逻辑

这是红外密码

图像

1就像

我找到了这个胎面和Python代码@ 123.卡拉斯惊人的帮助。但当他向YAML大师指出它时,他给我看了这个。我使用的是python策略#2并且不打算更改,但是如果您知道YAML代码将为此工作,我认为这将不会触发日志垃圾邮件。这似乎就是HA用于处理此类事情的方式。

—platform: mqtt name: this_door state_topic: tele/RF_Bridge/RESULT value_template: > {%- if value_json['RfReceived']。数据定义和value_json['RfReceived'].Data['E4180!%}{%-如果value_json['RfReceived']。数据== 'E4180E' -%} ON {%- elif value_json['RfReceived']。Data == 'E4180A' -%} OFF {% endif %} {% else %} {{states('binary_sensor.this_door')}} {% endif %} availability_topic: "tele//RF_Bridge/LWT" payload_available: "Online" payload_not_available: "Offline" device_class: door qos: 1

它专门查找代码库,数据中的常见数字相同,这可以用作设备标识符。如果它没有看到它,它只发送回流状态。这不应该触发警告。
我没有插入这个代码并测试它,所以如果它需要触摸让我们修复它,我抓住了他所拥有并插入rfbrid的东西(而不是zigbee桥的东西),你看到了主体。如果重新允许的值不是其中之一,它会给visorot一个。

有效的策略#1除了模板采取额外的预防措施,确认负载包含变量value_json.rfreceived.data.在使用之前。

重要的部分是它验证了收到的数据来自您正在寻找的传感器,即数据的共同部分,使得该代码具有唯一的该传感器。如果不是,它只返回当前状态,所以HA不会关心或认为您有相同的多个答案(相对于ON/OFF)
重要的部分是,它验证接收到的数据是来自您正在寻找的传感器,即使此代码对该传感器唯一的数据的公共部分。如果不是,它只返回当前状态,所以HA不会关心或认为您有相同的多个答案(相对于ON/OFF)
@Blakadder.从他的ZigBee桥上向我展示了这篇文章,所以我以此在这里做了同样的例子

你可能想看看这个帖子的第一个帖子,因为你确实描述了“策略1:value_template”是如何操作的。就像你刚才解释的那样。

唔。大概吧。显然是2年前,当我读到我不明白的时候,爱的策略2如此之多,我从来没有给出了另一个想法(直到呼吁它)。哦,好吧,这有点不同,比特更有效,因为它不是在1 -if-而不是2.而不是2.它可能有助于某人......

我很高兴听到你现在明白了它使用了与策略1相同的方法。

你有过测试吗?我有,事实上,它并不效率,甚至没有工作。

控件中的这个小语法错误availability_topic

availability_topic:“tele / / RF_Bridge /轻型”^

真正的问题是第二个测试中的错误:

和value_json [' RfReceived '] . data [' E4180 !']的定义是^^^^^^^^^^

在点表示法中,模板期望JSON路径如下:

value_json.rfreceived.data.e4180!

有效载荷的JSON结构看起来像这样:

{"RfReceived":{"Data":"E4180E"}}

但是,模板的JSON PATH期望有效载荷看起来像这样:

{" RfReceived ":{"数据":{" E4180 !”:“? ?”}}}

它将从来没有具有该结构,因此模板中的第二个测试总是评估.这意味着返回的结果是总是这:

{{州(binary_sensor.this_door)}}

由于第一篇文章中解释的原因,那个模板也不正确。binary_sensor的状态是较低的情况下或者这就是州()函数将报告。然而,它应该提供情况下或者因为这是一个预期的默认有效载荷MQTT二进制传感器

payload_on.
(字符串)(可选)

表示ON状态的字符串。它将与状态_topic中的消息进行比较(有关详细信息,请参阅value_template)

默认值:


编辑
您可以使用模板编辑器向您自己证明这一点。

这报告NO,因为有效负载的JSON结构不匹配模板的JSON路径。

这个报告是YES,因为有效负载的JSON结构确实匹配模板的JSON路径。然而,Sonoff RF桥不会用这种结构传输有效载荷。

作为射频信号,当2同时广播时,广播是乱码和代码不正确。我有一个PIR和门簧传感器非常接近,所以我经常打开门,门的运动触发PIR,所以我会得到乱码…