Publish "unknown" value of a sensor

Is there any way to intentionally publish an “unknown” value to Home Assistant?

Context: when my kettle is off the base, there is no way to know what its temperature really is.

While I am avoiding publishing any new data in this situation by using {}, HA continues to trust and display the last value, and shows a flat line graph in the history.

Here’s what I have,

tuya:
  # These datapoints need to publish here, otherwise ESPhome will convert them to a float by the time they reach the entity's on_raw_value
  on_datapoint_update:
    - sensor_datapoint: 19 # problem bitfield 
      datapoint_type: bitmask
      then:
        - binary_sensor.template.publish:
            id: kettle_absent
            state: !lambda 'return (x & 0x02);'

sensor:
  - id: current_temperature
    name: "Current Temperature"
    platform: tuya
    sensor_datapoint: 2
    device_class: temperature
    unit_of_measurement: °C
    filters:
      - lambda: |-
          if (id(kettle_absent).state) return {};
          return x;

binary_sensor:
  - id: kettle_absent
    name: "Kettle Absent"
    platform: template

[Full source]

What I’d ideally like to add is something like “on_value → then → water_heater.template.publish → UNKNOWN_VALUE”.

I think you have to return none, not the string 'none'.

Unfortunately that gives a compile error:

Compiling .pioenvs/weekett-replacement/src/main.cpp.o
/config/weekett-replacement.yaml: In lambda function:
/config/weekett-replacement.yaml:93:40: error: 'none' was not declared in this scope
   93 |           if (id(kettle_absent).state) return none;
      |                                        ^~~~
*** [.pioenvs/weekett-replacement/src/main.cpp.o] Error 1

The documentation here says “To prevent values from being published, return {}”, which does indeed suppress it publishing new values, but I want to actively publish an ‘unknown’ so HA doesn’t keep the last known value.

Did you try return NAN; ?

Brilliant, that works, thank you :slight_smile: