Sensor value reference

I need to check and store the minimum value of an analogue sensor (smoke) to use it as ground reference. To do this, I think to use a slider as lowest value memory (start at maximum, then an automation read the sensor value and, if lower, modify the slider to the latest lower value) and second automation to check the difference between the actual value and the slider value.
Do you have any other idea especially to check and store the lowest sensor value?

I have addes the following code which doesn’t work yet, if you know how to correct it, please let me know:

input_slider R1SL1:
  slider1:
    name: Smoke_Ground
    initial: 1023
    min: 0
    max: 1023
    step: 1

automation:
- alias: R1_smoke_ground
  trigger:
    platform: numeric_state
    entity_id: sensor.R1_gas
    below: '{{numeric_state.input_slider.slider1}}'
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.slider1
      value: '{{ numeric_state.sensor.R1_gas }}'
      
- alias: R1_smoke_alarm
  trigger:
    platform: numeric_state
    entity_id: sensor.R1_gas
    above: '{{numeric_state.input_slider.slider1 + 100}}'
  action:
    service: homeassistant.turn_on
    entity_id: switch.R1_REL2

Thank you

Is it possible to keep a sensor value into a variable? How to do this through configuration.yaml file?

Did you try the Min/Max sensor? Also, take a look at the Statistics sensor.

Thank you, min/max is about at least two entities, so it doesn’t help, but statistic seems interesting and may be useful for me.

I succeed with statistics sensor, thanks. The code is the following, may be it can help other people:

sensor arduino_stat:
  platform: statistics
  entity_id: sensor.arduino_A0
  name: arduinostat

sensor x1:
  - platform: template
      sensors:
        analog:
          value_template: '{{ "%.0f"|format((states.sensor.arduino_a0.state | float) - (states.sensor.arduinostat_mean.attributes.min_value | float)) }}'

Please, can you help me in this?