Convert brightness πŸ”… to % percentage

I have setup a ESPhome node for which changes the brightness of the Aquarium lights via esphome automation. Connected a lcd_pcf8574 display to it. Now am trying to display the current brightness :high_brightness: level on the display using the lambda function. The value I get is between 0-1, e.g 70% brightness is displayed as 0.7. I want to display it as a percentage. e.g Brightness 70%. How do I do that? with filters maybe?

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    id: lcd 
    lambda: |-
          switch (id(page)){
            case 1:
              // Print the current time
            it.strftime("Time is %c", id(sntp_time).now());
            // Result for 10:06 on august 21st 2018 -> "It is 10:06 on 21.08.2018"
              break;
            case 2: 
              it.printf(0, 0, "ESP32 Halleffect: %.1fΒ΅T", id(halleffect).state);
              break;
            case 3: 
              it.printf(0, 0, "brightness: %.1f", id(AqauriumLight).current_values.get_brightness());
              break;
          }

You should be able to just multiply that floating point decimal number by 100 and then in a filter display it as a percentage

1 Like

I didn’t realize you can do switch case statements in a lambda. I thought I read somewhere that there was a feature request for that, do you know how long that’s been possible?

It’s just C++ code in lambdas, so if you can express it in C[++], you can do it in lambdas.

Solution was multiply, but I was doing it wrongly
Jesse himself provided it

case 3: 
              it.printf(0, 0, "brightness: %.1f", id(AqauriumLight).current_values.get_brightness() * 100);
              break;
1 Like

I think I’ve only used switch case a handful of times and that was in my Arduino days. I just remembered seeing a feature request for it but I looked again, it was a request to use it directly in esphome not a lambda. It’s all good to know though. No one ever complained about knowing to much.