Set output.set_level with lambda function from number template

Hi,
Im trying to set output.set_level on motor using lambda function get states from number template.

        - output.set_level:
            id: silnik_1_pwm
            level: !lambda 'return (id(mopowanie_predkosc_silnik1).state);'

but its gets onlu number but char “%” is required how to print it with lambda at end of that?

number:

  • platform: template
    name: mopowanie_predkosc_silnik1
    id: mopowanie_predkosc_silnik1
    unit_of_measurement: ‘%’
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true

What does the documentation say?

- output.set_level:
            id: silnik_1_pwm
            level: !lambda  |- return id(mopowanie_predkosc_silnik1).state;

Sorry but still i dont understand, its the lamba code correct? I need change mode in number or something?

Just post your config


substitutions:
  devicename: d-mop


wifi:
  networks:
  - ssid: 'xxx'
    password: 'xxxx'
  - ssid: 'xxxxxx'
    password: 'xxxxx'
  reboot_timeout: 0s
  domain: '.xxxxx'
  ap:
    ssid: "${devicename}"
    password: xxxxxx
api:
  reboot_timeout: 0s
ota:
  password: xxxxxxxx
captive_portal:
logger:



esphome:
  name: ${devicename}
  platform: esp32
  board: esp32dev
  on_boot:
    - priority: 600
      then:
        # Start - sprawdzanie systemu i pojemników
        - display.page.show: oled_start
        - switch.turn_on: led_brudna_woda
        - switch.turn_on: led_mopowanie
        - switch.turn_on: led_czyszczenie
        - switch.turn_on: led_zaloz_walek
        - switch.turn_on: led_zbieranie
        - switch.turn_on: led_zatkana_rura
        - switch.turn_on: led_brak_wody
        - delay: 2s
        - switch.turn_off: led_brudna_woda
        - switch.turn_off: led_mopowanie
        - switch.turn_off: led_czyszczenie
        - switch.turn_off: led_zaloz_walek
        - switch.turn_off: led_zbieranie
        - switch.turn_off: led_zatkana_rura
        - switch.turn_off: led_brak_wody
    - priority: 0
      then:
        # Podciaganie wody
        - script.execute: podciaganie_wody
        - delay: 3s
        # Sprawdzanie stanu wody co 3s
        - script.execute: sprawdzanie
        - delay: 1s
      # Gotowy
        - display.page.show: oled_gotowy
        - dfplayer.play_folder:
            folder: !lambda 'return (id(language).state);'
            file: 1



i2c:
  sda: GPIO1
  scl: GPIO3

web_server:
  port: 80
  version: 1

time:
  - platform: homeassistant
    id: homeassistant_time


number:
  - platform: template
    name: Język
    id: language
    min_value: 1
    max_value: 3
    step: 1
    optimistic: true
    restore_value: true
  # MOPOWANIE - PREDKOSCI
  - platform: template
    name: mopowanie_predkosc_silnik1
    id: mopowanie_predkosc_silnik1
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  - platform: template
    name: mopowanie_predkosc_silnik2
    id: mopowanie_predkosc_silnik2
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  - platform: template
    name: mopowanie_czas_pompka1
    id: mopowanie_czas_pompka1
    unit_of_measurement: 's'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  # MOPOWANIE TURBO - PREDKOSCI
  - platform: template
    name: mopowanie_turbo_predkosc_silnik1
    id: mopowanie_turbo_predkosc_silnik1
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  - platform: template
    name: mopowanie_turbo_predkosc_silnik2
    id: mopowanie_turbo_predkosc_silnik2
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  - platform: template
    name: mopowanie_turbo_czas_pompka1
    id: mopowanie_turbo_czas_pompka1
    unit_of_measurement: 's'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  # ZBIERANIE - PREDKOSCI
  - platform: template
    name: zbieranie_predkosc_silnik1
    id: zbieranie_predkosc_silnik1
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true
  - platform: template
    name: zbieranie_predkosc_silnik2
    id: zbieranie_predkosc_silnik2
    unit_of_measurement: '%'
    min_value: 1
    max_value: 100
    step: 1
    optimistic: true
    restore_value: true




