I’m new to templating and have been playing around with setting up a MQTT sensor to store when zigbee2mqtt is updating a device and show the messages output in lovelace.
This is a mqtt message example:
topic 'zigbee2mqtt/bridge/log', payload '{"type":"ota_update","message":"Update of 'Remote Kitchen' at 0.36%, +- 196 minutes remaining","meta":{"status":"update_progress","device":"Remote Kitchen","progress":0.36}}'
This is what I have for a sensor:
- platform: mqtt
name: Zigbee Bridge Update Log
state_topic: "zigbee2mqtt/bridge/log"
icon: mdi:message-alert-outline
value_template: "{{ value_json.type }}: {{ value_json.message }}"
This just displays all messages from the topic with “type: message” I want to be able to filter out only “type”:“ota_update” but not sure how to do that with the sensor?
I need to do this to display only ota update related log messages and also I’m getting errors in the HA log due to a really long MQTT message on the same topic showing all devices and their status:
Exception in message_received when handling msg on 'zigbee2mqtt/bridge/log': '{"type":"devices","message":[LONG_MESSAGE]}' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper msg_callback(msg) File "/usr/src/homeassistant/homeassistant/components/mqtt/sensor.py", line 165, in message_received self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 290, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 403, in _async_write_ha_state self.entity_id, state, attr, self.force_update, self._context File "/usr/src/homeassistant/homeassistant/core.py", line 1007, in async_set state = State(entity_id, new_state, attributes, last_changed, None, context) File "/usr/src/homeassistant/homeassistant/core.py", line 755, in __init__ f"Invalid state encountered for entity id: {entity_id}. " homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.zigbee_bridge_update_log. State max length is 255 characters.