ESPhome sensor is interpreted as strings in HA

I have a board near my mechanical ventilation to control the setpoint of this fan. I would like to the board to report back it’s interpreted setpoint from my automations. All the automations work as expected. I’m able to adjust the setpoint. However, the value I read back in HA is interpreted as a string. I would like to be able to plot it in a graph instead.

I have the following configuration in ESP home, but I’m not sure what to change in order for it to read as a float (or integer). In the logs it even reports
“‘Fan setpoint’: Sending state 24.00000 with 1 decimals of accuracy”, which leads me to believe it actually is a float.

esphome:
  name: esphome-fancontrol

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: xxx

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:
    
#fan definition
fan:
  - platform: speed
    output: fan_pwm_output
    name: "Mechanical Ventilation"
    id: "mechanical_ventilation"
    speed_count: 100

sensor:
  platform: template
  name: "Fan setpoint"
  lambda: |-
      return id(mechanical_ventilation).speed/1;
  update_interval: 30s
    
#output    
output:
  - platform: ledc
    pin: GPIO25
    frequency: 10000 Hz
    id: fan_pwm_output

States are always strings. It just needs a unit to be graphed like that:

sensor:
  platform: template
  name: "Fan setpoint"
  lambda: |-
      return id(mechanical_ventilation).speed/1;
  update_interval: 30s
  unit_of_measurement: 'rpm' # or whatever it is

Wow thanks! That was remarkably simple.

perhaps a second question related to the configuration above. I noticed the Fan connected to the board only starts picking up on the pwm output starting at 15% and saturates above 80%, is there any way I can scale the output of the fan definition, such that 0% fan setting, corresponds with 15% pwm output, and 100% fan setting, corresponds with 80% pwm output, if that makes sense?

Not that I know of.

Not sure if this works but there is the calibrate linear
Sensor Component — ESPHome

I have never used it myself but this is what I would try:

filters:
  - calibrate_linear:
      - 0.0 -> 0.0
      - 15.0 -> 0.0
      - 85.0 -> 100.0
      - 100.0 -> 100.0

I think that could work for the value reported back to home assistant (since a filter can be applied to a sensor), but what I’m trying to achieve is that when I set the speed of the fan entity in home assistant to 100%, the corresponding output of the pwm output signal in esphome is set to 80% (for example).

I found the solution to the second problem.
The output can be altered as following:
where the max_power' corresponds with the fraction at a 100% output and min_power’ the fraction at 0% output.

#output    
output:
  - platform: ledc
    pin: GPIO25
    frequency: 10000 Hz
    id: fan_pwm_output
    min_power: 0.13
    max_power: 0.77