Plant moisture notification

This is based off the great “Low Battery Level Detection” blueprint by Sbyx. This Blueprint works using the data in the “plant” card, you need to have min_moisture setup for your plants in order for this to work. I personally use Mi Flora sensors and a Bluetooth dongle on a raspberrypi (not the same Pi that HASS runs on). I make use of the following package to relay the data to HASS via MQTT (GitHub - ThomDietrich/miflora-mqtt-daemon: Linux service to collect and transfer Xiaomi Mi Flora plant sensor data via MQTT to your smart home system, with cluster support 🌱🌼🥀🏡🌳).

Here is my action notification yaml I have configured:
image

service: notify.mobile_app_my_phone
data:
  message: 'Low moisture warning for: {{sensors}}'

Here are some of my plants :smiley:

Let me know if you run into any issues. Also of note, Bluetooth does not seem to work well through glass windows, especially for the Mi Flora sensors. Just keep this in mind if you have your Bluetooth dongle inside (near a window) and plants outside. Good luck!

blueprint:
  name: Low moisture level detection & notification for all plant sensors
  description: Regularly test all plant sensors with 'moisture' crossing
    under their threshold.
  domain: automation
  input:
    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: Plant sensors (e.g. cactus) to exclude from detection. Only entities are supported, devices must be expanded!
      default: {entity_id: []}
      selector:
        target:
          entity:
            domain: plant
    actions:
      name: Actions
      description: Notifications or similar to be run. {{sensors}} is replaced with
        the names of sensors being low on moisture.
      selector:
        action: {}
variables:
  day: !input 'day'
  exclude: !input 'exclude'
  sensors: >-
    {% set result = namespace(sensors=[]) %}
    {% for state in states.plant if 'moisture low' in state.attributes.problem %}
      {% if not state.entity_id in exclude.entity_id %}
        {% set result.sensors = result.sensors + [state.attributes.friendly_name] %}
      {% 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
5 Likes

@cweakland, Thank you so much. I have implemented this, hopefully it works as intended. Do you have any updates on this blueprint?

Any chance to get the friendly name of the plant sensors to be used in actions such as mobile app notification or alexa media player announcement?

service: notify.mobile_app_my_phone
data:
  message: 'Low moisture warning for: {{sensors}}' <-- Frindly name of sensors

I don’t have friendly names set on my plants, however, I think you would change state.name with state.attributes.friendly_name. I will test this out later on and let you know if it works, if it does, I will update the blueprint.

Edit: It worked. I updated the blueprint, you will have to re-download it.

It seems like state.attributes.friendly_name is same as state.name for plant entities.

Tried this in template editor:

{% set result = namespace( sensors = [] ) %}

{% for state in states.plant if 'moisture low' in state.attributes.problem %}
    
    {% set result.sensors = result.sensors + [state.attributes.friendly_name] %}
    
{% endfor %}

{{result.sensors|join(', ')}}

But when I try to declare a friendly_name in <config>/plants.yaml config file I get a configuration error.

@cweakland, And is there any chance that you can make the plant sensors template logic into a binary_sensor like below, so that if any plant has moisture low then that state can be used to set the state of binary_sensor to on which in-turn can be used as a trigger in mobile_app or mediaplayer notification automation.

template:
  - binary_sensor:
      - name: People home
        state: >
          {{ is_state('device_tracker.sean', 'home')
             or is_state('binary_sensor.hallway_134', 'on') }}

Friendly name has to be set in customize.yaml.

1 Like

I have even tried customize.yaml long ago and I get a config error for that as well.

Error:
extra keys not allowed @ data['customize']['ficus_elastica']

cusotmize.yaml

# Plants
plant.dypsis_lutescens:
  friendly_name: Dypsis Lutescens
ficus_elastica:
  friendly_name: Ficus Elastica

EDIT
Now I realized my silly mistake in customize.yaml. Fixed and now that works. Thank you for making me revisit this issue.

# Plants
plant.dypsis_lutescens:
  friendly_name: Dypsis Lutescens
plant.ficus_elastica:
  friendly_name: Ficus Elastica

@cweakland, I was able to convert the template logic in your blueprint to a binary_sensor like how I asked for in this post:

# plant low moisture sensor
- binary_sensor:
    - name: Thirsty Plants
      state: >
        {% set thirsty = namespace( plants = []) %}
        {% set allplants = states.plant %}
        {% for plant in allplants if 'moisture low' in plant.attributes.problem %}
            {% set thirsty.plants = thirsty.plants + [plant.name] %}
        {% endfor %}
        {{ thirsty.plants|length > 0 }}
1 Like

@cweakland Can you let me know which plant card you are using and how you are showing up the image of the plant in the card. Thanks

I believe it is the built in “plant status” card. Then I went on google, searched for an image I liked, download it, cropped it some, and tied it in via customize.yaml like so:

plant.monstera:
  friendly_name: Monstera
  entity_picture: /local/plants/monstera.jpg

The actual file resides here: /root/config/www/plants/monstera.jpg

2 Likes

@cweakland Thank you so much, I am also using the built in plant card but entity_picture is something I didn’t know about before. It made me revisit customizing entities documentation. Thanks again.

2 Likes

Thank you very much! I am not used to importing blueprints without a github-url, so I created one myself. Please advice if this is stupid :smiley:

For anyone who’d like to simply import this:

As action I also included the option to open the corresponding dashboard (action field after you import the blueprint and clicked on “create”):

service: notify.mobile_app_al_13_app
data:
  message: "Low moisture warning for: {{sensors}}"
  data:
    actions:
      - action: URI
        title: App öffnen
        uri: /lovelace-zimmer/plants
        icon: mdi:home-assistant
2 Likes

That’s fine, I have had success entering this URL into the Blueprint addition tool in HA and it performs the import.

I tried to change your blueprint, since my moisture alert is resulting “low” status, but it does not work:

  sensors: >-
           {% set result = namespace(sensors=[]) %} 
           {% for state in states.plant if 'Low' in state.attributes.moisture_status %} 
             {% if not state.entity_id in exclude.entity_id %}   
               {% set result.sensors = result.sensors + [state.attributes.friendly_name] %}  
             {% endif %}
           {% endfor %} 
           {{result.sensors|join(', ')}}

This always results in the error:

“TypeError: argument of type ‘NoneType’ is not iterable”

What’s the problem?

1 Like