Problem converting a sensor number value to a global integer

Hi, I am trying to modify a global int using set_action from a template number:

globals:
- id: setpoint1
  type: int
  restore_value: no
  initial_value: '25'

number:
- platform: template
  name: "Setpoint accensione camino da HA"
  optimistic: true
  unit_of_measurement: °C
  min_value: 20
  max_value: 70
  initial_value: 25
  id: setpoint1_ha
  step: 1
  set_action:
    then:
      - lambda:  id(setpoint1) = id(setpoint1_ha);

the global int is used in a kind of thermostat:

sensor:
  - platform: dallas
    address: 0xb2838a4b1f64ff28
    name: "Camino"
    id: 'camino'
    on_value:
      then:
        - script.execute: avvio_camino

script:
  - id: avvio_camino
    then:
      - lambda: |-
         if (id(camino).state > id(setpoint1)) {
         id(switch1).turn_on();
         } else if (id(camino).state < (id(setpoint1) - id(isteresi1))) {
         id(switch1).turn_off();
         }

but i got the error message in lambda action when compiling:

/config/esphome/termocamino.yaml: In lambda function:
/config/esphome/termocamino.yaml:55:26: error: invalid conversion from 'esphome::template_::TemplateNumber*' to 'int' [-fpermissive]
       - lambda:  id(setpoint1) = id(setpoint1_ha);
                          ^
*** [/data/termocamino/.pioenvs/termocamino/src/main.cpp.o] Error 1
========================= [FAILED] Took 12.52 seconds =========================

I ahe tried to define the global as FLOAT, got a similar error

/config/esphome/termocamino.yaml:55:26: error: cannot convert 'esphome::template_::TemplateNumber*' to 'float' in assignment

what can I do?

Here’s some things to try (I don’t know specifc solution):

Try it like this:

    set_action:
      then:
        - globals.set:
            id: setpoint1
            value: !lambda return x;

Or try putting a .state on one/both in your lambda.

id(setpoint1).state 
id(setpoint1_ha).state 

or try wrapping one/both in an int.

int(id(setpoint1))

Or try combinations of above…

Thank you!
solved this way:

...
step: 1
  set_action:
    - globals.set:
        id: setpoint1
        value: !lambda return id(setpoint1_ha).state;
2 Likes