Low humidity level detection & notification for miflora sensors

Github Gist:https://gist.github.com/VincenzoMaletta/04142b9d54c8235dea5d79f307e1724d

This blueprint is a fork from the terrific job of Sbyx (https://community.home-assistant.io/t/low-battery-level-detection-notification-for-all-battery-sensors/258664); I’ve only changed some minor details in order to detect and report the humidity level from my miflora sensors.

Please refer to the original blueprint for a full description of the functionalities implemented.

Thank you very much Sbyx for the excellent contribution, which I have successfully implemented in my HA installation and which prompted me to make this little customization, which I hope will be useful to others as well.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

I have not used blueprints. So can you briefly explain what it does or how you use it yourself?

Blueprints are a quick way to implement HA automations that have been written (and hopefully tested and debugged) by other users and are believed to be useful to the Home Assistant user community.

Using blueprints, you just import the code of an automation ready to use.

This project, in particular, periodically checks the humidity status reported by the miflora sensors and, if it finds any below the defined threshold, it sends a notification through any notifier defined in HA.

In my case, I chose to set the check every day at 10:00 and receive a message on Telegram every time that some sensor reports a humidity below 20%. All parameters are fully customizable.

@vincenzomaletta
I was looking to do just the same, but stumbled upon your code. Which is great. However, how is this working for you? My sensor for moisture doesn’t have a device class

I do have an Aqara temp/humidty sensor, which would show up in your code, but never get selected because there’s no minimum for such a sensor :upside_down_face:

So what I did is tweak the filtering. The convention here is that your icon remains mdi:water-percent.
I don’t see any other way at the moment.
Also replaced a little missed adjustment where in the Actions part you left “battery” instead of “humidity” :wink:

blueprint:
  name: "Low humidity level detection & notification for miflora sensors"
  description:
    "Regularly test all sensors with 'humidity' device-class for crossing
    a certain humidity level threshold and if so execute an action."
  domain: automation
  input:
    threshold:
      name: "Humidity warning level threshold"
      description: "Humidity sensors below threshold are assumed to be low-humidity."
      default: 20
      selector:
        number:
          min: 5.0
          max: 100.0
          unit_of_measurement: "%"
          mode: slider
          step: 5.0
    time:
      name: "Time to test on"
      description: "Test is run at configured time"
      default: "10:00:00"
      selector:
        time: {}
    day:
      name: "Weekday to test on"
      description:
        "Test is run at configured time either everyday (0) or on a given
        weekday (1: Monday ... 7: Sunday)"
      default: 0
      selector:
        number:
          min: 0.0
          max: 7.0
          mode: slider
          step: 1.0
    exclude:
      name: "Excluded Sensors"
      description:
        "Humidity sensors (e.g. ambient sensors) to exclude from detection. Only
        entities are supported, devices must be expanded!"
      default:
        entity_id: []
      selector:
        target:
          entity:
            device_class: humidity
    actions:
      name: "Actions"
      description:
        "Notifications or similar to be run. {{sensors}} is replaced with
        the names of sensors being low on humidity."
      selector:
        action: {}
  source_url: https://gist.github.com/VincenzoMaletta/04142b9d54c8235dea5d79f307e1724d
variables:
  day: !input "day"
  threshold: !input "threshold"
  exclude: !input "exclude"
  sensors: >-
    "{% set result = namespace(sensors=[]) %} 
    {% for state in states.sensor 
      | selectattr('attributes.unit_of_measurement', '==', '%')
      | selectattr('attributes.device_class', '!=', 'humidity')
      | selectattr('attributes.icon','==','mdi:water-percent') %}
      {% if 0 <= state.state | int(-1) < threshold | int and not state.entity_id in exclude.entity_id %}
        {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
      {% endif %}
    {% endfor %} 
    {{ result.sensors|join(', ') }}"
trigger:
  - platform: time
    at: !input "time"
condition:
  - "{{ sensors != '' and (day | int == 0 or day | int == now().isoweekday()) }}"
action:
  - choose: []
    default: !input "actions"
mode: single