Scripting using variable

Hi,

Im trying using a number helpers to set my bulb luminosity value from 0 to 100.
I created a input_number.luminosity and put it in my automation like this:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.hallway_detection_zone_east
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: '{{ states("input_number.hallway_luminosity_value") }}'
    target:
      entity_id:
        - light.hallway_light_east
mode: single

I also tried other different way to type it but It cant be detected. How do I put the value from that variable into the brightness_pct correctly?
Thank you

wait… is your input_number called input_number.luminosity? if so, try this?

trigger:
  - platform: state
    entity_id:
      - binary_sensor.hallway_detection_zone_east
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: |
        {{ states('input_number.luminosity') }}
    target:
      entity_id:
        - light.hallway_light_east
mode: single

Whats the point of the | symbol?
I tried ur solution without the | symbol and it doesnt work. Using the | also doesnt work, I get “brightness_pct” need a float value

huh… try casting to a float?

In this particular case the | doesn’t do a ton… It does force it into template mode. if you don’t have the | and you put it on the same line, you will need to quote it to indicate it is a template, not a string. And you then need to double quote the quotes or be sure to use " instead of ’ to wrap the line… I avoid it all by using the | and putting the template on it’s own line

trigger:
  - platform: state
    entity_id:
      - binary_sensor.hallway_detection_zone_east
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: |
        {{ states('input_number.luminosity') | float }}
    target:
      entity_id:
        - light.hallway_light_east
mode: single

If you continue to get an error, could you please post the code verbatim that gives you the float error.

don’t brother posting the code without the |

So I can try to make it work in template modded andd then copy paste easily. DIdnt know that.
Ended up with this:

brightness_pct: "{{ states('input_number.luminosity') | int }}"

and even if it is an INT it works as well. Thank you so much

awesome. glad you got it working! yes, the template modeling tool is a great way to work things out!! the services tab of dev tools is also very useful. you can test the action call and fiddle with it more quickly!