Using value of helper to set brightness of light in a scene

Very new to Home Assistant. I’ve been learning a lot from the forums and docs, but I can’t seem to find the answer to this query.

- name: Dim Morning, Main Area
  icon: "mdi:lightbulb-group"
  entities:
    light.living_room_pot_lights:
      state: "on"
      brightness: '{{ input_number.default_dimmer_3.dim.state | int }}'
    switch.living_room_sconces: "off"
    switch.living_room_chandelier: "off"
    switch.living_room_accent_lights: "on"
    switch.entrance_lights: "off"

I am trying to use the value of an input_number to set the value of the brightness in a scene. The scene is working, other than the brightness part. This is what I’ve cobbled together from a few other topics, but something is still missing. Thanks for your help.

For brightness try:

"{{ states('input_number.default_dimmer_3.dim') | int }}"

Scenes don’t support templates.

You may wish to consider using a script.

Thanks @Gnat54. I’ll give that a try.

Thanks @123, I’ll look into that. Could I trouble you to give me an example of what you mean to get me started?

The assumption here is that your input_number, representing brightness, is a number between 0 and 255. If it’s a number between 0 and 100 then change brightness to brightness_pct in the script below.

dim_morning_main_area:
  alias: Dim Morning Main Area
  icon: "mdi:lightbulb-group"
  mode: single
  sequence:
    - service: light.turn_on
      target:
        entity_id: light.living_room_pot_lights
      data:
        brightness: "{{ states('input_number.default_dimmer_3') }}"
    - service: switch.turn_on
      target:
        entity_id: switch.living_room_accent_lights
    - service: switch.turn_off
      target:
        entity_id:
          - switch.living_room_sconces
          - switch.living_room_chandelier
          - switch.entrance_lights

References:
Scripts
Script Syntax

Ah! I see what you mean. Scrap scenes altogether and input each of the steps into a script, then just call the script.

Thank you, that is very helpful. I will try that.

If I may bug you one more time, I am using brightness_pct, but it is asking for a float. I have tried to change it to "{{ states('input_number.default_dimmer_3') | float }}" as per the example above where it was converted to an int, but that doesn’t seem to work either.

The pot lights never actually turn on. All the other switches are responding as expected.

The template shouldn’t require a filter to convert the input_number’s value to float (or int) because Home Assistant’s native typing feature will interpret the value correctly. However it will fail if the input_number’s entity_id is incorrect. Double check the entity_id’s spelling.

In the following version, the input_number’s value is reported as an integer. If the input_number’s entity_id is incorrect, the int filter will report 0 as the default value. In other words, it will turn off the light.

dim_morning_main_area:
  alias: Dim Morning Main Area
  icon: "mdi:lightbulb-group"
  mode: single
  sequence:
    - service: light.turn_on
      target:
        entity_id: light.living_room_pot_lights
      data:
        brightness_pct: "{{ states('input_number.default_dimmer_3') | int(0) }}"
    - service: switch.turn_on
      target:
        entity_id: switch.living_room_accent_lights
    - service: switch.turn_off
      target:
        entity_id:
          - switch.living_room_sconces
          - switch.living_room_chandelier
          - switch.entrance_lights
1 Like

This was the issue. Thanks. I’m still getting used to the entity_id vs friendly name. This has tripped me up a few times.

I appreciate you taking the time!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.