MQTT发现
MQTT设备的发现将使人们能够在家庭助理侧面使用最小配置工作的MQTT设备。必威是什么配置是在设备本身和设备使用的主题上完成的。类似于HTTP二进制传感器和HTTP传感器。为了防止多个相同的条目,如果设备重新连接,则必须使用唯一的标识符。设备侧需要两个部分:配置主题,其中包含必要的设备类型和唯一标识符,以及没有设备类型的剩余设备配置。
由MQTT Discovery支持:
配置
默认情况下启用了MQTT Discovery,但可以禁用。为此,请单击UI集成页面中的“配置”,然后单击“重新配置MQTT”,然后再进行“下一个”。
高级发现配置
可以通过配置发现主题的前缀configuration.yaml
。
发现主题
发现主题需要遵循特定格式:
//[/] /config
:一个支持的MQTT组件之一,例如。binary_sensor
。
((选修的):提供该主题的节点的ID,这不是由家庭助手使用,而是用于构建MQTT主题。必威是什么节点的ID必须仅由字符类中的字符组成[A-ZA-Z0-9_-]
(Alphanumerics,下划线和连字符)。
:设备的ID。这只是为每个设备提供单独的主题,并且不适用于ENTITY_ID
。设备的ID必须仅由字符类中的字符组成[A-ZA-Z0-9_-]
(Alphanumerics,下划线和连字符)。
具有一个具有的实体的最佳实践唯一身份
是设置
到唯一身份
并省略
。
有效载荷必须是JSON词典,并且将像您的条目一样检查configuration.yaml
文件如果添加了新设备。这意味着丢失的变量将被平台的默认值填充。所有配置变量必需的必须在初始有效载荷发送到/config
。
将收到有效有效负载的主题上的后续消息作为配置更新处理,并且带有空有效负载的配置更新将导致删除先前发现的设备。
这
客户只能使用一个通配符主题来订阅自己的(命令)主题
。
一个基本主题〜
可以在有效载荷中定义以节省内存时,当多次使用同一主题基础时。以结尾的配置变量的值_话题
,,,,〜
如果是〜
发生在值的开头或结尾。
发现有效载荷中的配置变量名称可以缩写以节省内存,从内存约束设备发送发现消息时。
支持的缩写:
'act_t':'action_topic','act_tpl':'action_template','atype':'automation_type','aux_cmd_t':'':'able_tones','avty''availability','avty_mode':'availability_mode','avty_t':'availability_topic','avty_tpl':'availability_template','over_mode_mode_mode_cmd_t':'over_mode_state_template','over_mode_stat_t':'over_mode_state_topic','b_tpll':'blue_template','bri_cmd_t':'bri_command_command_topic',', 'bri_tpl': 'brightness_template', 'bri_val_tpl': 'brightness_value_template', 'clr_temp_cmd_tpl': 'color_temp_command_template', 'bat_lev_t': 'battery_level_topic', 'bat_lev_tpl': 'battery_level_template', 'chrg_t': 'charging_topic', 'chrg_tpl':'charging_template','clr_temp_cmd_t':'color_temp_command_topic','clr_temp_stat_t':'color_temp_state_topic', 'clr_temp_tpl': 'color_temp_template', 'clr_temp_val_tpl': 'color_temp_value_template', 'cln_t': 'cleaning_topic', 'cln_tpl': 'cleaning_template', 'cmd_off_tpl': 'command_off_template', 'cmd_on_tpl': 'command_on_template', 'cmd_t': 'command_topic', 'cmd_tpl': 'command_template', 'cod_arm_req': 'code_arm_required', 'cod_dis_req': 'code_disarm_required', 'cod_trig_req': 'code_trigger_required', 'curr_temp_t': 'current_temperature_topic', 'curr_temp_tpl': 'current_temperature_template', 'dev': 'device', 'dev_cla': 'device_class', 'dock_t': 'docked_topic', 'dock_tpl': 'docked_template', 'e': 'encoding', 'ent_cat': 'entity_category, 'err_t': 'error_topic', 'err_tpl': 'error_template', 'fanspd_t': 'fan_speed_topic', 'fanspd_tpl': 'fan_speed_template', 'fanspd_lst': 'fan_speed_list', 'flsh_tlng': 'flash_time_long', 'flsh_tsht': 'flash_time_short', 'fx_cmd_t': 'effect_command_topic', 'fx_cmd_tpl': 'effect_command_template', 'fx_list': 'effect_list', 'fx_stat_t': 'effect_state_topic', 'fx_tpl': 'effect_template', 'fx_val_tpl': 'effect_value_template', 'exp_aft': 'expire_after', 'fan_mode_cmd_tpl': 'fan_mode_command_template', 'fan_mode_cmd_t': 'fan_mode_command_topic', 'fan_mode_stat_tpl': 'fan_mode_state_template', 'fan_mode_stat_t': 'fan_mode_state_topic', 'frc_upd': 'force_update', 'g_tpl': 'green_template', 'hold_cmd_tpl': 'hold_command_template', 'hold_cmd_t': 'hold_command_topic', 'hold_stat_tpl': 'hold_state_template', 'hold_stat_t': 'hold_state_topic', 'hs_cmd_t': 'hs_command_topic', 'hs_stat_t': 'hs_state_topic', 'hs_val_tpl': 'hs_value_template', 'ic': 'icon', 'init': 'initial', 'hum_cmd_t': 'target_humidity_command_topic', 'hum_cmd_tpl': 'target_humidity_command_template', 'hum_stat_t': 'target_humidity_state_topic', 'hum_stat_tpl': 'target_humidity_state_template', 'json_attr': 'json_attributes', 'json_attr_t': 'json_attributes_topic', 'json_attr_tpl': 'json_attributes_template', 'max_mirs': 'max_mireds', 'min_mirs': 'min_mireds', 'max_temp': 'max_temp', 'min_temp': 'min_temp', 'max_hum': 'max_humidity', 'min_hum': 'min_humidity', 'mode_cmd_tpl': 'mode_command_template', 'mode_cmd_t': 'mode_command_topic', 'mode_stat_tpl': 'mode_state_template', 'mode_stat_t': 'mode_state_topic', 'modes': 'modes', 'name': 'name', 'obj_id': 'object_id', 'off_dly': 'off_delay', 'on_cmd_type': 'on_command_type', 'opt': 'optimistic', 'osc_cmd_t': 'oscillation_command_topic', 'osc_cmd_tpl': 'oscillation_command_template', 'osc_stat_t': 'oscillation_state_topic', 'osc_val_tpl': 'oscillation_value_template', 'pct_cmd_t': 'percentage_command_topic', 'pct_cmd_tpl': 'percentage_command_template', 'pct_stat_t': 'percentage_state_topic', 'pct_val_tpl': 'percentage_value_template', 'pl': 'payload', 'pl_arm_away': 'payload_arm_away', 'pl_arm_home': 'payload_arm_home', 'pl_arm_custom_b': 'payload_arm_custom_bypass', 'pl_arm_nite': 'payload_arm_night', 'pl_avail': 'payload_available', 'pl_cln_sp': 'payload_clean_spot', 'pl_cls': 'payload_close', 'pl_disarm': 'payload_disarm', 'pl_home': 'payload_home', 'pl_lock': 'payload_lock', 'pl_loc': 'payload_locate', 'pl_not_avail': 'payload_not_available', 'pl_not_home': 'payload_not_home', 'pl_off': 'payload_off', 'pl_on': 'payload_on', 'pl_open': 'payload_open', 'pl_osc_off': 'payload_oscillation_off', 'pl_osc_on': 'payload_oscillation_on', 'pl_paus': 'payload_pause', 'pl_stop': 'payload_stop', 'pl_strt': 'payload_start', 'pl_stpa': 'payload_start_pause', 'pl_ret': 'payload_return_to_base', 'pl_rst_hum': 'payload_reset_humidity', 'pl_rst_mode': 'payload_reset_mode', 'pl_rst_pct': 'payload_reset_percentage', 'pl_rst_pr_mode': 'payload_reset_preset_mode', 'pl_toff': 'payload_turn_off', 'pl_ton': 'payload_turn_on', 'pl_trig': 'payload_trigger', 'pl_unlk': 'payload_unlock', 'pos_clsd': 'position_closed', 'pos_open': 'position_open', 'pow_cmd_t': 'power_command_topic', 'pow_stat_t': 'power_state_topic', 'pow_stat_tpl': 'power_state_template', 'pr_mode_cmd_t': 'preset_mode_command_topic', 'pr_mode_cmd_tpl': 'preset_mode_command_template', 'pr_mode_stat_t': 'preset_mode_state_topic', 'pr_mode_val_tpl': 'preset_mode_value_template', 'pr_modes': 'preset_modes', 'r_tpl': 'red_template', 'ret': 'retain', 'rgb_cmd_tpl': 'rgb_command_template', 'rgb_cmd_t': 'rgb_command_topic', 'rgb_stat_t': 'rgb_state_topic', 'rgb_val_tpl': 'rgb_value_template', 'send_cmd_t': 'send_command_topic', 'send_if_off': 'send_if_off', 'set_fan_spd_t': 'set_fan_speed_topic', 'set_pos_tpl': 'set_position_template', 'set_pos_t': 'set_position_topic', 'pos_t': 'position_topic', 'pos_tpl': 'position_template', 'spd_rng_min': 'speed_range_min', 'spd_rng_max': 'speed_range_max', 'src_type': 'source_type', 'stat_cla': 'state_class', 'stat_clsd': 'state_closed', 'stat_closing': 'state_closing', 'stat_off': 'state_off', 'stat_on': 'state_on', 'stat_open': 'state_open', 'stat_opening': 'state_opening', 'stat_stopped': 'state_stopped', 'stat_locked': 'state_locked', 'stat_unlocked': 'state_unlocked', 'stat_t': 'state_topic', 'stat_tpl': 'state_template', 'stat_val_tpl': 'state_value_template', 'stype': 'subtype', 'sup_duration': 'support_duration', 'sup_vol': 'support_volume_set', 'sup_feat': 'supported_features', 'sup_off': 'supported_turn_off', 'swing_mode_cmd_tpl': 'swing_mode_command_template', 'swing_mode_cmd_t': 'swing_mode_command_topic', 'swing_mode_stat_tpl': 'swing_mode_state_template', 'swing_mode_stat_t': 'swing_mode_state_topic', 'temp_cmd_tpl': 'temperature_command_template', 'temp_cmd_t': 'temperature_command_topic', 'temp_hi_cmd_tpl': 'temperature_high_command_template', 'temp_hi_cmd_t': 'temperature_high_command_topic', 'temp_hi_stat_tpl': 'temperature_high_state_template', 'temp_hi_stat_t': 'temperature_high_state_topic', 'temp_lo_cmd_tpl': 'temperature_low_command_template', 'temp_lo_cmd_t': 'temperature_low_command_topic', 'temp_lo_stat_tpl': 'temperature_low_state_template', 'temp_lo_stat_t': 'temperature_low_state_topic', 'temp_stat_tpl': 'temperature_state_template', 'temp_stat_t': 'temperature_state_topic', 'temp_unit': 'temperature_unit', 'tilt_clsd_val': 'tilt_closed_value', 'tilt_cmd_t': 'tilt_command_topic', 'tilt_cmd_tpl': 'tilt_command_template', 'tilt_inv_stat': 'tilt_invert_state', 'tilt_max': 'tilt_max', 'tilt_min': 'tilt_min', 'tilt_opnd_val': 'tilt_opened_value', 'tilt_opt': 'tilt_optimistic', 'tilt_status_t': 'tilt_status_topic', 'tilt_status_tpl': 'tilt_status_template', 't': 'topic', 'uniq_id': 'unique_id', 'unit_of_meas': 'unit_of_measurement', 'val_tpl': 'value_template', 'whit_val_cmd_t': 'white_value_command_topic', 'whit_val_scl': 'white_value_scale', 'whit_val_stat_t': 'white_value_state_topic', 'whit_val_tpl': 'white_value_template', 'xy_cmd_t': 'xy_command_topic', 'xy_stat_t': 'xy_state_topic', 'xy_val_tpl': 'xy_value_template',
设备注册表配置的支持缩写:
'cu':'configuration_url''cns':'connections','ids':'diendenifiers','name':'name','name','name','mf':'Manufacturer','mdl':'mdl':'Model','sw'':'sw_version','sa':'supsed_area',
第三方工具的支持
以下软件对MQTT发现具有内置支持:
- Arilux al-LC0X LED控制器
- ebusd
- Ecowitt2MQTT
- 怪物
- Espurna
- 哈斯
- iotlink(从2.0.0开始)
- Miflora MQTT守护程序
- OpenMQTTGATEWAY
- 房间辅助(从1.1.0开始)
- 聪明
- tasmota(从5.11.1e开始,开发停止)
- teleinfo mqtt(从3.0.0开始)
- TYDOM2MQTT
- 什么是码头工人?(从3.5.0开始)
- Wyzesense2MQTT
- 小米达法黑客
- Zigbee2MQTT
- Zwave2MQTT(从2.0.1开始)
例子
运动检测(二进制传感器)
一个可以由A表示的运动检测设备二进制传感器对于您的花园,将其配置作为JSON有效载荷发送到配置主题。在第一条消息到config
,然后发送到状态主题的MQTT消息将在家庭助理中更新州。必威是什么
- 配置主题:
乡亲/binary_sensor/garden/config
- 国家主题:
乡亲/binary_sensor/garden/state
- 有效载荷:
{“ name”:“ garden”,“ device_class”:“运动”,“ state_topic”:“ homeassistant/binary_sensor/garden/state”}
- 保留:添加-R开关以保留经纪人中的配置主题。没有此,在家庭助理重新启动后,传感器将无法使用。必威是什么
手动创建新的传感器。
Mosquitto_pub-r-H127.0.0.1-p1883年-t“乡亲/binary_sensor/garden/config”-m'{“ name”:“ garden”,“ device_class”:“运动”,“ state_topic”:“ homeassistant/binary_sensor/garden/state”}'}'
更新状态。
Mosquitto_pub-H127.0.0.1-p1883年-t“乡亲/binary_sensor/garden/state”-m在
通过发送空消息来删除传感器。
Mosquitto_pub-H127.0.0.1-p1883年-t“乡亲/binary_sensor/garden/config”-m''
有关更多详细信息,请参考MQTT测试部分。
具有多个值的传感器
设置具有多个测量值的传感器需要多个连续的配置主题提交。
- 配置主题No1:
乡亲/传感器/传感器室/配置
- 配置有效载荷No1:
{“ device_class”:“温度”,“名称”:“温度”,“ state_topic”:“ homeassistant/senser/sensorbed room/state”,“ unit_of_measurement”:“°C”,“ value_template”}}“}}
- 配置主题NO2:
乡亲/传感器/传感器室/config
- 配置有效载荷NO2:
{“ device_class”:“湿度”,“名称”:“湿度”,“ state_topic”:“ homeassistant/sensor/sensor/sensorbedroom/state/state”,“ unit_of_measurement”:“%”,“ value_template”}“}}
- 普通州有效载荷:
{“温度”:23.20,“湿度”:43.70}
开关
设置开关相似,但需要一个command_topic
如MQTT开关文档。
- 配置主题:
乡亲/开关/灌溉/配置
- 国家主题:
乡亲/开关/灌溉/状态
- 命令主题:
乡亲/开关/灌溉/套装
- 有效载荷:
{“ name”:“ garden”,“ command_topic”:“ homeassistant/switch/inrigation/set”,“ state_topic”:“ homeassistant/switch/switch/inrigation/state”}
- 保留:添加-R开关以保留经纪人中的配置主题。没有此,在家庭助理重新启动后,传感器将无法使用。必威是什么
Mosquitto_pub-r-H127.0.0.1-p1883年-t“乡亲/开关/灌溉/配置”\ \-m'{“ name”:“ garden”,“ command_topic”:“ homeassistant/switch/inrigation/set”,“ state_topic”:“ homeassistant/switch/switch/inrigation/state”}'
设置状态。
Mosquitto_pub-H127.0.0.1-p1883年-t“乡亲/开关/灌溉/设置”-m在
缩写主题名称
使用主题前缀和缩写配置变量名称设置开关,以减少有效载荷长度。
- 配置主题:
乡亲/开关/灌溉/配置
- 命令主题:
乡亲/开关/灌溉/套装
- 国家主题:
乡亲/开关/灌溉/状态
- 配置有效载荷:
{“〜”:“ homeassistant/switch/灌溉”,“名称”:“ garden”,“ cmd_t”:“〜/set”,“ stat_t”:“〜/state”}
灯光
设置一个带有JSON有效载荷的光,带有缩写配置变量名称:
配置主题:
乡亲/轻/厨房/配置
命令主题:
乡亲/轻/厨房/套装
国家主题:
乡亲/轻/厨房/州
示例状态有效载荷:
{“ state”:“ on”,“亮度”:255}
配置有效载荷:
{“〜”:“乡亲/轻/厨房”,,,,“姓名”:“厨房”,,,,“唯一身份”:“ Kitchen_light”,,,,“ cmd_t”:“〜/设置”,,,,“ stat_t”:“〜/状态”,,,,“模式”:“ JSON”,,,,“亮度”:真的}
气候控制
建立气候整合(仅热):
- 配置主题:
乡亲/气候/客厅/配置
- 配置有效载荷:
{“姓名”:“客厅”,,,,“ mode_cmd_t”:“乡亲/气候/客厅/恒温器”,,,,“ mode_stat_t”:“乡亲/气候/客厅/州”,,,,“ mode_stat_tpl”:“”,,,,“ avty_t”:“乡亲/气候/客厅/可用”,,,,“ pl_avail”:“在线的”,,,,“ pl_not_avail”:“离线”,,,,“ temp_cmd_t”:“乡亲/气候/客厅/targettempcmd”,,,,“ temp_stat_t”:“乡亲/气候/客厅/州”,,,,“ temp_stat_tpl”:“”,,,,“ curr_temp_t”:“乡亲/气候/客厅/州”,,,,“ curr_temp_tpl”:“”,,,,“ min_temp”:“ 15”,,,,“ max_temp”:“ 25”,,,,“ temp_step”:“ 0.5”,,,,“模式”:[[“离开”,,,,“热”这是给予的}
- 国家主题:
乡亲/气候/客厅/州
- 州有效载荷:
{“模式”:“离开”,,,,“ target_temp”:“ 21.50”,,,,“ Current_Temp”:“ 23.60”}
存在检测(设备跟踪器)
设置设备跟踪器:
- 配置主题:
homeassistant/device_tracker/paulus/config
- 示例配置有效载荷:
{“姓名”:“保罗”,,,,“ state_topic”:“乡亲/device_tracker/paulus/state”,,,,“ payload_home”:“家”,,,,“ PAYLOAD_NOT_HOME”:“不在家”,,,,“ source_type”:“蓝牙”}
- 国家主题:
乡亲/device_tracker/paulus/state
- 示例状态有效载荷:
家
或者不在家
或者地点名称
如果设备支持GPS坐标,则可以通过指定属性主题(即“ JSON_ATTRIBUTES_TOPIC”)将它们发送到家庭助理:必威是什么
- 属性主题:
homeassistant/device_tracker/paulus/属性
- 示例属性有效载荷:
{“纬度”:32.87336,,,,“经度”:-117.22743,,,,“ gps_accuracy”:1.2}
使用object_id影响实体ID
实体ID是从实体名称自动生成的。所有MQTT实体组件都可以选择支持提供object_id
如果提供,将使用它。
- 配置主题:
乡亲/传感器/设备1/config
- 示例配置有效载荷:
{“姓名”:“我的超级设备”,,,,“ object_id”:“设备1”,,,,“ state_topic”:“乡亲/传感器/设备1/状态”}
在上面的示例中,Entity_id将是传感器.Device1
代替Sensor.my_super_device
。