Can't set LVGL Spinbox to initial value from sensor

Hi, I’m trying to follow the example in the LVGL cookbook aorund climate control.
I’ve also read the issue on GitHub about using on_change.
But the spinbox always starts with the lower range value no matter what I do (10 in the code below).
How do I get the initial value to be what is from the sensor?

This is my sensor code (just added the lmbda to see the value which is always correct)

  - platform: homeassistant
    id: office_thermostat
    entity_id: climate.office
    attribute: temperature
    on_value:
      - lvgl.spinbox.update:
          id: spinbox_id
          value: !lambda return x;
      - lambda: |-
          char temp_str[32];
          snprintf(temp_str, sizeof(temp_str), "%.2f", x);  // Format float to string with 2 decimal places
          ESP_LOGI("Temperature", "Temperature: %s", temp_str);

and this is my widget code

    - id: thermostat_control
      widgets:
        - obj:
            align: BOTTOM_MID
            y: -50
            layout:
              type: FLEX
              flex_flow: ROW
              flex_align_cross: CENTER
            width: SIZE_CONTENT
            height: SIZE_CONTENT
            widgets:
              - button:
                  id: spin_down
                  on_click:
                    - lvgl.spinbox.decrement: spinbox_id
                  widgets:
                    - label:
                          text: "-"
              - spinbox:
                  id: spinbox_id
                  align: CENTER
                  text_align: CENTER
                  width: 50
                  range_from: 10
                  range_to: 35
                  step: 0.5
                  rollover: false
                  digits: 3
                  decimal_places: 1
                  on_change:
                    then:
                      - homeassistant.action:
                          action: climate.set_temperature
                          data:
                            temperature: !lambda return x;
                            entity_id: climate.office
              - button:
                  id: spin_up
                  on_click:
                    - lvgl.spinbox.increment: spinbox_id
                  widgets:
                    - label:
                        text: "+"

Many thanks in advance
Dave

Hi,

A quick update. I changed the sensor code to the following and it now works, but not sure I’m doing this properly or even if I have to do this:

  - platform: homeassistant
    id: office_thermostat
    entity_id: climate.office
    attribute: temperature
    on_value:
    - lambda: |-
        float val = roundf(x * 2.0f) / 2.0f;  // Round to nearest 0.5
        int scaled = (int)(val * 10);         // Scale for 1 decimal place
        lv_spinbox_set_value(id(spinbox_id), scaled);
        lv_obj_invalidate(id(spinbox_id));    // Force redraw

I have another small problem, which I’m sure I’ve seen being discussedd, but I can’t fine the link again.

The up and down increments do not appear to adjust the decimal part, only the number digits and only when I place the cursor on them - is this supposed to work like this?

BTW all this LVGL stuff is excellent, thanks for all the hardwork.

Dave

Another update,

So I made the spin box much bigger and now the decimal part work, but not sure why it wasn’t working in the original exmaple provided. I had to make the spin box font 36 before it would work.

Dave