ESPHome Sensor value after restart

Hello,
I use ESPHome to create sensor “base” from Linky, the issue is when I restart HA or the ESP the value become unavailable and HA record a crazy value at this moment in the “sensor.energy_total_daily”.
Is there a solution to avoid this issue, by example save the last value when unavailable ?
PS : Impossible to use “restore_mode: RESTORE_LAST_VALUE” in ESPHome for my sensor.

  • utility_meter:
    energy_total_usage_daily:
    source: sensor.linky_base
    cycle: daily

  • platform: template
    sensors:
    energy_total_daily:
    friendly_name: “Energy Consumed Today”
    entity_id:
    - sensor.energy_total_usage_daily
    value_template: ‘{{ (states(’‘sensor.energy_total_usage_daily’’) | float / 1000) | round(3) }}’
    unit_of_measurement: kWh
  • platform: teleinfo
    id: base
    tag_name: “BASE”
    name: “Linky - Base”
    unit_of_measurement: “Wh”
    teleinfo_id: myteleinfo

Hi
Show your ESPhome code in the preformatted text way </> minus sensitive data like your wifi password and it may stimulate some responses.

substitutions:
friendly_name: “WeMos Teleinfo”

esphome:
name: wemos

esp32:
board: esp32dev
framework:
type: arduino

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
key: “********************************”

ota:
password: “****************************”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on

i2c:
sda: GPIO21 #D2=pin 19
scl: GPIO22 #D1=pin 20
scan: True
id: bus_a

uart:
id: uart_a
rx_pin: GPIO23
#tx_pin: GPIO1
baud_rate: 1200
parity: EVEN
data_bits: 7

teleinfo:
id: myteleinfo
uart_id: uart_a
update_interval: 10s
historical_mode: true

LED

light:

  • platform: partition
    name: “${friendly_name} LED”
    id: led1
    default_transition_length: 0s
    segments:

    • id: rgb_led
      from: 0
      to: 0
  • platform: neopixelbus
    num_leds: 1
    pin: GPIO18
    name: “${friendly_name} RGB strip”
    variant: ws2812
    id: rgb_led
    default_transition_length: 0s

Sensor Configuration

sensor:

Index option Base

  • platform: teleinfo
    id: base
    tag_name: “BASE”
    name: “Linky - Base”
    unit_of_measurement: “Wh”
    icon: mdi:flash
    teleinfo_id: myteleinfo

Alot of people have been searching for the answer to this using the API. Much easier to fix if you use mqtt instead. In mqtt you just make sure the birth and last will topics are different. The value of sensor doesn’t change until device comes back available and sends a new value.

mqtt:
  # ...
  birth_message:
    topic: myavailability/topic
    payload: online
  will_message:
    topic: myavailability/anything as long as it's not topic
    payload: offline	

I don’t have an answer for using API.