MQTT event filter value template

I’m trying for days to get a “wait for trigger” action right to monitor for 2 specific values in an MQTT message.

'{"before": {"id": "1634213158.895165-hqxs41", "camera": "CAM1_Voor",
      "frame_time": 1634213159.894722, "snapshot_time": 1634213159.894722,
      "label": "person", "top_score": 0.701171875, "false_positive": false,
      "start_time": 1634213158.895165, "end_time": null, "score": 0.75390625,
      "box": [579, 347, 722, 572], "area": 32175, "region": [482, 276, 782,
      576], "current_zones": [], "entered_zones": [], "has_clip": false,
      "has_snapshot": false}, "after": {"id": "1634213158.895165-hqxs41",
      "camera": "CAM1_Voor", "frame_time": 1634213164.894735, "snapshot_time":
      1634213160.49555, "label": "person", "top_score": 0.818359375,
      "false_positive": false, "start_time": 1634213158.895165, "end_time":
      null, "score": 0.796875, "box": [862, 243, 967, 436], "area": 20265,
      "region": [724, 188, 1024, 488], "current_zones": [], "entered_zones": [],
      "has_clip": false, "has_snapshot": false}, "type": "update"}

The automation is first triggered by any message containing CAM1_Voor, this works.
A variable is used to capture the ID of this message.

  id: '{{ trigger.payload_json[''after''][''id''] }}'

(This works also)

Next, I want to send the snapshot to telegram as soon as it is ready, in the message above it’s not ready yet (has_snapshot: false). I’m trying to setup a “wait for tigger” where the MQTT message has the same ID as stored in the variable {{ id }} AND the value has_snapshot=true.

platform: mqtt
topic: frigate/events
payload: ‘{{ id }}’
value_template: ‘{{ value_json[‘after’][‘id’] and value_json[‘after’][‘has_snapshot’]==true }}’

Tried many variation but it won’t work. What am I missing here?

Nobody? It really drives me crazy as it seems not that difficult…

Your value template is incorrect. You’re using the same inside quotes as outside quotes.

Next, you dont need the == true.

value_template: "{{ and value_json.after.has_snapshot }}"

Also, if this is an event stream then you should really use the new template integration and use an MQTT trigger that populates the sensor with information when it’s present.

Thanks a lot petro!! This actually worked at first attempt :D:D

Can you show nodes?