Automation: Set light brightness using input_number in visual editor

I’ve just started using automations and my current goal is to use a input_number variable to set the light brightness. (the input_number variable is updated by another automation that reads an illuminance sensor).

I’m creating my automations using the visual editor and so far I understand that it’s not possible to use things like input_number in the visual editor unless you switch to the YAML editor which uses a slightly different syntax.

1. Is there a simple way of editing just the action part of the automation in YAML and supplying the input_number variable there?

I have tried this without success, wondering if it’s even possible:

type: turn_on
device_id: 008577b037f49c9895e5e177f3078427
entity_id: light.l_hol1
domain: light
brightness_pct: "{{ states.input_number.brightness_hol.state | int }}"

I’m getting this error:

Message malformed: expected float for dictionary value @ data[‘brightness_pct’]

2. If #1 is not possible, then it should be done by switching to complete YAML automation code editing, in which case how should my automation code look like to be valid and to use the input_number for setting the brightness?

alias: 'PIR #1'
description: ''
trigger:
  - type: turned_on
    platform: device
    device_id: c837b698eaa4a3167706f62cf2efd962
    entity_id: binary_sensor.pir_ias_zone
    domain: binary_sensor
condition:
  - condition: time
    after: '20:00:00'
    before: '08:00:00'
  - condition: device
    type: is_off
    device_id: 008577b037f49c9895e5e177f3078427
    entity_id: light.l_hol1
    domain: light
action:
  - type: turn_on
    device_id: 008577b037f49c9895e5e177f3078427
    entity_id: light.l_hol1
    domain: light
    brightness_pct: 10
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - type: turn_off
    device_id: 008577b037f49c9895e5e177f3078427
    entity_id: light.l_hol1
    domain: light
mode: single

Thank you!

If you use the Automation Editor to create a Device Trigger in visual mode, do not attempt to modify the Device Trigger in YAML mode.

Device Triggers/Conditions/Actions were invented for use in visual mode and their verbose YAML representation shouldn’t be modified beyond what is permitted in visual mode.

I suggest you use traditional State Trigger, State Condition, and Service Call.

alias: 'PIR #1'
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.pir_ias_zone
    to: 'on'
condition:
  - condition: time
    after: '20:00:00'
    before: '08:00:00'
  - condition: state
    entity_id: light.l_hol1
    state: 'off'
action:
  - service: light.turn_on
    target:
      entity_id: light.l_hol1
    data:
      brightness_pct: "{{ states('input_number.brightness_hol') | int(0) }}"
  - delay: '00:00:30'
  - service: light.turn_off
    target:
      entity_id: light.l_hol1
mode: single
1 Like

Thanks! I appreciate the help!

1 Like