Dimmer trun on brightness vs toggle

Hi, I want to turn on my dimmer with a button click. On and of works by using:

Button 1:
- light.turn_off: dimmer

Button 2:
- light.turn_on: dimmer

But now when I have my dimmer set a 4-8% and turning it off it will not start a few hours later.

I have now:
Button 2:

          - light.turn_on: 
              id: dimmer
              brightness: 10%

This always starts the dimmer correctly (never lower than 10%).

But then obviously It always starts a 10%.

I would want to start at the last know brightness unless it was lower than 10% (if lower than 10% then start at 10…). Like the turn_on and off did…

Could use some help in thinking this out the right way.

What light/output component?

light:
  - platform: shelly_dimmer
    name: "${device_name}"
    id: dimmer
    icon: mdi:globe-light-outline
    power:
      name: "${device_name} Power"
      id: power_dimmer
    voltage:
      name: "${device_name} Voltage"
    current:
      name: "${device_name} Current"
    min_brightness: 350
    max_brightness: 1000
    firmware:
      version: "51.6"
      update: true

binary_sensor:
  - platform: gpio
    name: 'Switch 1'
    id: switchID_1
    pin:
      number: GPIO12
      mode: INPUT
    internal: true
    filters:
      - delayed_on_off: 50ms
    on_multi_click:
      # single click
      - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
        then:
          - logger.log: "Single-Clicked"
          - light.turn_off: dimmer
      # Hold button
      - timing:
        - ON for at least 1s
        then:
          - logger.log: "Hold - Dim DOWN"
          - while:
                condition:
                  - binary_sensor.is_on: switchID_1
                then:
                  - light.dim_relative:
                      id: dimmer
                      relative_brightness: -0.5%
                      transition_length: 0.01s
                  - delay: 0.01s
  - platform: gpio
    name: 'Switch 2'
    id: switchID_2
    pin:
      number: GPIO14
      mode: INPUT
    internal: true
    filters:
      - delayed_on_off: 50ms
    on_multi_click:
      # single click
      - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
        then:
          - logger.log: "Single-Clicked"
          - light.turn_on:
              id: dimmer
              brightness: 12%
      # Hold button
      - timing:
        - ON for at least 1s
        then:
          - logger.log: "Hold - Dim UP"
          - while:
                condition:
                  - binary_sensor.is_on: switchID_2
                then:
                  - light.dim_relative:
                      id: dimmer
                      relative_brightness: +0.5%
                      transition_length: 0.01s
                  - delay: 0.01s
``

I think it’s dimmer’s fault. Many dimmers can go as low as 4% or even lower, but only from higher value, while they won’t start until you reach 10% or so when going from 0% - triac inside just can’t start to conduct at such low values. Same effect was back then when i used button-designed wall dimmers: i’ve always had to turn a bit higher for light to start and then revert to lower value.

Only solution in this case is to start dimmer higher and then immediately go lower, say one “if” sentence:

  • if brightness is lower than 10% then:
  • turn on light to 10%
  • go back with brightness to 4%.

This part works. That’s what you mean.

An indeed, this

Is what I need, but where and how do I do that?

I guess that something like this:

binary_sensor:
  - platform: gpio
    name: 'Switch 1'
    id: switchID_1
    pin:
      number: GPIO12
      mode: INPUT
    internal: true
    filters:
      - delayed_on_off: 50ms
    on_press:
      if:
        condition:
          light.is_off:
            id: ${device_name}
        then:
          - light.turn_on:
              id: ${device_name}
              transition_length: 0s
              brightness: 10%
          - light.turn_on:
              id: ${device_name}
              transition_length: 0s
              brightness: 4%  
        else:
          - light.turn_on:
              id: ${device_name}
              transition_length: 0s
            brightness: 4%              

it’s untested, written by memory, but it’s a start…

Here’s what I came up with to implement the bump start for brightness less than 10%

    #when light is turned on and brightness less than 10%
    #bump brightness to 10% and then back to current
    on_turn_on:
      then:
        - lambda: |- 
            float b = id(dimmer).remote_values.get_brightness();
            if (b < 0.10) {
              id(dimmer).remote_values.set_brightness(0.10);
              id(dimmer).remote_values.set_brightness(b);
            }

This should execute only when the light is turned from off to on. If the brightness was less than 10%, set the brightness to 10% and then back to original value. The remote_values.get_brightness() and remote_values.set_brightness() aren’t documented functions. I tested on a monochromatic light and the logic worked and brightness was updated. Might need to add a delay to give the 10% brightness time to propagate to the light.

1 Like