button:
  - platform: restart
    name: "Restart"
  - platform: template
    name: "Audio - Play 1"
    on_press:
      then:
        - dfplayer.play_folder:
            folder: !lambda 'return (id(language).state);'
            file: 1
  - platform: template
    name: "Audio - Volume 10"
    on_press:
      then:
        - dfplayer.set_volume: 10
  - platform: template
    name: "Audio - Volume 20"
    on_press:
      then:
        - dfplayer.set_volume: 20
  - platform: template
    name: "Audio - Volume 30"
    on_press:
      then:
        - dfplayer.set_volume: 30
  - platform: template
    name: "Audio - BASS"
    on_press:
      then:
        - dfplayer.set_eq: BASS

switch:

# LED
  - platform: gpio
    name: 'LED - Mopowanie'
    id: led_mopowanie
    pin: GPIO27

  - platform: gpio
    name: 'LED - Zbieranie'
    id: led_zbieranie
    pin: GPIO26

  - platform: gpio
    name: 'LED - Czyszczenie'
    id: led_czyszczenie
    pin: GPIO25

  - platform: gpio
    name: 'LED - Brak wody'
    id: led_brak_wody
    pin: GPIO16

  - platform: gpio
    name: 'LED - Brudna woda'
    id: led_brudna_woda
    pin: GPIO14

  - platform: gpio
    name: 'LED - Załóż wałek'
    id: led_zaloz_walek
    pin: GPIO33

  - platform: gpio
    name: 'LED - Zatkana rura'
    id: led_zatkana_rura
    pin: GPIO12

# MOPOwANIE
  - platform: template
    name: Mopowanie
    id: switch_mopowanie
    optimistic: true
    turn_on_action:
      - switch.turn_off: switch_mopowanie_turbo
      - switch.turn_off: switch_zbieranie
      - switch.turn_off: switch_czyszczenie
      - switch.turn_on: led_mopowanie
      - script.execute: mopowanie
    turn_off_action:
      - switch.turn_off: led_mopowanie
      - script.stop: mopowanie
      - script.execute: stop

# MOPOWANIE TURBO
  - platform: template
    name: Mopowanie Turbo
    id: switch_mopowanie_turbo
    optimistic: true
    turn_on_action:
      - switch.turn_off: switch_mopowanie
      - switch.turn_off: switch_zbieranie
      - switch.turn_off: switch_czyszczenie
      - switch.turn_on: led_mopowanie
      - script.execute: mopowanie_turbo
    turn_off_action:
      - switch.turn_off: led_mopowanie
      - script.stop: mopowanie_turbo
      - script.execute: stop

# ZBIERANIE
  - platform: template
    name: Zbieranie
    id: switch_zbieranie
    optimistic: true
    turn_on_action:
      - switch.turn_off: switch_mopowanie
      - switch.turn_off: switch_mopowanie_turbo
      - switch.turn_off: switch_czyszczenie
      - switch.turn_on: led_zbieranie
      - script.execute: zbieranie
    turn_off_action:
      - switch.turn_off: led_zbieranie
      - script.stop: zbieranie
      - script.execute: stop

# CZYSZCZENIE
  - platform: template
    name: Czyszczenie
    id: switch_czyszczenie
    optimistic: true
    turn_on_action:
      - switch.turn_off: switch_mopowanie
      - switch.turn_off: switch_mopowanie_turbo
      - switch.turn_off: switch_zbieranie
      - switch.turn_on: led_czyszczenie
      - script.execute: czyszczenie
    turn_off_action:
      - switch.turn_off: led_czyszczenie
      - script.stop: czyszczenie
      - script.execute: stop



# ------------------------------------------------------------------------------- SKRYPTY
script:
# Podciąganie wody
  - id: podciaganie_wody
    then:
      # Włączanie pompki od wody na 3s
      - output.set_level:
          id: pompka_1_pwm
          level: 50%
      - delay: 3s
      - output.turn_off: pompka_1_pwm


