Adjusting light brightness/temperature

I am new to HA template, I want to set an automation to increase/decrease light brightness and temperature on trigger. However, when I test the below action in development/service page, the code is not working.
I can only update the light by put a static value to the brightness/color_temp attribute, but not a template. Any advise on how to inc/dec light brightness/temperature?

I am using HA version 2022.5. Thanks!

service: light.turn_on
data_template:
  transition: 1
# the templates statement below is not working
  brightness: {{ state_attr('light.livingroom_tv_lightbulbs','brightness')|int + 10 }}
  color_temp: {{ state_attr('light.livingroom_tv_lightbulbs','color_temp')|int + 10 }}
# replace to below code will work
#  brightness: 50
#  color_temp: 100
target:
  entity_id: light.livingroom_tv_lightbulbs

You no longer need to use data_template, just data will do.

You need to quote single line templates.

service: light.turn_on
target:
  entity_id: light.livingroom_tv_lightbulbs
data:
  transition: 1
  brightness: "{{ state_attr('light.livingroom_tv_lightbulbs','brightness')|int(128) + 10 }}"
  color_temp: "{{ state_attr('light.livingroom_tv_lightbulbs','color_temp')|int(6000) + 10 }}"

You should also supply default values for your |int filters in case the entities return a non numeric value. In this case I have chosen 50% brightness (128/255) and cool white for the color temp. Feel free to change them to whatever you want.

You also need to guard against the brightness value exceeding 255, e.g.

 {{ [state_attr('light.livingroom_tv_lightbulbs','brightness')|int(128) + 10, 255]|min }}

You should also do this for your color temp, but I don’t know what the maximum for your light is.

Thanks for your kind description about the default value and min operation. It is very useful for me to enhance my scripts.
However, I found the templates for lighting control is still not working, as the service call on template attributes will not do anything.
I can show the template values in Development page as attached, But whenever I put it into data part of the light_on service call, it will do nothing. Seems the light-on service call just ignored the template attributes.

Please post your action, now that you have edited it.

Oh, I’ve missed double quote for the template. It works after I double quote for the template part in the script.
Thank you again for kind help!

No problem. Yeah if you don’t use different types of quotes you end up with this:

brightness: '{{ state_attr('

Also 250 seems a very low default colour temp. Are you sure your light supports this?

Yup, I found the light (Aqara light bulb) only support color temperate range from 153 to 370. So I use 250 as default value.

Oh right. I keep forgetting that color_temp is in mireds. It’s the kelvin attribute that is 2700° to 6000°.