Keeping the latest sensor data, even when the sensor is unaviable

Hello,

I am using a Wemos D1 with tasmota flashed and the Home Assistant discovery enabled.
I am reading with the Wemos every 10min some sensor data, and then he is falling into deepsleep. The Wemos is sending the data to HA and it is displaying in Lovelace, but when the Wemos go back into deepsleep the sensor data switch to unviable.

It is possible to show the latest data over the MQTT Discovery? Over a option, template or a costume entity?

Before I integrated all data by myself over the configuration.yaml and without HA discovery enabled in tasmota.

Greeting and thanks for helping!

Disable LWT (last will and testament) messaging. Not sure how you do that in Tasmota. In ESPhome you just use blank LWT topics.

The other option is to create templates sensors that store the last known state. There’s an example here: Lovelace UI official Gauge Card: Invalid numeric figure

It is not possible to change the LWT message with the HA discovery enabled.

So I’m switching back to my own Integration :sweat_smile:

THX

Btw this is working like a charm :ok_hand:t4: thanks for that!

  - platform: template
    sensors:
        wetterstation_pm10:
          friendly_name: 'Feinstaub PM10'
          icon_template: "mdi:air-filter"
          unit_of_measurement: "µg/m³"
          value_template: >
                            {% if state_attr('sensor.wetterstation', 'SDS0X1')['PM10'] == 0 %}
                              {{ states('sensor.wetterstation_pm10') }}
                            {% else %}
                              {{ state_attr('sensor.wetterstation', 'SDS0X1')['PM10'] }}
                            {% endif %}

If you wish, you can reduce the template to this:

  - platform: template
    sensors:
      wetterstation_pm10:
        friendly_name: 'Feinstaub PM10'
        icon_template: "mdi:air-filter"
        unit_of_measurement: "µg/m³"
        value_template: >
          {% set pm10 = state_attr('sensor.wetterstation', 'SDS0X1')['PM10'] %}
          {{ states('sensor.wetterstation_pm10') if pm10 == 0 else pm10 }}
1 Like

Smart! Thanks