# Sprawdzanie poziomu wody
  - id: sprawdzanie
    then:
      - repeat:
          count: 99999
          then:

            # CZYSTA WODA - TYLKO LED
            - if:
                condition:
                  - binary_sensor.is_on: sensor_brak_wody
                then:
                  - switch.turn_on: led_brak_wody
            - if:
                condition:
                  - binary_sensor.is_off: sensor_brak_wody
                then:
                  - switch.turn_off: led_brak_wody
            # CZYSTA WODA - MOPOWANIE
            - if:
                condition:
                  - binary_sensor.is_on: sensor_brak_wody
                  - switch.is_on: switch_mopowanie
                then:
                  - switch.turn_off: switch_mopowanie
                  - delay: 2s
                  - switch.turn_on: led_brak_wody
                  - display.page.show: oled_brak_wody
                  - dfplayer.play_folder:
                      folder: !lambda 'return (id(language).state);'
                      file: 6
            # CZYSTA WODA - MOPOWANIE TURBO
            - if:
                condition:
                  - binary_sensor.is_on: sensor_brak_wody
                  - switch.is_on: switch_mopowanie_turbo
                then:
                  - switch.turn_off: switch_mopowanie_turbo
                  - delay: 2s
                  - switch.turn_on: led_brak_wody
                  - display.page.show: oled_brak_wody
                  - dfplayer.play_folder:
                      folder: !lambda 'return (id(language).state);'
                      file: 6
            # CZYSTA WODA - CZYSZCZENIE
            - if:
                condition:
                  - binary_sensor.is_on: sensor_brak_wody
                  - switch.is_on: switch_czyszczenie
                then:
                  - switch.turn_off: switch_czyszczenie
                  - delay: 2s
                  - switch.turn_on: led_brak_wody
                  - display.page.show: oled_brak_wody
                  - dfplayer.play_folder:
                      folder: !lambda 'return (id(language).state);'
                      file: 6

            # PELNY ZBIORNIK BRUDNEJ WODY
            - if:
                condition:
                  - binary_sensor.is_on: sensor_brudna_woda
                then:
                  - switch.turn_off: switch_mopowanie
                  - switch.turn_off: switch_mopowanie_turbo
                  - switch.turn_off: switch_zbieranie
                  - switch.turn_off: switch_czyszczenie
                  - delay: 2s
                  - switch.turn_on: led_brudna_woda
                  - display.page.show: oled_brudna_woda
                  - dfplayer.play_folder:
                      folder: !lambda 'return (id(language).state);'
                      file: 7
            - if:
                condition:
                  - binary_sensor.is_off: sensor_brudna_woda
                then:
                  - switch.turn_off: led_brudna_woda

            - delay: 10s


  # MOPOWANIE
  - id: mopowanie
    then:
      - if:
          condition:
            - binary_sensor.is_on: sensor_przechyl
            - binary_sensor.is_off: sensor_brak_wody
            - binary_sensor.is_off: sensor_brudna_woda
          then:
            - display.page.show: oled_mopowanie
            - dfplayer.play_folder:
                folder: !lambda 'return (id(language).state);'
                file: 2
            - delay: 2s
            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (id(mopowanie_predkosc_silnik1).state, "%%");'
            - output.set_level:
                id: silnik_2_pwm
                level: !lambda 'return (id(mopowanie_predkosc_silnik2).state, "%%");'
            - repeat:
                count: 9999
                then:
                  - output.set_level:
                      id: pompka_1_pwm
                      level: 50%
                  - delay: 1s
                  - output.turn_off: pompka_1_pwm
                  - delay: !lambda 'return (id(mopowanie_czas_pompka1).state, "%s");'


  # MOPOWANIE TURBO
  - id: mopowanie_turbo
    then:
      - if:
          condition:
            - binary_sensor.is_on: sensor_przechyl
            - binary_sensor.is_off: sensor_brak_wody
            - binary_sensor.is_off: sensor_brudna_woda
          then:
            - display.page.show: oled_mopowanie_turbo
            - dfplayer.play_folder:
                folder: !lambda 'return (id(language).state);'
                file: 3
            - delay: 2s
            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (id(mopowanie_turbo_predkosc_silnik1).state);'
            - output.set_level:
                id: silnik_2_pwm
                level: !lambda 'return (id(mopowanie_turbo_predkosc_silnik2).state);'
            - repeat:
                count: 9999
                then:
                  - output.set_level:
                      id: pompka_1_pwm
                      level: 50%
                  - delay: 1s
                  - output.turn_off: pompka_1_pwm
                  - delay: !lambda 'return (id(mopowanie_turbo_czas_pompka1).state);'


  # ZBIERANIE
  - id: zbieranie
    then:
      - if:
          condition:
            - binary_sensor.is_on: sensor_przechyl
            - binary_sensor.is_off: sensor_brudna_woda
          then:
            - switch.turn_on: led_zbieranie
            - display.page.show: oled_zbieranie
            - dfplayer.play_folder:
                folder: !lambda 'return (id(language).state);'
                file: 4
            - delay: 2s
            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (id(zbieranie_predkosc_silnik1).state);'
            - output.set_level:
                id: silnik_2_pwm
                level: !lambda 'return (id(zbieranie_predkosc_silnik2).state);'


  # CZYSZCZENIE
  - id: czyszczenie
    then:
      - if:
          condition:
            - binary_sensor.is_off: sensor_przechyl
            - binary_sensor.is_off: sensor_brak_wody
            - binary_sensor.is_off: sensor_brudna_woda
          then:
            - switch.turn_on: led_czyszczenie
            - display.page.show: oled_czyszczenie
            - dfplayer.play_folder:
                folder: !lambda 'return (id(language).state);'
                file: 5
            - delay: 3s
            - output.set_level:
                id: silnik_1_pwm
                level: 100%
            - output.set_level:
                id: silnik_2_pwm
                level: 100%
            # Włacza pompke
            - output.set_level:
                id: pompka_1_pwm
                level: 50%
            - delay: 240s
            - output.turn_off: pompka_1_pwm
            - delay: 60s
            - switch.turn_off: switch_czyszczenie

  # STOP
  - id: stop
    then:
      - output.turn_off: silnik_1_pwm
      - output.turn_off: silnik_2_pwm
      - output.turn_off: pompka_1_pwm
      - display.page.show: oled_gotowy



