Shelly Flood

Hi!

I would really appreciate a tip from a Home Assistant expert on how to tackle the following problem:

  1. I use several Shelly Flood devices. These WiFi-enabled devices generate an alarm in case of a water leakage.

  2. The Shelllies are very conservative in battery usage which is, in principle, a great feature. I.e., they are generally triggered by leakage event. In addition, they connect to the WiFi and send an update about their status every couple of hours. Otherwise they are in sleep mode and thus disconnected from the WiFi.

  3. When the sensor is disconnected from the WiFi, the sensor disappears from HA yielding an error message in the Lovelace interface that a sensor with such a name does not exist.

  4. How can I avoid this error? For example, it is possible to store and show the sensor value until the next update?

Thanks ins advance and kind regards!

That would depend on how they are connected to Home Assistant. Are you using MQTT?

If so, simply set the LWT messages as blank.

Dear tom,

thanks for your quick response. Currently I am not connected via MQTT since I have been playing around with the Shelly-integrated cloud features recently.

Is there also an easy solution without MQTT?

Thanks in advance and kind regards,
Roman.

Is there also an easy solution without MQTT?

I don’t use the cloud so I don’t know, sorry.

You could create a template sensor that uses the status of the original sensor to determine what it displays as the value - if the sensor status is actually working then use the actual value otherwise use the old value.

here is an example that you can modify to your needs:

  - platform: template
    sensors:
      nws_alert_count_filtered:
        friendly_name: NWS Alert Count
        entity_id: sensor.nws_alert_count_raw
        value_template: >
          {% if is_state('sensor.nws_alert_count_raw', 'unavailable') or is_state('sensor.nws_alert_count_raw', 'unknown') %}
            {{ states.sensor.nws_alert_count_filtered.state }}
          {% else %}
            {{ states.sensor.nws_alert_count_raw.state }}
          {% endif %}

Dear finity,

thanks for the suggestion. I will try it later today.

If I understand correctly, this if statement should also work if the entity does not exist? I am asking because when the sensor is in sleep mode and thus disconnected from WiFi, HA reports “Entity is not available: shelly_flood”.

Kind regards!

You can use Shellies Discovery Script

Hi!

Great, thanks for pointing me to your discovery script! I have definitely try it.

Kind regards!

the template as written above won’t but you can add another clause to check if the entity isn’t defined which will return true if the entity doesn’t exist:

{% if states.sensor.your_shelly.state is not defined or is_state('sensor.your_shelly', 'unavailable') or is_state('sensor.your_shelly', 'unknown') %}

Thanks again for all the feedback! I have adjusted and tested all suggestions and they all worked flawlessly. I have not decided yet which one I will use in the long term. This decision will most likely be made based on my future Shelly purchases. :slight_smile:

Kind regards!

Good evening!

One quick question to a related problem: I own a couple of AVM FRITZ!DECT 200 smart plugs which work fine. They comprise smart plug functionality with power monitoring and temperature sensing. The power filter attribute is called “current_power_w” as usual. Unfortunately, if the switch in the plug is turned off, this filter attribute disappears in HA yielding to an error message in a card displaying this value. Is there a trick similar to the one above posted by finity to just display the value zero when the switch is turned off?

Thanks in advance!

Dear all,

did anyone successfully integrate shelly flood without MQTT?
Could you share your experience?

Regards,
xwox

Hello,

continuing this fred…

i recently bought a Shelly and setup mqtt as following:

sensor:
  - platform: mqtt
    state_topic: "shellies/shellyflood-7659D2/sensor/temperature"
    name: "Wassersensor Keller Temp"
    unit_of_measurement: "°C"
    device_class: temperature
    
  - platform: mqtt
    state_topic: "shellies/shellyflood-7659D2/sensor/battery"
    name: "Wassersensor Keller Batterie"
    unit_of_measurement: "%"
    device_class: battery
    
binary_sensor:
  - platform: mqtt
    state_topic: "shellies/shellyflood-7659D2/sensor/flood"
    name: "Wassersensor Keller"
    #icon: mdi:pipe-leak
    payload_on: "true"
    payload_off: "false"
    device_class: moisture

Note: you must adjust the state-topic, i used the following command on SSH command line to get the correct values:
mosquitto_sub -h 192.168.178.45 -u <user> -P <password> --insecure -t 'shellies/#' -v

Shelly is correctly reporting the values into mqtt. During the flodding, it sounds the speaker and during that time, the last of above values is correctly set o “true”

The only thing i am currently still struggling around is that the Push notification is not working correctly - but i am far away from beeing an expert in automations as i did only a few so far. Here’s my config, mybe s.o. can point me into right direction here?

  - alias: "Water alarm"
    trigger:
      platform: state
      entity_id:
        - binary_sensor.watersensor1_shelly
      from: 'Off'
      to: 'On'
    action:
      service: notify.pushover
      data_template:
          title: "Alarm! Water Alarm!"
          message: "Water detected!"

Thanks
/ Ralf

1 Like

Thx @Ralf. I used your example of the binary_sensor to fix a bug in my configuration. I forgot to use the quotation marks in payload_on: "true". It worked on other sensors, but not for Shelly.

I don’t know if you got your push notification working already, but I noticed capital casing in your sensor values. Maybe from: 'off' and to: 'on' fixes it? And/or leave the from out completely because you’ll miss an update from status unknown to status on.

1 Like

Hello,

sorry for late reply.
Unfortunately i did not had time validating it. Must really do it soon.
Thanks for your note and tipps, will try it and give feedback.

/ Ralf

@gurbyz,

Sorry for the very late reply.
Thanks for your tips, helped me make it work.

For whoever is interested here my current automation:

  - alias: "Water_leak"
    trigger:
      platform: state
      entity_id:
        - binary_sensor.wassersensor_keller
#      from: 'off'
      to: 'on'
    action:
      service: notify.pushover
      data_template:
          title: "Alarm! Water!"
          message: "Water leak!"

/ Ralf

1 Like