Need help for lvgl button, to switch a zigbee or matter light

Hello, I can’t get this example to work. I’m not a programmer. I would be grateful for any help. The output component is reporting an error.

INFO ESPHome 2025.12.0-dev
INFO Reading configuration /config/esphome/zentraleinheit01.yaml...
INFO Detected timezone 'Europe/Vienna'
Failed config

light.binary: [source /config/esphome/zentraleinheit01.yaml:458]
  
  'output' is a required option for [light.binary].
  platform: binary
  name: remote_light01
  id: remote_light01
  on_turn_on: 
    then: 
      homeassistant.action: 
        service: light.turn_on
        data: 
          entity_id: light.tischzentrale01
  on_turn_off: 
    then: 
      homeassistant.action:

Here is my current configuration.

binary_sensor:
#########
#text_sensor:?
######### für licht remote button
  - platform: homeassistant
    id: tischzentrale01
#    widget: light_btn01
    entity_id: light.tischzentrale01
#    trigger_on_initial_state: true
#    publish_initial_state: true # wird entfernt
###########
  - platform: homeassistant
    name: "tischzentrale01"
    id: tischzentrale01_button01
    entity_id: light.tischzentrale01
    on_state:
      then:
        if:
          condition:
            binary_sensor.is_on: tischzentrale01_button01
          then:
            - lvgl.widget.update:
                id: lvgl_button01_icon
                text_color: 0xFFFF00
            - lvgl.widget.update:
                id: lvgl_button01
                state:
                  checked: true
          else:
            - lvgl.widget.update:
                id: lvgl_button01_icon
                text_color: 0xB6B6B6
            - lvgl.widget.update:
                id: lvgl_button01
                state:
                  checked: false

output:
  - platform: ledc
    pin: GPIO22
    id: backlight_pwm
    frequency: 1000Hz
########## für licht ??????
#  - platform: template
#    id: remote_relay01
#    type: float
#    write_action:
#      if:
#        condition:
#          light.is_on: remote_light01
#        then:
#          - light.turn_on: tischzentrale01_button01
#        else:
#          - light.turn_off: tischzentrale01_button01
light:
########## für licht neu
  - platform: binary
    output: remote_relay01
    name: "remote_light01"
    id: remote_light01
    on_turn_on:
      then:
        homeassistant.action:
          service: light.turn_on
          data:
            entity_id: light.tischzentrale01
    on_turn_off:
      then:
        homeassistant.action:
          service: light.turn_off
          data:
            entity_id: light.tischzentrale01

lvgl: #...sniped

        - button:
            height: 223
            checkable: true
            id: lvgl_button01
            widgets:
              - label:
                  #text_font: light40
                  align: top_left
                  text: $lightbulb
                  id: lvgl_button01_icon
              - label:
                  align: bottom_left
                  text: "Center Light"
                  long_mode: dot
            on_click:
              light.toggle: remote_light01

What would be the easiest way to do it? Thankx for any help!

Light needs output component (even if you don’t use it).
You can use dummy gpio output on some unused pin or binary template output.

output:
  - platform: template
    id: dummy_output
    type: binary
1 Like

thank you very much, but now i need a write_action.
it is to difficult for me now, i am new with programming

esphome does not compile;)

INFO ESPHome 2025.12.0-dev
INFO Reading configuration /config/esphome/zentraleinheit01.yaml...
INFO Detected timezone 'Europe/Vienna'
Failed config

output.template: [source /config/esphome/zentraleinheit01.yaml:434]
  
  'write_action' is a required option for [output.template].
  platform: template
  id: remote_relay01
  type: binary

Just add it there

  platform: template
  id: remote_relay01
  type: binary
  write_action:
1 Like

yes thanks, i have read, but i have no idea for the explicit write_action :man_facepalming:

  - platform: template
    id: remote_relay01
    type: binary
    write_action:
      - output.set_level:
          id: remote_light01
          level: !lambda return state;  # i dont now if this is correct?

this is the compile log now

