Tasmota integration and unavailable Deep Sleep sensors

I’m attempting to utilize a mostly no-coding-required setup of hass.io and ESP8266 sensors. I am using Tasmota (tasmota.sensors) and the latest available rbpi Hass.io images.

Mostly- it has been a great experience. I was able to get the Tasmota integration working and add entities from my ESP8266 module that has a BMx280 attached. No problems there. No coding necessary.

When I enable DeepSleepTime on tasmota, Tasmota sends out an MQTT message stating that it is powered off (LWT Offline). This is normal. Home Assistant sees this message and marks the sensor as Unavailable. This is also normal, mostly… however for these types of sensors people would like to see the last known good sensor value.

2020-12-14 07_39_03-Window

How can I fix this? Well, I know I can manually add the entity in YAML and have it ignore the LWT messages. But I think this is unintended behavior and that there should be an option within the Tasmota integration to ignore LWT or somehow otherwise make the entity sensor show the last seen value.

I have looked on the Tasmota side and I found a similar question, however the Tasmota people say they are just following the MQTT protocol and it’s not their job to break it for HA.

I’m not really plugged in to HA development so I wanted to field this question here rather than make a github issue. I’m aware I could be the problem so I wanted to ask for help first.

Thanks

Hi, same here, did you figure out any solution to this?

@elik745i
I switched over to ESPHome. I’ll share my ESPHome configuration for a BME280 sensor node, if it is of any use to anyone. The important part is that I changed the birth_message and will_message to be empty.

This has the desired effect, and it’s fine with me, however some people may want to know the status of their sensors that have gone offline. The solution would have to be within HomeAssistant ideally.

esphome:
  name: d1_1
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "xxx"
  password: "xxx"
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "D1 1 Fallback Hotspot"
    password: "xxx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxx"

ota:
  password: "xxx"
  
i2c:
  sda: 4
  scl: 5
  scan: True
  id: bus_a
  
sensor:
  - platform: bme280
    i2c_id: bus_a
    temperature:
      name: "Bedroom Temperature"
      oversampling: 16x
      id: bme_temp
    pressure:
      name: "Bedroom Pressure"
      id: bme_pressure
    humidity:
      name: "Bedroom Humidity"
      id: bme_rh
    address: 0x76
    update_interval: 60s
    
deep_sleep:
  # ...
  id: deep_sleep_1
  run_duration: 5s
  sleep_duration: 1min
  
mqtt:
  # ...
  broker: 192.168.1.234
  username: xxx
  password: xxx
  birth_message:
    topic: d1_1/status
    payload: 
  will_message:
    topic: d1_1/status
    payload: 
  on_message:
    - topic: d1_1/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: deep_sleep_1
    - topic: d1_1/sleep_mode
      payload: 'ON'
      then:
        - deep_sleep.enter: deep_sleep_1

Thanks for sharing your experience with esphome. I’m still using tasmota, my device is built around it and I need solution for that, to show when sensor was online last time and to show last data…

You can write your own YAML in Home Assistant to define a sensor from the MQTT messages. You aren’t required to use the Tasmota integration with your Tasmota device.
Maybe this helps: https://www.home-assistant.io/integrations/sensor.mqtt/

I also had the unavailable problem.

I ended up with a mqtt sensor (I have ultrasonic sensor wired to a nodemcu, in order to monitor my water tank level)

- platform: mqtt
  name: "Water tank level"
  state_topic: "tele/tasmota_A0B766/SENSOR"
  value_template: "{{ value_json.SR04.Distance }}"
  unit_of_measurement: 'cm'
  unique_id: 'tasmota_A0B766'
  force_update: true

And I removed the device from tasmota integration.

By the way, does somebody have ‘something’ to monitor the battery level ?

Yes I did the same, but it shows unavailable again:

  • platform: mqtt
    name: wstation_mqtt_windspeed
    state_topic: “tele/WStation/SENSOR”
    value_template: “{{((value_json[‘COUNTER’].C1)|float/30)|round(1)}}”
    unit_of_measurement: “m/sec” # “km/h”
    availability_topic: “tele/WStation/LWT”
    payload_available: “Online”
    payload_not_available: “Offline”

with regards to battery level I connected voltage divider to ADC and here is how to do calcs:

  • platform: mqtt
    name: wstation_mqtt_battery
    state_topic: “tele/WStation/SENSOR”
    value_template: “{{((((value_json[‘ANALOG’].A0)|float/224 - 3)*100)/(4.2-3))|round(1)}}”
    unit_of_measurement: ‘%’ # “F” if using Fahrenheit
    availability_topic: “tele/WStation/LWT”
    payload_available: “Online”
    payload_not_available: “Offline”
    device_class: battery

you have to remove availability_topic (and payload_available and payload_not_available). Before tasmota device goes offline, it sends Offline on topic .../LWT. By removing the availability_topic HA will ignore the message and will keep the sensor available.

EDIT:
Thanks for the battery level :slight_smile:

understood, thanks. checking…

I’m stuck on this too.

I removed LWT from the template as seen below but the device still shows as unavailable when sleeping (did multiple reboots as well to flush any old configs).

- platform: mqtt
    name: "Livingroom Temperature"
    state_topic: "tele/tasmota_C74A88/SENSOR"
    value_template: "{{ value_json ['AHT1X-0x38'].Temperature }}"
    unit_of_measurement: "°C" # "F" if using Fahrenheit
    device_class: temperature

Any other ideas? Thanks

You could try removing the device from tasmota integration and add a unique_id

This seems to be a problem of many. I also have a BME280 connected via Tasmota on Wemos D1mini (ESP8266). Since it always sents an offline message via MQTT LWL before DeepSleep, HA sets any sensor data to “unavailable” at this moment. I tried to search for a solution but cannot find any way to configure how HA or mosquitto (MQTT) should deal with this topic nor could I manage to get rid of these messages on Tasmota or ignore them. This is really mad as there was no problem on old Tasmotaversions that did not send LWL-Messages. Any solution for this on a Tasmota/HA-Setup?

You just manually make your sensors and have SensorRetain set to 1 in tasmota(not sure I even have retain set, I can’t check for abit). You don’t need SensorRetain.
It will hold the last value unless you restart or reload the manually configured mqtt entities.
I don’t think I have anything else special set in tasmota.

tasprt

sensor:
  - platform: mqtt
    name: "Pool Roof Temp"
    state_topic: "tele/ds1820/SENSOR"
    value_template: '{{value_json.DS18B20.Temperature}}'
    unit_of_measurement: "°C"
    icon: "mdi:coolant-temperature"
    device_class: temperature
    state_class: measurement

Hi, same problem here. The problem is, that the tasmota integration is listining on availability topic. Just before the device enters DeepSleep it send Offline, and this marks the Sensor Offline in HA.
There just two workarounds for this:

  1. configure the device manually and leave out the availibility topic (maybe with retain)
  2. do some changes in HA tasmota integration to ignore availibility if DeepSleep is detected for that device.

The first approach would also mean to disable the autodiscoved deepsleep device in HA. AFAIR you cannot prevent the device itself in tasmota not to send tasmota/discovery information OR use mqtt disvovery (SO19 Option) but not turn it off completely.

You don’t need to disable auto discovery, you just need to manually configure the mqtt sensor and leave out availability topic as you say. It will still the device in the Tasmota integration as well… the sensors will just be duplicated. So I wouldn’t name them identically.

1 Like