Light brightness when switched on

Hello,

I’d like to change the brightness of my light so that it turns on with a certain brightness when switched with a wall switch. The problem is that in HA I can apparently only set light brightness when the light is on. This automation works fine:

alias: Light brightness
description: ''
trigger:
  - platform: device
    domain: mqtt
    device_id: 04fa4d759aeb9fb322a78bad971a5a99
    type: action
    subtype: hold
    discovery_id: 0x00158d000373d8c4 action_hold
condition: []
action:
  - service: light.turn_on
    target:
      device_id: 1cd7038c8a8bbea60553b897a011ee31
    data:
      brightness_pct: 50
mode: single

But if I change the - service: light.turn_on to - service: light.turn_off, it doesn’t work anymore.

I tried to change the brightness by turning the light on with a certain brightness and then immediately turn it off. But it is not fast enough and the light flashes with this approach.

How can I change the brightness of my light (it is controlled by a smart dimmer QS-Zigbee-D02-TRIAC-L) without actually turning the light on? Thank you.

1 Like

This is, how I solve it:

Make a scene from the light state, as you want it.
In the automation, after switching the light on, call that scene.

example, as i use it (even with delay, giving the lamp time to react…):

alias: Raaf Lamp aan
description: ''
trigger:
  - platform: state
    entity_id: switch.sonoff_10008c3a5b_3
    from: 'off'
    to: 'on'
condition: []
action:
  - delay: '1'
  - service: light.turn_on
    data: {}
    entity_id: light.raaflamp
  - scene: scene.raaf_lamp_wit
mode: single

To my knowledge, only the LIFX integration supports setting a light’s parameters while the light is off using a custom service call: LIFX Service lifx.set_state

For most other lighting integrations, Home Assistant sets the lights parameters (like brightness) using the standard light.turn_on service.

I just wait until it has been on for a few seconds, and then set the brightness:

alias: 'AUTO Lighting: Livingroom'
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: f2895dc2612fdd5d8a39ce4d28e100d6
    entity_id: light.fireplace_light
    domain: light
    id: fireplace_on
  - platform: device
    type: turned_on
    device_id: 8e9341d5bbe8f7ab55e1bb2492774367
    entity_id: light.livingroom_window_light
    domain: light
    id: window_on
[snip]
condition:
  - condition: state
    entity_id: input_boolean.livingroom_media_lighting_override
    state: 'off'
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: fireplace_on
              - condition: trigger
                id: window_on
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: '{{ trigger.entity_id }}'
              brightness_pct: '{{ states(''input_number.livingroom_light'')|int }}'
      - conditions:
          - condition: trigger
            id: level_change
        sequence:
          - service: script.turn_on
            target:
              entity_id: script.adjust_brightness_if_on
            data:
              variables:
                light_target: light.fireplace_light
                brightness_target: '{{ states(''input_number.livingroom_light'')|int }}'
          - service: script.turn_on
            target:
              entity_id: script.adjust_brightness_if_on
            data:
              variables:
                light_target: light.livingroom_window_light
                brightness_target: '{{ states(''input_number.livingroom_light'')|int }}'
    default: []
mode: parallel
max: 10

There is additional stuff snipped out, like reacting to input_number changes etc, but that’s the basics.