INFO ESPHome 2025.12.0-dev
INFO Reading configuration /config/esphome/zentraleinheit01.yaml...
INFO Detected timezone 'Europe/Vienna'
Failed config

output.template: [source /config/esphome/zentraleinheit01.yaml:434]
  platform: template
  id: remote_relay01
  write_action: 
    then: 
      - output.set_level: 
          
          ID 'remote_light01' of type light::LightState doesn't inherit from output::FloatOutput. Please double check your ID is pointing to the correct value.
          id: remote_light01
          level: !lambda |-
            return state;
  type: binary

I got completely lost now about what are you trying to do.
Light component controls output, but now here you are trying to control light from that output.

Since your homeassistant action is coded on light component, you should leave the output write_action empty.

with an empty write_action: i become this faild config :man_facepalming:

INFO ESPHome 2025.12.0-dev
INFO Reading configuration /config/esphome/zentraleinheit01.yaml...
INFO Detected timezone 'Europe/Vienna'
Failed config

output.template: [source /config/esphome/zentraleinheit01.yaml:434]
  platform: template
  id: remote_relay01
  type: binary
  
  expected a dictionary.
  write_action: 

and i am confused now, whats the right id: ect

It’s stubborn :grin:
Try like this:

  - platform: template
    id: remote_relay01
    type: binary
    write_action:
      - lambda: |-
1 Like

you are the best :+1: :cowboy_hat_face: :grinning:
it has finish compiled but the light does not switch on or off in real :joy:

[19:04:14.907][C][homeassistant.sensor:031]:   Entity ID: 'sensor.tempkaminwohnen_temperature'
[19:04:18.295][W][component:481]: lvgl took a long time for an operation (234 ms)
[19:04:18.296][W][component:484]: Components should block for at most 30 ms
[19:04:20.826][D][light:090]: 'remote_Light01' Setting:
[19:04:20.826][D][light:103]:   State: ON
[19:04:25.666][D][light:090]: 'remote_Light01' Setting:
[19:04:25.666][D][light:103]:   State: OFF
[19:04:34.551][I][safe_mode:042]: Boot seems successful; resetting boot loop counter
[19:04:34.556][D][esp32.preferences:149]: Writing 1 items: 0 cached, 1 written, 0 failed
[19:04:37.848][D][sensor:135]: 'Battery Percentage': Sending state 92.48881 % with 1 decimals of accuracy
[19:04:38.454][D][sensor:135]: 'Battery Voltage': Sending state 8.06250 V with 2 decimals of accuracy
[19:04:38.455][D][sensor:135]: 'Battery Current': Sending state 0.17294 A with 3 decimals of accuracy

Is your code for light using syntax like this?

    on_turn_on:
      - homeassistant.action:
          service: light.turn_on
          data:
            entity_id: light.tischzentrale01
1 Like

this is my light:

  - platform: binary
    output: remote_relay01
    name: "remote_Light01"
    id: remote_light01
    on_turn_on:
      - homeassistant.action:
          service: light.turn_on
          data:
            entity_id: light.tischzentrale01
    on_turn_off:
        homeassistant.action:
          service: light.turn_off
          data:
            entity_id: light.tischzentrale01

on_turn_off is missing -

1 Like

yes thanks, i have also seen now and it does clean and compile now :slightly_smiling_face:

1 Like

i dont know, if this is right? i can only turn on and off from homeassistant self

[20:15:21.857][D][homeassistant.binary_sensor:026]: 'light.tischzentrale01': Got state ON
[20:15:21.858][D][binary_sensor:039]: 'tischzentrale01': New state is ON
[20:15:23.908][D][homeassistant.binary_sensor:026]: 'light.tischzentrale01': Got state OFF
[20:15:23.908][D][binary_sensor:039]: 'tischzentrale01': New state is OFF
[20:15:31.051][D][main:393]: LVGL resuming
[20:15:31.051][D][light:090]: 'Display Backlight' Setting:
[20:15:31.051][D][light:103]:   State: ON
[20:15:31.051][D][light:141]:   Transition length: 0.2s
[20:15:32.321][D][light:090]: 'remote_Light01' Setting:
[20:15:32.323][D][light:103]:   State: ON
[20:15:33.220][D][light:090]: 'remote_Light01' Setting:
[20:15:33.220][D][light:103]:   State: OFF

