Attempting to set light brightness from input_text

Hello all,

My end goal here is to reset my hue lights back to what they were after an event happens that triggers a script… at the moment I have the following test script:

This script gets the current brightness of the light, dims it, then turns it back to whatever brightness it was originally set at. Everything works up to setting the brightness back

    test_script:
      sequence:
        - service: input_text.set_value
          data_template:
            entity_id: input_text.right_table_lamp_brightness
            value: '{{states.light.right_table_lamp.attributes.brightness}}'
        - service: light.turn_on
          entity_id: light.right_table_lamp
          data:
            brightness_pct: 30
            transition: 1.15
        - delay:
            milliseconds: 2300
        - service: light.turn_on
          entity_id: light.right_table_lamp
          data:
            brightness: '{{states.input_text.right_table_lamp_brightness.state}}'
            transition: 1.15

I cannot get "brightness: ‘{{states.input_text.right_table_lamp_brightness.state}}’ " to work I have tried many different iterations and variations of the line but I always get the same error:

Invalid service data for light.turn_on: expected int for dictionary value @ data['brightness']. Got '{{states.input_text.right_table_lamp_brightness.state}}'

What am I doing wrong here? Is there a better way to store a global variable? I feel like this should be something commonplace, but then again I am a programmer by trade.

Given that you’re storing a number, would an input_number not be better than an input_text??

Anyway, you’re passing a string to a function that requires an integer. The last-but-one line needs |int at the end of it to convert it (can’t remember off the top of my head weather it needs to be in the brackets or out, but definitely needs to be in the quotes).

Hope this helps.

1 Like

I got it solved… I just had a typo used “data” instead of “data_template” Thanks!