Using input_number in the Automation Editor

I am trying to make an automation that sends the “brightness” parameter to my z-wave dimmer switch from the input_number slider on the front-end.

This works from the Services window, turning the light on at a level of 200 (from 0-255):

{
  "entity_id": "light.landing",
  "brightness" : "200"
}

But I haven’t figured out how to get the slider data into the Action of the automation. Here’s one of my attempts:

Action Type:
Call Service

Service:
light.turn_on  
   
Service Data  
{
  "brightness": "states('input_number.ldg_dimmer')",
  "entity_id": "light.landing"
}

If I put a discrete number for “brightness”:“200”, then touching the slider turns the light on at level 200. Any tips would be appreciated to show me how to get the slider value into this automaton action.

I’m not sure you can use templates in the automation editor. If you can, it should be:

{
  "brightness": "{{ states('input_number.ldg_dimmer') }}",
  "entity_id": "light.landing"
}

I suspected that I couldn’t use templates. Your suggestion doesn’t work either.
I just discovered the “automation_old” component, may be that’s my solution.

Thanks for the input.

Well, that didn’t work. I got this on config check:

Component not found: automation_old

Now, I can’t find where I read about “automation_old”.

I think you could avoid these headaches if you learned how to automate via yaml. This would have been a single line fix in yaml.

Thanks, I don’t have anything significant in automations.yaml that can’t be rewritten since they are just experiments.

automation.old was supposed to be a way to have both yaml and automations editor, but I can’t find where it is described.

I’ll try again with a new automations.yaml file.

This documentation has a description on how to use automation old:

fwiw, and pardon me if I am jumping on the wrong train here, but just a few hours ago I couldn’t figure out why this would not work:

action:
  service: light.turn_on
  data_template:
    entity_id: light.outside
    brightness: >
      {{state_attr('light.outside','brightness') }}

and it appeared the brightness expects an int…:

Invalid service data for light.turn_on: expected int for dictionary value @ data['brightness'].

action:
  service: light.turn_on
  data_template:
    entity_id: light.outside
    brightness: >
      {{state_attr('light.outside','brightness') |int }}

did the trick.

maybe it helps. Nice thing here, is that it even works when brightness = 0, turning off the light with the turn_on command :wink:

btw @petro might I ask you to have a look here: Using input_number in the Automation Editor - #8 by Mariusthvdb also trying to use an input_number in an automation…

Thanks so much. It’s still not working, but I am getting closer.
I couldn’t find “automation_old” because it isn’t a component and it is “automation old”.

I did see the example automation that publishes an MQTT message with the slider value. I kind of started there.

I made a new include file named “automations_old” and added it to my configuration.yaml. In it I attempted to make the automation, and it almost works.

- alias: Landing Light Dimmer Control
  trigger:
  - entity_id: input_number.landing_brightness
    platform: state
  condition: []
  action:
    service: light.turn_on
    data_template:
      {"brightness": "{{ states('input_number.ldg_dimmer')|int }}","entity_id": "light.landing"}

Now, with the new (old-style) automation, if I touch the slider, the light turns off. I am guessing that it is receiving a bightness of zero but the config tool only says “off”. So, as I said, getting somewhere because before now, touching the slider did nothing.

doh-computer-120x76

I was using the wrong states entity in my action section…

This works:

- alias: Landing Light Dimmer Control
  trigger:
  - entity_id: input_number.landing_brightness
    platform: state
  condition: []
  action:
    service: light.turn_on
    data_template:
      {"brightness": "{{ states('input_number.landing_brightness')|int }}","entity_id": "light.landing"}

Again, many thanks. I would not have found the solution this fast without your guidance.

you know you can also write this like:

- alias: Landing Light Dimmer Control
  trigger:
    platform: state
    entity_id: input_number.landing_brightness
  condition: []
  action:
    service: light.turn_on
    data_template:
      entity_id: light.landing
      brightness: > #this is the multiline indicator and makes you not need quotes around the template
        {{ states('input_number.landing_brightness')|int }}

maybe even replace that last template by:

  {{trigger.to_state.state |int}} though i must confess I didn't test that..

For my personal taste, this is prettier on the eye.

I also prefer the ‘pretty’ version even though JSON generally ignores white space and line breaks. JSON Formatter is my friend.

I was apparently wrong to advice on the |int for brightness, (unless you’ve made your input_number not create int’s…)
please see this thread on that Isn't this an int?

You might still need it, but because of a special and peculiar detail, when the template hasn’t got a value (None), and you need it to have a value to pass.

Mine won’t work without the int.
Here’s the slider code:

input_number:
  landing_brightness:
    name: Landing Brightness
    initial: 50
    min: 0
    max: 255
    step: 1
    mode: slider

as is my experience. Still puzzles me.
see: Input Number - Home Assistant for brightness using |int.