SOLVED Use filter with maximum value

Hi,
i made a Thermometer using DS18B20 and for display MAX7219.

I want to use my Solarpanel Voltage to control the brightness of the MAX7219 display.

here my code:

dallas:
  - pin: GPIO05
    update_interval: 10s
  
sensor:
  - platform: dallas
    address: 0x8001212f15e6c228
    name: "POOL Luft Temp"
    id: "DS18B20_1"
  - platform: dallas
    address: 0x1001212ecab08628
    name: "POOL Wasser Temp"
    id: "DS18B20_2"
  - platform: dallas
    address: 0x8b01212f137c8e28
    name: "POOL Solar Temp"
    id: "DS18B20_3"
  - platform: dallas
#    address: 0x6601212f0084db28
    address: 0x8888888888888888
    name: "POOL Heizung Temp"
    id: "DS18B20_4"
  - platform: homeassistant
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    entity_id: "sensor.solar_input_voltage"
    filters:
      - calibrate_linear:
          - 1 -> 0
          - 22 -> 15

spi:
  clk_pin: 14
  mosi_pin: 13

display:
  - platform: max7219
    cs_pin: 04
    num_chips: 2
    intensity: 1
    lambda: |-
      it.set_intensity(id(max7219_bright).state);
      it.printf(0, " ");
      it.printf(1, "%.1f", id(DS18B20_1).state);
      it.printf(4, " ");
      it.printf(5, "%.1f", id(DS18B20_2).state);
      it.printf(8, " ");
      it.printf(9, "%.1f", id(DS18B20_4).state);
      it.printf(12, " ");
      it.printf(13, "%.1f", id(DS18B20_3).state);
           

My Problem is:

if the solar_voltage gets higher than 22V the MAX7219 gets values over 15.
How can i limit the output of the filter so it never goes higher than 15? (Thats the brightes value for the MAX…)
Or could i use the sun.sunset /sun.sunrise in the filter?

Goal is to turn the display dark when day is gone.
So if it would be easier with the sun value i go that way.
can filter accept sunrise ? or only number values?

What if you do this?

    filters:
      - calibrate_linear:
          - 1 -> 0
          - 22 -> 15
          - 100 -> 15 

If that doesn’t work you can use a template number and set it in a lambda.

  - platform: homeassistant
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    entity_id: "sensor.solar_input_voltage"
    on_value:
      then:
        lambda: |-
          if (id(max7219_bright).state == 0.0) {
              auto call = id(brightness).make_call();
              call.set_value(0);
              call.perform();;
          }
          else if ((id(max7219_bright).state > 0.0) and (id(max7219_bright).state <= 8.0)) {
              auto call = id(brightness).make_call();
              call.set_value(5);
              call.perform();;
          }
          else if ((id(max7219_bright).state > 8.0) and (id(max7219_bright).state <= 16.0)) {
              auto call = id(brightness).make_call();
              call.set_value(10);
              call.perform();;
          }
          else {
              auto call = id(brightness).make_call();
              call.set_value(15);
              call.perform();;
          }

number:
  - platform: template
    id: brightness
    optimistic: true
    min_value: 0
    max_value: 15
    step: 1

i have tried this:

    filters:
      - calibrate_linear:
          - 1 -> 0
          - 22 -> 15.7
          - 23 -> 15.7
          - 24 -> 15.7
          - 25 -> 15.8
          - 26 -> 15.7
          - 27 -> 15.7
          - 28 -> 15.7
          - 29 -> 15.8
          - 30 -> 15.7
          - 31 -> 15.7
          - 32 -> 15.7
          - 33 -> 15.7
          - 34 -> 15.7
          - 35 -> 15.7
          - 36 -> 15.7
          - 37 -> 15.7
          - 38 -> 15.7
          - 39 -> 15.7

Now i get always values of 15.0 - 15.3 , so at the moment it seems to be ok.

About sun: is it also possible to use the state of sun in the filter?
like so:

    filters:
      - calibrate_linear:
          - sun.sunset -> 0
          - sun.sunrise -> 15

if you want to use sun you’ll still need the number component as I don’t see a way to call the intensity on the fly.

number:
  - platform: template
    id: brightness
    optimistic: true
    min_value: 0
    max_value: 15
    step: 1


sun:
  latitude: 48.8584°
  longitude: 2.2945°

  on_sunrise:
    - then:
        - number.set:
            id: brightness
            value: 15

  on_sunset:
    - then:
        - number.set:
            id: brightness
            value: o




I have tried both variants, the sun variant works but it doesn’t look so good, just too much brightness switching. Technical ok but not for human eys.

So i tried your first variant and this seems to be it!
If there are more different brightness steps needed, one can just add another block.

So here my finished code, maybe someone else find it useful:

esphome:
  name: pool_temp
  platform: ESP8266
  board: d1_mini

# Enable Home Assistant API
api:
  password: "xxxxxxxx"

ota:
  password: "xxxxxxxx"

wifi:
  networks:
  - ssid: "xxxxxxxx 2"
    password: "xxxxxxxx"
  - ssid: "xxxxxxxx 3"
    password: "xxxxxxxx"
  manual_ip:
    static_ip: 192.168.2.254
    gateway: 192.168.2.1
    subnet: 255.255.252.0

web_server:
  port: 80

dallas:
  - pin: GPIO05
    update_interval: 30s
  
sensor:
  - platform: dallas
    address: 0x8001212f15e6c228
    name: "POOL Luft Temp"
    id: "DS18B20_1"
  - platform: dallas
    address: 0x1001212ecab08628
    name: "POOL Wasser Temp"
    id: "DS18B20_2"
  - platform: dallas
    address: 0x8b01212f137c8e28
    name: "POOL Solar Temp"
    id: "DS18B20_3"
  - platform: dallas
    address: 0x6601212f0084db28
    name: "POOL Heizung Temp"
    id: "DS18B20_4"
  - platform: homeassistant
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    entity_id: "sensor.solar_input_voltage" # Data comes over MQTT of my MPPT-Charger over HA
    on_value:
      then:
        lambda: |-
          if (id(max7219_bright).state < 10.0)  # if Solar-Voltage less than 10V it is nearly dark
          {
              auto call = id(brightness).make_call();
              call.set_value(0); # Set MAX7219 Brightness to 0 (this is not off, but the lowest Brightness)
              call.perform();;
          }
          else if ((id(max7219_bright).state > 10.0) and (id(max7219_bright).state <= 20.0)) 
          {
              auto call = id(brightness).make_call();
              call.set_value(5);
              call.perform();;
          }
          else if ((id(max7219_bright).state > 20.0) and (id(max7219_bright).state <= 28.0)) 
          {
              auto call = id(brightness).make_call();
              call.set_value(12);
              call.perform();;
          }
          else 
          {
              auto call = id(brightness).make_call();
              call.set_value(15);
              call.perform();;
          }

number:
  - platform: template
    id: brightness
    optimistic: true
    min_value: 0
    max_value: 15
    step: 1

 spi:
  clk_pin: 14
  mosi_pin: 13

display:
  - platform: max7219
    cs_pin: 04
    num_chips: 2
    intensity: 1
    lambda: |-
      it.set_intensity(id(max7219_bright).state);
      it.printf(0, " ");
      it.printf(1, "%.1f", id(DS18B20_1).state);
      it.printf(4, " ");
      it.printf(5, "%.1f", id(DS18B20_2).state);
      it.printf(8, " ");
      it.printf(9, "%.1f", id(DS18B20_4).state);
      it.printf(12, " ");
      it.printf(13, "%.1f", id(DS18B20_3).state);
      

So many thanks for all your help!

1 Like