Trying to work out how to change multiple sensors based on multiple values in a JSON response and getting very confused!
My JSON is:
{“before”: {“id”: “1613547320.882099-qmp59k”, “camera”: “garage”, “frame_time”: 1613547321.042901, “label”: “motorcycle”, “top_score”: 0.71484375, “false_positive”: false, “start_time”: 1613547320.882099, “end_time”: null, “score”: 0.734375, “box”: [229, 16, 353, 142], “area”: 15624, “region”: [148, 0, 448, 300], “current_zones”: [], “entered_zones”: [], “thumbnail”: null}, “after”: {“id”: “1613547320.882099-qmp59k”, “camera”: “garage”, “frame_time”: 1613547322.047451, “label”: “motorcycle”, “top_score”: 0.71484375, “false_positive”: false, “start_time”: 1613547320.882099, “end_time”: 1613547324.140135, “score”: 0.71484375, “box”: [242, 25, 353, 131], “area”: 11766, “region”: [161, 0, 461, 300], “current_zones”: [], “entered_zones”: [], “thumbnail”: null}, “type”: “end”}
The parts I’m looking to get are “camera” and “end_time” in the before part. The camera object can be 3 different values (side, garage and front) and what I’m looking to do is have 3 different binary sensors for motion, which is determined from the “end_time” value not being null
I’ve tried reading the templating guide in the docs and tried the following:
- platform: mqtt
name: "Frigate Test"
state_topic: "frigate/events"
value_template: "{{ value_json.before }}"
json_attributes_topic: "frigate/events"
json_attributes_template: "{{ value_json.before.camera }} {{ value_json.before.end_time }}"
And various different options on the json_attributes_template (with before, without, etc), I can get the camera name, or the end_time, but I need to get both and return this to a different sensor based on the camera name.
Think I’m missing something obvious here - can anyone help?