Setup -
I have capacitive soil sensor plugged to Wemos d1 mini which is connected to battery.
I am using Esphome via MQTT.
Problem -
Whenever Wemos goes to deep sleep i get “NaN” or “Unavailable” for plant sensor and i would like to get “last known value” instead, so not to wait few hours to read the data.
Is there a HA template i can use to read last known value and show instead of “unavailable” while in deep sleep?
HA sensor code
- platform: mqtt
name: Plant 1 Soil Humidity
state_topic: "wemos_plantmonitor/sensor/plant_1_saturation/state"
unit_of_measurement: "%"
Esphome code
mqtt:
discovery: true
discovery_prefix: homeassistant
client_id: plantsensor_1
broker: ****
username: ****
password: ****
birth_message:
topic: wemos_plantmonitor/status
payload: online
will_message:
topic: wemos_plantmonitor/status
payload: offline
on_message:
topic: wemos_plantmonitor/ota_mode
then:
- if:
condition:
lambda: 'return x == "ON";'
then:
- deep_sleep.prevent: deep_sleep_1
- if:
condition:
lambda: 'return x == "OFF";'
then:
- deep_sleep.enter: deep_sleep_1
deep_sleep:
id: deep_sleep_1
run_duration: 1min
sleep_duration: 30min