Display light attributes in log

Simple question here. How do I display the current state a light attribute in a log message?
Here’s what I’ve got.

message: '{{ light.hue_color_nightstand.attributes.hs_color }}'
level: info

and here’s the output I get in my log file

2020-10-25 20:01:43 INFO (MainThread) [homeassistant.components.system_log.external] {{ light.hue_color_nightstand.attributes.hs_color }}

Running this same thing from a python script yields much better results

hs = hass.states.get('light.hue_color_nightstand').attributes['hs_color']
logger.info("Nightstand HS State: %s", hs)

with the following results

2020-10-25 20:05:39 INFO (SyncWorker_16) [homeassistant.components.python_script.hello_world.py] Nightstand HS State: (14.93, 83.529)

Any help would be appreciated.
Thanks

message: "Nightstand HS State: {{ state_attr('light.hue_color_nightstand', 'hs_color' }}"

Thanks for the reply. Unfortunately this doesn’t work. Here’s the output.

2020-10-25 23:50:09 ERROR (MainThread) [homeassistant.components.system_log.external] Nightstand HS State: {{ state_attr('light.hue_color_nightstand', 'hs_color' }}

I thought, “maybe I have a typo in the Entity ID”, I copied and pasted it right from the “Entity ID” field of the light.

Do you want this message to appear in the logbook or the home assistant system log?

Logbook:

  - service: logbook.log
    data:
      name: 'Nightstand HS State'
      message: "{{ state_attr('light.hue_color_nightstand', 'hs_color' }}"

System log:

I don’t think there is a service for this exposed to automations.

Also note that hs_color will probably not be exposed as an attribute unless the light is on.

Hey tom_I,
I’m not picky with where the data is logged. I just want to see it.
Your code sample above worked great after I added the missing “)”.
Thanks!

Not totally sure why I can’t migrate that same message string over to the system_log.write service. When I do, I just get the string output exactly as it went in. Both cases with their respective results below.

name: 'Nightstand HS State'
message: "{{ state_attr('light.hue_color_nightstand', 'hs_color') }}"

#### LOGBOOK RESULT ####
Nightstand HS State (39.818, 43.137)

And the system log version that doesn’t work

message: "{{ state_attr('light.hue_color_nightstand', 'hs_color') }}"

#### SYSTEM LOG RESULT ####
2020-10-26 17:06:31 ERROR (MainThread) [homeassistant.components.system_log.external] {{ state_attr('light.hue_color_nightstand', 'hs_color') }}