Sensor.webhook_temperature: UndefinedError: 'dict object' has no attribute 'temperature'

guys & gals I admit failure on this one.

I’m trying to extract a simple temp value from a json file webhook. data is coming through fine. However my webhook is failing to extract the right information from the JSON file:

{“event”:{“eventId”:“c3v8minimbf5a5g12mj0”,“targetName”:“projects/bskjodneanog00f76kf0/devices/bjeis9e7gpvg00cjoapg”,“eventType”:“temperature”,“data”:{“temperature”:{“value”:27,“updateTime”:“2021-07-26T10:15:04.644000Z”,“samples”:[{“value”:27,“sampleTime”:“2021-07-26T10:15:04.644000Z”}]}},“timestamp”:“2021-07-26T10:15:04.644000Z”},“labels”:{}}

My template is:

template:

  • trigger:
    • platform: webhook
      webhook_id: sensor_tempdt
      sensor:
    • name: “Webhook Temperature”
      state: “{{ trigger.json.temperature[‘value’] }}”
      unit_of_measurement: °C

Seems like every combination I use I can’t get the value to register. Any and all help is appreciated.

Please edit your post and format your pasted config and data as per point 11 here.

Anyway, I pasted the json data you provided into the left side of this site: https://jsonpathfinder.com/

Then I had to replace all the fancy quotes “” with straight quotes "" in a text editor and try again (because you did not format your data as above).

Then I drilled down on the right hand side to obtain this path (at the top of the right hand side column):

x.event.data.temperature.value

So you need:

state: "{{ trigger.json.event.data.temperature['value'] }}"

The value on the end has to be in square bracket notation as that word has special meaning in templates (but you already had that bit sorted).

Wow, great response and 100% fixed my problem. Some really good tips. Many thanks.