I’m making a simple boot screen for my ESP32 and I want to display some text sensors. I can’t figure out how to get the text sensors onto the display. I’m using the new LVGL library so there are not any examples of this online.
You can see I tried lvgl.label.update but that didn’t work. The text labels just stay their default values.
text_sensor:
- platform: wifi_info
ip_address:
name: "IP Address"
entity_category: diagnostic
ssid:
name: "Connected SSID"
entity_category: diagnostic
mac_address:
name: "Mac Address"
entity_category: diagnostic
- platform: version
id: esphome_version
name: "ESPHome Version"
hide_timestamp: true
on_value:
then:
- lvgl.label.update:
id: esphome_version_label
text: !lambda |-
return ("ESPHome Version: " + id(esphome_version).state).c_str();
lvgl:
...
top_layer:
widgets:
- obj:
id: boot_screen
layout:
type: flex
flex_flow: COLUMN_WRAP
width: 100%
height: 100%
bg_color: 0xffffff
bg_opa: COVER
radius: 0
pad_all: 5
widgets:
- img:
src: boot_logo
antialias: true
pad_bottom: 10
- label:
text: "IP Address: 0.0.0.0"
- label:
text: "Mac Address: 00:00:00:00:00:00"
- label:
text: "Connected SSID: nonet"
- label:
text: "WiFi Strength: 0%"
- label:
id: esphome_version_label
text: "ESPhome Version: 0.0"
- label:
text: " "
- label:
text: " "
- label:
text: " "
- label:
text: " "
- label:
text: " "
- btn:
radius: 15
width: 100
height: 60
checkable: true
widgets:
- label:
text_color: 0xFFFFFF
align: center
text: "OK"
on_press:
- lvgl.widget.hide: boot_screen
There’s some examples here:
.gitignore
# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case.
# You can modify this file to suit your needs.
/.esphome/
/secrets.yaml
/wifi.yaml
Indicator.yaml
---
substitutions:
name: indicator
friendly_name: "Indicator LVGL"
esphome:
name: indicator
friendly_name: "${friendly_name}"
name_add_mac_suffix: false
platformio_options:
build_unflags: -Werror=all
This file has been truncated. show original
cat.jpg
����JFIF``��C !"$"$��C���@"�� ��?!1AQa"2q����#BRb��3��$Cr�t������4!1AQ"aq���#���23BR���?����)�lV
�) �jť-!�cj�)��6=h̼9v�e�UlFO �/�G|zTe%I�-���N�O�T�;ր뚐�J��:�� ⭅�b2:Jl�zإ2��R0GZ�R�+1J�(�?���8$��� ���V���U@��Z�U7r�?jC�����YǓ��dI4�"���@�&����k�fB�IPz�:��F�MJO��/�<��ަ{M��tm
��N�X-�L��ߙ�w�p>�'�������
��E��slV`R�Y�*�!�Vr�X���B1Z#jY�ii�����i�����c�"L���A�4JA��7#zt@��N)�IS�Mj���T�j����R����B%�l
�[�́��+mE!ͨ���ZQN(��\՛��y����o;�2}�����t)��*���4�_V�T2)~Fp(7�ۖCP��`�p���LY�s6�.}ES����I�M%�{��<�:�O~��u����3�$��J=}%��a$2+y�<�jȯ߮9��&iΨM����]iڌ�w�n\c#�D�3������
�3��A�'
Xj6l/-�ge¶0�G��U�.�2Z�]\���h����i�2�����rY4٤^N\Ȭc�l����Ю�%�o1�ެ�KUnYÔ$���މ�θy&2�L �Վ٨��R��a��ٗ"���ۑyHlu�j����t�US��دPE�:vm`�i$+�3�=j� ���߆�bc�.����(��$��}Ӵ�O3�B��ܒI��A��I<��P��^�n�c����j�z����K�@�I� ���:x���m�3�r[S���{gX�����f�.��
�����?_�N�!,����D�q���yQ�7��b$x���'�P���^��Ki�^��eޟ��X��3<�rIf&�� Ѭ��e!RF��}+��i�'"Z1$l
~��o��
���lt� 9.UՊ.��U�=J��#{����xx��Ϟ��;
��ۿ��s��'��Pj�Fc�f��tڐ�� ��Μ_,�OCHC7��ƛp1N����Ҡ\�$�m����D"��p��8�8�V�K�k�'�V+X�!>u���!(V�mKQLOJ�
q��S�';r�SOAo�m̫���hލi�J���
�m���G�3x$�Hzn��9��?b+�{/�y�y� 1p���)�j��2�Y�1��o�
���8WP����K�<����B�84����W��������GYd��8�� ��Hb�Ү�ŵ���W 8���(��i��Ų�{s2)���a���10̓��a�=h]�H��^f��c�2�|��{yc8�汦+��
���cm��W(��}�Kk,`s����M����/=̲��͌��ck�MpZ��~J��5��c�����U�;��c��=FZ�.�e�9@��]ɠZ��rjK�O/.ΰf���i$���gl��8xL��nR{P'��#d�F�=i$���"Ys��hI0�$���e-�.9#�QB��y$e{��Xsnޟ/Z3Ú�����;�5(����h�gm�(��/�%��]�d`�P=�����t�
e�)=1!�*KF�He�]�ڶ�F�|(��0�`sv��[�i.Ҥ��84�9[1kr�I�<���Y�{���+�i�!�>���ڃA�����P�l���7��l��D&=�$~U���
This file has been truncated. show original
There are more than three files. show original
I have used these example to learn how the new LGVL component works. Unfortunately there are now examples here of how to get a text sensor to display
I don’t have such a display, so I’m just shooting the breeze, but have you tried following the example format?
This example seems to use snprintf()
to format the text, maybe try something like that:
.gitignore
# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case.
# You can modify this file to suit your needs.
/.esphome/
/secrets.yaml
/wifi.yaml
t-embed.yaml
# Before asking any questions - read the docs!: https://deploy-preview-3510--esphome.netlify.app/components/lvgl.html
esphome:
name: t-embed
friendly_name: LVGL Test on T-Embed
platformio_options:
board_build.flash_mode: dio
esp32:
board: esp32-s3-devkitc-1
This file has been truncated. show original
I tried that and it didn’t work. I think it’s more about what command to use to update the boot screen and when.
My example code should also work using the lvgl.label.update command but it does not.
I just need a simple command to update a page as it loads with existing text sensors. There are no existing example of this I can find.
You don’t need the screen I have any LVGL screen could be used for this or even the VNC display driver. I use the VNC driver to test LVGL code on a PC running Windows and also on my Linux PC.
Clyde @clydebarrow I hate to ask you this one directly but this seems to be something that is missing from the LVGL documentation.
Most things in ESPhome take real time data from sensors and push it up to the UI. In this case I want data (text sensors) that are already defined (suchs as the ESPhome version) to go to the UI. I think this is a timing thing as this data could be pulled in as the LVGL page is loaded for the first time.
I just don’t exactly know how to do this.
Use lvgl.label.update
- see the docs.
I have the lvgl.label.update working fine. I just need to know what to trigger it on.
on_value didn’t work so I ended up using an on_boot command. Let me know if there is a better way to do this
For reference this works.
on_boot:
priority: -100
then:
- lvgl.label.update:
id: esphome_version_label
text:
format: "ESPHome Version: %s"
args: [ 'id(esphome_version).state.c_str()' ]
- delay: 60s
- lvgl.widget.hide: boot_screen
That’s got nothing to do with LVGL then, best ask in the Discord #general support channel.
People over on Discord gave me this. It’s works well and is very simple. I update the SSID with a wifi on.value like this
sensor:
# Reports the WiFi signal strength in %
- platform: copy
id: wifi_signal_db_percent
source_id: wifi_signal_db
name: "WiFi Strength"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: diagnostic
on_value:
then:
- lvgl.label.update:
id: wifi_signal_db_percent_label
text:
format: "Wi-Fi Strength: %s"
args: [ 'id(wifi_signal_db_percent).state.c_str()' ]
lvgl:
...
widgets:
- obj:
id: boot_screen
layout:
type: flex
flex_flow: COLUMN_WRAP
width: 480px
height: 480px
text_font: roboto24
scrollbar_mode: 'off'
bg_color: 0xffffff
bg_opa: COVER
radius: 0
pad_all: 5
widgets:
- label:
id: ip_address_label
text: "IP Address:"
- label:
text:
format: "MAC Address: %s"
args: [ 'id(mac_address).state.c_str()' ]
- label:
id: connected_ssid_label
text: "Connected SSID:"
- label:
id: wifi_signal_db_percent_label
text: "WiFi Strength: 0%"
- label:
text:
format: "ESPHome Version: %s"
args: [ 'id(esphome_version).state.c_str()' ]