# OLED 1
image:
  - file: images/esphome_logo.png
    id: esphome_logo
    resize: 128x64

font:
  - file: "gfonts://Roboto"
    id: font_40
    size: 40
  - file: "gfonts://Roboto"
    id: font_30
    size: 30
  - file: "gfonts://Roboto"
    id: font_18
    size: 18
  - file: "gfonts://Roboto"
    id: font_14
    size: 14

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3D
    update_interval: 1s
    id: oled_1
    pages:
      - id: oled_start
        lambda: |-
          it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "TurboMop 3000");
          it.print(64, 35, id(font_14), TextAlign::CENTER_HORIZONTAL, "wykonal: Wojtek");
      - id: oled_gotowy
        lambda: |-
          it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "Witaj");
          it.print(64, 35, id(font_18), TextAlign::CENTER_HORIZONTAL, "Ola");
      # Mopowanie
      # it.printf(64, 32, id(font_18), TextAlign::CENTER_HORIZONTAL, "%.2fV", id(czujnik_zabrudzenia_adc).state);
      - id: oled_mopowanie
        lambda: |-
            it.print(64, 32, id(font_18), TextAlign::CENTER, "Mopowanie");
      # Mopowanie Turbo
      - id: oled_mopowanie_turbo
        lambda: |-
            it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "Turbo");
            it.printf(64, 35, id(font_18), TextAlign::CENTER_HORIZONTAL, "Mopowanie");
      # Zbieranie
      - id: oled_zbieranie
        lambda: |-
            it.print(64, 32, id(font_18), TextAlign::CENTER, "Zbieranie");
      # Czyszczenie
      - id: oled_czyszczenie
        lambda: |-
            it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "Czyszczenie");
            it.printf(64, 35, id(font_18), TextAlign::CENTER_HORIZONTAL, "3 minuty");
      # Pełny zbiornik brudnej wody
      - id: oled_brudna_woda
        lambda: |-
            it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "Wylej");
            it.print(64, 35, id(font_18), TextAlign::CENTER_HORIZONTAL, "brudna wode");
      # Brak wody
      - id: oled_brak_wody
        lambda: |-
          it.print(64, 5, id(font_18), TextAlign::CENTER_HORIZONTAL, "Dolej");
          it.print(64, 35, id(font_18), TextAlign::CENTER_HORIZONTAL, "czystej wody");
      # Mowa
      - id: oled_mowa_info
        lambda: |-
          it.printf(64, 32, id(font_30), TextAlign::CENTER, "%.0f", id(language).state);



# AUDIO
uart:
  tx_pin: GPIO23
  rx_pin: GPIO22
  baud_rate: 9600



dfplayer:


output:

# Silnik 1 PWM Output (PCB_1 3.3V - mozna wieksze freq bo ma 3 fazy i niezalezne uzwojenia)
  - platform: ledc
    id: silnik_1_pwm
    pin: GPIO4
    frequency: 20kHz
    channel: 2

# Silnik 2 PWM (PCB_2 - wyzsze freq indukcja na zwojach silnika nie pozwala, albo trzeba na 5V pcb)
  - platform: ledc
    id: silnik_2_pwm
    pin: GPIO2
    frequency: 20kHz
    channel: 4

