Forcing auto-update of a value on_change

I want the frontend to be able to set an calibration offset (don’t want to compile this to the firmware obviously, as this will be different for probably each device) and figured I could do it this way:


number:
  - platform: template
    name: "Temperature offset"
    id: temperature_offset
    optimistic: true
    min_value: -10
    max_value: 10
    step: 0.1
    restore_value: true
    initial_value: 0
    on_value: 
      then:
        - component.update: sensor_temperature

  - platform: template
    name: "Humidity offset"
    id: humidity_offset
    optimistic: true
    min_value: -25
    max_value: 25
    step: 0.1
    restore_value: true
    initial_value: 0
    on_value: 
      then:
        - component.update: sensor_humidity

sensor:
  - platform: aht10
    variant: AHT20
    temperature:
      name: "Temperature"
      id: sensor_temperature
      accuracy_decimals: 1
      filters:
        - lambda: return x + id(temperature_offset).state;
    humidity:
      name: "Humidity"
      id: sensor_humidity
      accuracy_decimals: 1
      filters:
        - lambda: return x + id(humidity_offset).state;

  - platform: ens160_i2c
    address: 0x53
    aqi:
      name: "AQI"
      id: aqi
      accuracy_decimals: 2
    eco2:
      name: "eCO2"
    tvoc:
      name: "Tvoc"
    compensation:
      temperature: sensor_temperature
      humidity: sensor_humidity

But getting the following yaml linting error:

ID 'sensor_temperature' of type sensor::Sensor doesn't inherit from PollingComponent. Please double check your ID is pointing to the correct value.

Autocomplete even helps me type it, just ends up being illegal :frowning:

It’s just an aesthetic thing of course, re-sending the value after changing the value so I don’t have to wait 60s after a value change. I’m sure this must be possible?

Maybe it doesn’t work for that component. The docs aren’t really helpful:

Please note that this only works with some component types and others will result in a compile error.

Right, shame, figured that component.update was something generic …

I’m no guru on this, but as it does seem to be a polling component, it seems component.update should work.

I wonder if it doesn’t work for sensors with multiple outputs?

Maybe there is a way to read_data() via lambda?

The developers on Discord may be of help here…

https://esphome.io/api/classesphome_1_1aht10_1_1_a_h_t10_component#a7ecc57a285e05b72b925a0d08034d68e

https://esphome.io/api/classesphome_1_1aht10_1_1_a_h_t10_component

Sadly, I don’t have discord, so that’s an avenue I can’t explore,

but if the ‘multiple-outputs’ scenario is the culprit; then it sounds like a bug and a bug-report could help resolve/discuss this.

As for the lambda; it’s for my case, just an aesthetic solution, so rather not due hackery to work around a (potential) bug ;p

1 Like

Would probably be categoried as an absent feature than a bug. So more expanding existing feature I think. If I’m correct about above.