Set input_number from LED brightness at automation action

Hi,

I’d like to set ‘input number’ from a LED brightness in automation action.

Device: LivingRoom_LED
entity_id: light.LivingRoom_LED

Automations - action:

service: input_number.set_value
target:
entity_id: input_number.led_brightness
data:
value: ‘{{ states.light.LivingRoom_LED.attributes.brightness | int }}’

But, it doesn’t work.

What is the right solution?

Here are some suggestions:

  1. Your indentation looks wrong but it is hard to check as your yaml is not formatted correctly (see “How to ask a good question” #11).
  2. Capitals are not valid in yaml as in light.LivingRoom_LED (i.e. L, R, LED).
  3. For your template try using {{ state_attr('light.livingroom_led','brightness') | int }}
  4. Test that the above template works first by pasting it into Developer Tools - Template.
  5. Do you get any error messages if so then please provide these.

Thank you for your help.

  1. The format was correct (I think), but the copy was wrong.
  2. The original entity is correct too, only I change it from my language.
    Here’s what I tried (with the original entity):
'1636574064227':
  alias: New script
  sequence:
  - service: input_number.set_value
    target:
      entity_id: input_number.led_fenyero
    data:
      value: '{{ state_attr('light.nappali_led_lepcso','brightness') | int }}'
  mode: single

The error message (configuration->server control->check configurations:
Error loading /config/configuration.yaml: while parsing a block mapping in “/config/scripts.yaml”, line 8, column 7 expected , but found ‘’ in “/config/scripts.yaml”, line 8, column 30

The other interesting thing, that I edit it at configuration->scripts and sometimes the HA hasn’t save the changes.

You need to fix the quotes used in the template. The outer quotes should not be the same as the inner quotes.

Change the outer single quotes to double quotes. In addition, provide the int filter with a default value.

      value: "{{ state_attr('light.nappali_led_lepcso','brightness') | int(0) }}"

One more thing you should know, this script’s service call won’t work as you might expect if the light is off. A light has no brightness attribute when it’s off. So, in that case, the int filter will supply a default value of zero. If that’s how you want it to work, when the light is off, then no worries.

It works perfectly

Thank you for your help

You’re welcome! Glad to hear it solved the problem.

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, refer to guideline 21 in the FAQ.

1 Like