# Pompka 1 PWM
  - platform: ledc
    id: pompka_1_pwm
    pin: GPIO15
    frequency: 100Hz
    channel: 6


fan:
  - platform: speed
    output: silnik_1_pwm
    name: "Silnik 1"

  - platform: speed
    output: silnik_2_pwm
    name: "Silnik 2"
  
  - platform: speed
    output: pompka_1_pwm
    name: "Pompka 1"







# SENSOR ZABRUDZENIA
sensor:
  - platform: adc
    pin: GPIO39
    name: "Czujnik - Zabrudzenia"
    id: czujnik_zabrudzenia_adc
    update_interval: 2s
    attenuation: auto

# SENSOR BRUDNEJ WODY
  - platform: adc
    pin: 
      number: GPIO32
      mode:
        input: true
        pullup: true
    name: "Sensor - Brudna woda"
    id: sensor_brudna_woda_adc
    update_interval: 2s
    attenuation: auto





binary_sensor:

# ----- STEROWANIE PRZYCISKAMI
# Przyciski 1 --> Mopowanie (ma się włączyc tylko jak czujnik wody pelny, brudnej wody pusty i mop w odpowiedniej pozycji) (trzeba podpompowac pompką inaczej caly czas ON)
  - platform: gpio
    name: "Przyciski 1 - Mopowanie / Turbo"
    pin: 
      number: GPIO21
      mode:
        input: true
        pulldown: true
    on_multi_click:
      # Krótkie naciśniecie guzika
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          # Brak czystej wody - podciąganie
          - if:
              condition:
                - binary_sensor.is_on: sensor_brak_wody
              then:
                - script.execute: podciaganie_wody
          - if:
              condition:
                - binary_sensor.is_off: sensor_brak_wody
              then:
                - switch.toggle: switch_mopowanie
          - if:
              condition:
                - switch.is_on: switch_mopowanie_turbo
              then:
                - switch.turn_off: switch_mopowanie_turbo
          # Dodatkowo kiedy wlaczone mopowanie to ma wylaczyc

      # Długie naciśnięcie guzika
      - timing:
          - ON for at least 1.5s
        then:
          # Brak czystej wody - podciąganie
          - if:
              condition:
                - binary_sensor.is_on: sensor_brak_wody
              then:
                - script.execute: podciaganie_wody
          - if:
              condition:
                - binary_sensor.is_off: sensor_brak_wody
              then:
                - switch.toggle: switch_mopowanie_turbo
          - if:
              condition:
                - switch.is_on: switch_mopowanie
              then:
                - switch.turn_off: switch_mopowanie


# Przyciski 2 --> Zbieranie
  - platform: gpio
    name: "Przyciski 2 - Zbieranie"
    pin: 
      number: GPIO19
      mode:
        input: true
        pulldown: true
    # Po nacisnieciu guzika
    on_press:
      then:
        - switch.toggle: switch_zbieranie


# Przyciski 3 --> Czyszczenie (tylko kiedy w pozycji pionowej i pusty zbiornik brudnej wody)
  - platform: gpio
    name: "Przyciski 3 - Czyszczenie"
    pin: 
      number: GPIO18
      mode:
        input: true
        pulldown: true
    # Po nacisnieciu guzika
    on_press:
      then:
        - if:
            condition:
              - binary_sensor.is_on: sensor_brak_wody
            then:
              - script.execute: podciaganie_wody
        - if:
            condition:
              - binary_sensor.is_off: sensor_brak_wody
            then:
              - switch.toggle: switch_czyszczenie


# Przyciski 4 --> Zmiana języka
  - platform: gpio
    name: "Przycisk 4 - Zmiana języka"
    pin: 
      number: GPIO17
      mode:
        input: true
        pulldown: true
    # Po nacisnieciu guzika
    on_press:
      then:
        - number.increment: language
        - display.page.show: oled_mowa_info
        - dfplayer.play_folder:
            folder: !lambda 'return (id(language).state);'
            file: 1
        - delay: 2s
        - display.page.show: oled_gotowy


# Czujnik - Brak wody (podlaczenie do chipu daje wysokie 3.3v na signal)
  - platform: gpio
    name: "Sensor - Woda"
    id: sensor_brak_wody
    pin: 
      number: GPIO36
      mode:
        input: true
    filters:
      - delayed_on: 2s
      - delayed_off: 2s


