Shelly uni sensor update issue

Hi,
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
    sensors:
      retained_sensor_value:
        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: ""
trigger:
  - platform: state
    entity_id:
      - sensor.top_tank_water_level_adc
condition:
  - condition: template
    value_template: "{{ is_number(state_attr('sensor.top_tank_water_level_adc', 'state')) }}"
action:
  - service: homeassistant.update_entity
    data: {}
    target:
      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.
Pat

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:

deep_sleep:
  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:

1 Like

Orange
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)
Pat