Parsing MQTT Events in HA
Posted: Sat Jun 12, 2021 2:49 am
I already have a thread in the Home Assistant forum but I thought it might be worth asking around here as well. I am having trouble parsing the label from events. I can parse name with no issues, which at least gets me around the 255 character limit, but for some reason everything that I have found online about how to parse the label out of an MQTT notification has not worked well for me.
I tried:
value_template: "{{ value_json.detection[0].label }}"
value_template: "{{ value_json.detection[0].label }}"
json_attributes_topic: "zoneminder/1"
json_attributes_template: "{{ value_json.detection[0] }}"
and it was telling me there is no value dictionary value for 0 for label. So I look at the full error message when I send MQTT without parsing and noticed that the dictionary seems to actually be using "labels" not "label", for example:
ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on ‘zoneminder/2’: ‘{“eventtype”:“event_start”,“hookvalue”:“0”,“state”:“alarm”,“eventid”:“500”,“monitor”:“2”,“detection”:{“image_dimensions”:{“original”:[1944,2592],“resized”:[600,800]},“confidences”:[0.985492706298828,0.94365668296814],“frame_id”:“snapshot”,“boxes”:[[138,248,216,468],[504,38,546,168]],“labels”:[“person”,“person”]},“name”:“Driveway:(500) [s] detected:person:99% Linked”}’
Someone told me to try this on the HA forums:
value_template: {{ value_json.detection.labels }}
But I started getting alternating dictionary and list errors. Does anyone else have a similar setup working or have any ideas? My Google Fu is failing me.
I tried:
value_template: "{{ value_json.detection[0].label }}"
value_template: "{{ value_json.detection[0].label }}"
json_attributes_topic: "zoneminder/1"
json_attributes_template: "{{ value_json.detection[0] }}"
and it was telling me there is no value dictionary value for 0 for label. So I look at the full error message when I send MQTT without parsing and noticed that the dictionary seems to actually be using "labels" not "label", for example:
ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on ‘zoneminder/2’: ‘{“eventtype”:“event_start”,“hookvalue”:“0”,“state”:“alarm”,“eventid”:“500”,“monitor”:“2”,“detection”:{“image_dimensions”:{“original”:[1944,2592],“resized”:[600,800]},“confidences”:[0.985492706298828,0.94365668296814],“frame_id”:“snapshot”,“boxes”:[[138,248,216,468],[504,38,546,168]],“labels”:[“person”,“person”]},“name”:“Driveway:(500) [s] detected:person:99% Linked”}’
Someone told me to try this on the HA forums:
value_template: {{ value_json.detection.labels }}
But I started getting alternating dictionary and list errors. Does anyone else have a similar setup working or have any ideas? My Google Fu is failing me.