Binary template for plant moisture

Hey guys, been a minute since I posted around here.

Need some help; essentially trying to create a binary sensor, using a template to pull out the “moisture low” option from a plant sensor with a problem. So if the plant needs water, binary sensor is true, or if it doesn’t need water, it’s false.

Just to use a real world example:
{{ state_attr('plant.moneytree', 'problem') }}
Outputs: moisture low, conductivity low, brightness low

Which is great, but i’m only concerned with “moisture low”, since it’s the only thing I can really do anything about, aka water the plant. So how would I check for the presence of that one option out of a list of all possible options?

It seems like a template is the only option, since the sensor “sensor.moneytree_moisture” only reports the value of the moisture, not whether it’s above or below a threshold- which is why I like the plant integration for this. Would be quite annoying to have to make yet another sensor, with a static variable just to know if the moisture if below the certain threshold.

Ideally, it’d be great to create a sensor, which only reported those plants which needed water from all the plants in the plant domain. So that way if a plant was added, and needed water, it would dynamically be reported, instead of having to code each and every plant.


Hi there, Please try this template sensor which would look for the term moisture loss in the output of your sensor.

  - binary_sensor:
      - name: "Moisture Sensor"
        state: "{{ state_attr('plant.moneytree', 'problem')|regex_search('moisture low',ignorecase=true) }}"
1 Like

For future reference, you can search for a sub-string in a string directly:

state: "{{ 'moisture low' in state_attr('plant.moneytree', 'problem') | lower }}"
1 Like

Sweet, thanks guys!

Don’t forget to mark sheminasalam’s post with the Solution tag.

It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.