Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting dropdown roller btnmatrix items by item name #52

Open
nagyrobi opened this issue Jan 25, 2024 · 5 comments
Open

Selecting dropdown roller btnmatrix items by item name #52

nagyrobi opened this issue Jan 25, 2024 · 5 comments

Comments

@nagyrobi
Copy link

nagyrobi commented Jan 25, 2024

There is:

    - lvgl.dropdown.update:
        id: dropdown_id
        selected_index: 3

which is good if we know the index number.

The corresponding HA integrations which could be used with these widgets use states which show not the index, but the name of the currently selected option.

We need a shortcut/wrapper for the action above which could be able to resolve the index from the name, something like:

    - lvgl.dropdown.select:
        id: dropdown_id
        item_name: Bassoon

Use case: with a text sensor we can retrieve the current state name from HA, and with the just call lvgl.**.select with item_name parameter to select the item with the same name.

@clydebarrow
Copy link
Owner

Can you provide an example for this? The select entity exposed to HA uses an index, not a string. Setting the value via an arbitrary text value might not work, as it would have to match exactly, so what should happen if it matches none of the options?

@nagyrobi
Copy link
Author

nagyrobi commented Jan 26, 2024

I may have ran a bit fast... :)

End goal is to present in LVGL a dropdown, roller or btnmatrix mirroring a select from HA corresponding to some other integration. Like in the examples from the cookbook, you use a switch widget in LVGL to toggle an arbitrary light switch in HA, or adjust various other entities, you need to retrieve their state first from HA with platform: homeassistant kind of sensor first.

For example you have in HA a select.ventilation_system (provided by some other integration) with some presets:

options:
  - Base
  - Mid
  - High
  - Turbo
  - Off
icon: mdi:fan
friendly_name: Ventilation presets

This select's state can only be a textual value, one of the options listed eg. state: Base

We could create a dropdown, roller or btnmatrix in LVGL with exactly these options (also see #46):

lvgl:
   ...
        - dropdown:
            id: vent_dropdown
            options:
              - Base
              - Mid
              - High
              - Turbo
              - Off

and a text sensor to retrieve the state, which would have to use a resolution function to update the dropdown't selected value by the name, since there's no index available:

text_sensor:
  - platform: homeassistant
    id: ventilation_system_select_state
    entity_id: select.ventilation_system
    on_value:
      - lvgl.dropdown.select:
          id: vent_dropdown
          item_name: !lambda return x.c_str(); #or similar

what should happen if it matches none of the options

Nothing, just a warning in ESPHome log (the chances to occur would be minimized if #46 would be possible).

Moreover, if we would have on_value for dropdown/roller/btnmatrix, we could do the reverse, update the select in HA based on the choice made here as described in #49.

@clydebarrow
Copy link
Owner

clydebarrow commented Jan 27, 2024

Just use a select linked to the roller/dropdown, and use automations in HA to sync with something else.

select:
  - platform: lvgl
    dropdown: lv_dropdown
    name: LVGL Dropdown

@nagyrobi
Copy link
Author

nagyrobi commented Jan 27, 2024

use automations in HA to sync with something else.

The above described approach would be better in the sense that the whole procedure would be done in a single place, the ESPHome node. Wouldn't require additional configs to maintain in the middleware (HA). Pretty much the same reason as why avoiding MQTT in general.

Plus afaik there's no easy way to sync entities to each other in HA (say, two selects), there's always the possibility to enter in a sync loop etc. Harder for users...

@nagyrobi
Copy link
Author

At least if we could have lambda equivalents for this. Say, consider this an advanced use case, which typically lambdas are apropriate for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants