Shelly uni sensor update issue

Just after some assistance with my obvious loack of coding knowledge.
I have a shelly uni connected to a water level sensor. This is all run by a 12v car battery that is toppped up with a solar panel.
The device during cloudy days sucks the battery too low and then powers off making the shelly uni become unavailable as a sensor.
I had thought that I could create a ‘dummy’ retained sensor in my config and then have an automation running that would keep reading valid outputs and keep a retained value. The goal is to to use this dummy sensor to ensure that I can clearly display the last known value on a dashboard. The following is the two bits of yaml I have.
In my config is the ‘dummy’ sensor.

- platform: template
        value_template: "{{ states('sensor.top_tank_water_level_adc') }}"
        friendly_name: "Retained top tank voltage"

In my automations I have built this

alias: update water tank sensor
description: ""
  - platform: state
      - sensor.top_tank_water_level_adc
  - condition: template
    value_template: "{{ is_number(state_attr('sensor.top_tank_water_level_adc', 'state')) }}"
  - service: homeassistant.update_entity
    data: {}
      entity_id: sensor.retained_sensor_value
mode: single

I’m obviously doing something wrong because the ‘dummy’ sensor doesn’t retain the last valid value.

What a pain! Maybe just ditch mqtt and use the native api with esphome instead?

Your sensor values will be retained just by adding deep_sleep: to your eshpome yaml :rocket:

Does the uni runs 24-7 or do you make use of deep_sleep at all? Might be worth to do something like this:

  run_duration: 10s
  sleep_duration: 10min

so that your device also survives cloudy days? Your 12V car battery probably doesn’t change voltages to fast anyways I would expect :wink:

That sounds great but I have a couple of questions. Are you saying that I should introduce the device to home assistant through esphome and ditch it from the shelly add-on?
I would love to use the deep sleep function but that isn’t available through shelly’s native config ( I asked shelly direct about this)