possibly is also an error in my binary_sensor: sektion?

#########
#binary_sensor or text_sensor: ?
######### für licht remote button
  - platform: homeassistant
    id: tischzentrale01
#    widget: lvgl_button01
    entity_id: light.tischzentrale01
    trigger_on_initial_state: true
#    publish_initial_state: true # wird entfernt
###########
#  - platform: homeassistant
#    name: "tischzentrale01"
#    id: tischzentrale01_button01
#    entity_id: light.tischzentrale01
#    on_state:
#      then:
#        if:
#          condition:
#            binary_sensor.is_on: tischzentrale01_button01
#          then:
#            - lvgl.widget.update:
#                id: lvgl_button01_icon
#                text_color: 0xFFFF00
#            - lvgl.widget.update:
#                id: lvgl_button01
#                state:
#                  checked: true
#          else:
#            - lvgl.widget.update:
#                id: lvgl_button01_icon
#                text_color: 0xB6B6B6
#            - lvgl.widget.update:
#                id: lvgl_button01
#                state:
#                  checked: false

######## abgekürzt
#    on_value:
#    - lvgl.widget.update:
#        id: btn_lightbulb
#        state:
#          checked: !lambda return x == "on";
#          disabled: !lambda return x == "unavailable" || x == "unknown";
#
#    - lvgl.label.update:
#        id: lbl_lightbulb
#        text:
#          format: "%s"
#          args: ['x == "on" ? "\U000F0335" : "\U000F0336"']
  - platform: homeassistant
    id: tischzentrale01
#    widget: lvgl_button01
    entity_id: light.tischzentrale01
    trigger_on_initial_state: true
#    publish_initial_state: true # wird entfernt
###########

Then binary sensor is fine.
Have a look at HA logs when you turn esphome light on/off…

1 Like

If all you want to do is toggle the HA light when the button is pressed, just put that action (service: light.toggle) directly in the on_click trigger. It’s not clear to me why you have the light component in ESPHome if your device is not directly controlling a light.

1 Like

@clydebarrow i does not understand for details, what you mean, sorry i am not a programmer,
but i have this problem since days and cannot solve this :man_facepalming:
thanks for any help.

is this remote-button example in the cookbook actualy? LVGL: Tips and Tricks - ESPHome - Smart Home Made Simple
for me it does not work now, i think the error is in my yaml-code.

thats my binary_sensor:

binary_sensor:
  - platform: homeassistant
    id: remote_tischzentralemitte
    entity_id: light.tischzentralemitte
    trigger_on_initial_state: true
#    publish_initial_state: true # wird entfernt
    on_state:
      then:
        lvgl.widget.update:
          id: lvgl_button01
          state:
            checked: !lambda return x;

thats my button in lvgl

        - button:
            height: 220
            align: top_right
            checkable: true
            id: lvgl_button01
            widgets:
              - label:
                  #text_font: light40
                  align: center
                  text: "tischzentralemitte"
                  id: lvgl_button01_icon
              - label:
                  align: bottom_mid
                  text: "wintergarten"
                  long_mode: dot
            on_click:
              - homeassistant.service:
                  service: light.toggle
                  data:
                    entity_id: light.tischzentralemitte

That looks basically correct. What part isn’t working?

Monitor the ESPHome logs while you turn the light on and off via HA, you should see lines (at debug level) like this:

[21:15:28][D][homeassistant.binary_sensor:026]: 'light.patio_light_light1': Got state OFF

And the checked state of your LVGL button should change. If that works, but clicking the button doesn’t toggle the light, then it’s likely you haven’t granted your ESPHome device permission to perform HA actions.

2 Likes

@clydebarrow you are my king! :cowboy_hat_face: :smiley:

it was the problem with the permissions!
thank you very much, for your help you are the best

1 Like