I have a simple lcd menu set up with esphome on a lcd_pcf8574.
It’s connected with a rotary encoder which controls the menu.
It is all working perfectly. I can operate simple menu items.
If I read Display Menu — ESPHome
correct I can create a custom menu item. I just can’t get it to work. Can anyone share a working example?
lcd_menu:
items:
- type: custom
immediate_edit: false
text: 'My Custom'
value_lambda: 'return to_string(some_state);'
on_next:
then:
lambda: 'some_state++;'
on_prev:
then:
lambda: 'some_state--;'
The example is not working out of the box.
error: 'some_state' was not declared in this scope
value_lambda: 'return to_string(some_state);'
^~~~~~~~~~
How can I declare variable some_state the best way to get is minimalistic example working?
Below some config snapshots:
display:
- platform: lcd_pcf8574
id: my_lcd
dimensions: 20x4
i2c_id: bus_a
address: 0x27
update_interval: 1000ms
user_characters:
- position: 0
data: # mark_back symbol
- 0b00100
- 0b01000
- 0b11110
- 0b01001
- 0b00101
- 0b00001
- 0b11110
- 0b00000
lcd_menu:
id: my_lcd_menu
display_id: my_lcd
active: false
mode: rotary
mark_back: 0x08
mark_selected: 0x3e
mark_editing: 0x2a
mark_submenu: 0x7e
on_enter:
then:
lambda: 'ESP_LOGI("display_menu", "root enter");'
on_leave:
then:
lambda: 'ESP_LOGI("display_menu", "root leave");'
items:
- type: command
text: 'Show Main'
on_value:
then:
lambda: |-
<blah blah>
- type: command
text: 'start full cycle'
on_value:
then:
<blah blah>
- type: menu
text: 'Manual control'
on_enter:
then:
lambda: 'ESP_LOGI("display_menu", "enter: %s", it->get_text().c_str());'
on_leave:
then:
lambda: 'ESP_LOGI("display_menu", "leave: %s", it->get_text().c_str());'
items:
- type: back
text: 'Back'
- type: label
text: !lambda |-
<blah blah>