diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 91f62cd0848..f680cd9c136 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -202,10 +202,11 @@ async def async_start(hass: HomeAssistantType, discovery_topic, hass_config, if TOPIC_BASE in payload: base = payload[TOPIC_BASE] for key, value in payload.items(): - if value[0] == TOPIC_BASE and key.endswith('_topic'): - payload[key] = "{}{}".format(base, value[1:]) - if value[-1] == TOPIC_BASE and key.endswith('_topic'): - payload[key] = "{}{}".format(value[:-1], base) + if isinstance(value, str): + if value[0] == TOPIC_BASE and key.endswith('_topic'): + payload[key] = "{}{}".format(base, value[1:]) + if value[-1] == TOPIC_BASE and key.endswith('_topic'): + payload[key] = "{}{}".format(value[:-1], base) # If present, the node_id will be included in the discovered object id discovery_id = '_'.join((node_id, object_id)) if node_id else object_id