Brightness issue with int in automation

Hello, I want to set brightness (and colors, but the issue is the same) from variables. For example I have variable configured: bedroom_lights_color_bright.

I’m doing this:

data:
  brightness: '{{ states(''input_number.bedroom_lights_color_bright'') | int }}'
  rgb_color:
    - 0
    - 0
    - 255
entity_id: light.bedroom
service: light.turn_on

It will fail with message:

BedroomWallSwitchToggle: Error executing script. Invalid data for call_service at pos 1: expected int for dictionary value @ data['brightness']

state is correct. For instance this (to test) sends correct value (eg: “test 123”):

data:
  message: 'test {{states(''input_number.bedroom_lights_color_bright'') | string}}'
service: telegram_bot.send_message

I’ve read most a lot of threads and examples. Besides in https://www.home-assistant.io/integrations/input_number/
example says:

data:
          entity_id: light.bedroom
          brightness: "{{ states('input_number.bedroom_brightness') | int }}"

I’ve tried different quotes, with and whiteout them.

Eg: doing like this

data:
  brightness: {{ states(''input_number.bedroom_lights_color_bright'') | int }}

will be saved as:

brightness:
  '[object Object]': null

What am I missing? Obviously something simple.

I would suggest double quotes around the value template. And single quotes inside. Just like the example from the docs.

Which version of Home Assistant are you using?

In all versions prior to 0.116, you must use data_template: if the option contains a template.

data_template:
  brightness: "{{ states('input_number.bedroom_lights_color_bright') | int }}"
  rgb_color:
    - 0
    - 0
    - 255
entity_id: light.bedroom
service: light.turn_on

If you are using 0.116+, then it’s no longer necessary to use data_template: and data: will work properly in all cases.

Thank you @123 this was the case. I’m using docker latest image or HA and it is in fact 0.107.5 (re-pulled today). With data_template it works as supposed.

@Emphyrio I used double quotes but UI replaces them on save. Thank you for proposition, but data_template is the answer.

1 Like