Jinja template OK, Logger message won't work?

I am receiving an update on light status from another system which I can see in logger as a first step to setting the entity state in HASS. I cannot workout why the template works OK, but the logger doesn’t - any ideas? TIA

The bare message is logged ok

service: system_log.write
data:
  message: '{{ trigger.json }}'
  level: info

results

    message:
      Cortex_HAAPI:
        Light: Family Room Star
        State: |
          Family Room Star - On, Override : Temporary on + presence.
    level: info

Using the Dev Tools Template

{% set my_test_json = {
  "Cortex_HAAPI":{
   "Light": "Family Room Star", 
   "State":  "|
          Family Room Star On, Override : Temporary on + presence." 
    }
  }
%}
{{ my_test_json.Cortex_HAAPI.Light  }}: {%  
  if "On" in my_test_json.Cortex_HAAPI.State %}On  {% else %}Off {% endif -%}

gives the result:
Family Room Star: On

All Good :slight_smile:

However when I move this into an automation (first step to log the result in a likely usable format)

- alias: cortex light state
  description: "update light status on webhook message"
  trigger:
    - platform: webhook
      webhook_id: cortex-light-state
  action:
    service: system_log.write
    data:
      #      timestamp:
      #      name: homeassistant.webhook.cortex-light-state
      message: "{{ trigger.Cortex_HAAPI.Light }}: {%  
      if 'On' in trigger.Cortex_HAAPI.State %}On  {% else %}Off {% endif -%}"
      level: info

The logger reports

Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'Cortex_HAAPI'

What have I got wrong??

According to the documentation for a Webhook Trigger, if the received data is in JSON then the variable to access it is trigger.json.

Based on that information, use:

trigger.json.Cortex_HAAPI.Light
trigger.json.Cortex_HAAPI.State
1 Like

Awesome thank you very much.
:smiley:

1 Like