Issue with Utility Meter after rebooting

Hi,

I am using Shelly 3EM through MQTT, and finally I have used following code to clear out the problem of getting unavalaible / unknown state of total power meter converted to 0 on restart:

sensor:
  - platform: template
    sensors:
      energy_consumption:
        friendly_name: "Total energy consumption"
        unit_of_measurement: kWh
        value_template: "{{ (states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_0')|float + states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_1')|float + states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_2')|float)|round(3) }}"
        availability_template: >
          {% if is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_0", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unknown") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unknown") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_2", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_2", "unknown") %}
            false
          {% else %}
            true
          {%- endif %}

The availability_template is not very clever, hopefully I could merge the unvailable and unknown for each sensor into one line, but it works for now. It prevents getting the state of 0 after converting those states after reset.

2 Likes