# Czujnik - Brudna woda (zwykłe łączenie poprzez wode, nie mozna pulldown: true bo za małe napiecie płynie przez wode, trzeba filtrowac skoki napiecia filtrem)
# Bez pulldown ON na pustym zbiorniku
# Z pulldown OFF na pustym i OFF na pelnym
# Zamienione na ADC
  - platform: template
    name: "Sensor - Brudna woda"
    id: sensor_brudna_woda
    lambda: |-
      if (id(sensor_brudna_woda_adc).state > 0.4)
        return true;
      else if (id(sensor_brudna_woda_adc).state < 0.4)
        return false;
    filters:
      - delayed_on: 10s
      - delayed_off: 1s


# Czujnik - Przechyłu (zwykły przełącznik potrzeba pulldown, bez pulldown czasami glupieje)
  - platform: gpio
    name: "Sensor - Przechył"
    id: sensor_przechyl
    pin: 
      number: GPIO13
      mode:
        input: true
        pulldown: true
    # Po nacisnieciu guzika
    on_press:
      then:
        - switch.turn_off: switch_czyszczenie
    on_release:
      then:
        - switch.turn_off: switch_mopowanie
        - switch.turn_off: switch_mopowanie_turbo
        - switch.turn_off: switch_zbieranie

What is the problem?

Welcome John.

You can try expressing the action using the lambda syntax. That can be more flexible (or even required) if you are not using a constant value.

You may also need to divide by 100.

The problem is when i put that lambda function i get only number but to set level i need to have “%” character at the end.

I want to have option to control speeds throught webgui without flash again esp32 to change speed

Same way as change light brightness from device itself webgui, not in homeassistant. Im trying to use number component so i can provide any number from 1 to 100 to change speed or light brightness

So then did you try the id(mopowanie_predkosc_silnik1).set_level() approach per my link?

Can you provide a example how to use it?
id(mopowanie_predkosc_silnik1).set_level()
how i can put there a number template? to set the speed from webgui

            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (id(mopowanie_predkosc_silnik1).set_level());'

not working

you mean like that?

- lambda: !lambda |-
                id(silnik_1_pwm).set_level(id(mopowanie_predkosc_silnik1).state);

not working

even i was trying something like that

            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (it.printf("%.0f%", id(mopowanie_predkosc_silnik1).state));'

not working

how to put with lambda sensor state plus extension like ‘s’ or ‘%’ because its required for set_level

!lambda 'return (id(mopowanie_predkosc_silnik1).state, "%");'

got error
:418:53: error: cannot convert ‘const char*’ to ‘float’ in return

this code

            - output.set_level:
                id: silnik_1_pwm
                level: !lambda 'return (id(mopowanie_predkosc_silnik1).state);'

provide only number for level: but dont have ‘%’ extension and level: need %

I use it this way. I’m on the phone, so you’ll need to fix the indentation.


      - lambda: |-
                auto call = id(fan_speed_pc).make_call();
                call.set_value(id(test_round).state + 5);
                call.perform();
             


1 Like

No it isn’t.

- output.set_level:
    id: silnik_1_pwm
    level: !lambda |-
      return id(mopowanie_predkosc_silnik1).state / 100.0;
1 Like

Thank you.

set_level: can be percentage 1-100% and number from 0.0 - 1 …

how i can accomplish same thing but with delay?

above method only works for level

Lambda on the seconds or minutes as appropriate:

                  - delay: 
                      seconds: !lambda 'return (id(mopowanie_czas_pompka1).state);'

says its required ‘float’

Oh, this is a delay action. In that case it needs to be in milliseconds:

- delay: !lambda 'return id(mopowanie_czas_pompka1).state * 1000;'
1 Like

You saved me lot of time. Thank you :slight_smile:

1 Like

Using a lambda action rather than the output.set_level action should be like this I think… For your reference.

button:
  - platform: template
    name: "Template Button"
    on_press:
      # As lambda.
      - lambda: |-
          id(silnik_1_pwm).set_level(id(mopowanie_predkosc_silnik1).state / 100.0);
      # as set level action.
      - output.set_level:
          id: silnik_1_pwm
          level: !lambda |-
            return id(mopowanie_predkosc_silnik1).state / 100.0;

You could also break down the lambda action a bit more how walberjunior suggested.

Personally I would probably go with how Troon has solved it as it’s probably the most readable and easy to follow/implement syntax. The lambda approach may come in handy for more complex use cases…