atv
(atv)
February 28, 2024, 7:46pm
1
Hi all,
So I’m using the Platerecognizer integration and it’s publishing a MQTT payload like below to what looks like a dict to me?
{
"plate_number": "CAM04",
"score": 0.9,
"frigate_event_id": "1709149025.353807-kftrt6",
"camera_name": "front_driveway_2",
"start_time": "2024-02-28 19:37:05"
}
How would I go about creating an MQTT sensor that incorporates all values?
Currently I have:
- name: "License plate"
state_topic: "frigate/platerecognizer"
value_template: "{{ plate_number }}"
#unit_of_measurement: "na"
#json_attributes_topic: "na"
icon: mdi:car
But it probably needs to be {{ json_value.plate_number }} and it also only gets that one value, whereas it would be helpful to get the other fields as well.
armedad
February 28, 2024, 8:30pm
2
i believe you need to have an entry for each value.
mqtt:
sensor:
- name: "License plate"
state_topic: "frigate/platerecognizer"
value_template: "{{ json.plate_number }}"
- name: "camera"
state_topic: "frigate/platerecognizer"
value_template: "{{ json.camera_name }}"
etc…
yes, this does risk race conditions where they can get mismatches.
typcially if you need them in sync, trigger off the mqtt trigger directly and use the data in the trigger event instead of reading the sensor.
if someone else knows a better way, i’d be interested too…
1 Like
VDRainer
(🍻)
February 28, 2024, 8:51pm
3
Something like this should work.
sensor:
- name: ems_esp_thermostat
state_topic: "ems-esp/thermostat_data"
value_template: "{{ value_json.hc2.mode }}"
json_attributes_topic: "ems-esp/thermostat_data"
One value of the json data will be the state of the sensor.
The other values will be attributes.
atv
(atv)
February 28, 2024, 9:01pm
4
Cool.
So the value_json.hc2.mode, what does the hc2.mode signify ?
In my case can I then just use value_json.plate_number ?
atv
(atv)
February 28, 2024, 9:02pm
5
Ah yes I forgot about Mqtt triggers. I might mess around with that. Ideally I do want to keep them synced up and make a history sensor out of it. Thanks.
VDRainer
(🍻)
February 28, 2024, 9:10pm
6
It’s just an example.
value_template: "{{ value_json.plate_number }}"
should work for you.
1 Like
armedad
February 28, 2024, 9:14pm
7
ah nice. learned something! thanks!
1 Like