Sensor Template for Plant Sensors below a value

Hello,

I was trying to make a sensor for my plant moisture sensors. What I want is to list all moisture entities and if any of those is below state 20, to turn return the on state for the sensor.

I tried to copy it from another sensor but doesnt work. And yes I read the Template page but it is just to muich for my brain and I will never understand it :slight_smile:

In the best case could be also without listing the entities and just search for all senors.plant_sensor… with state cass measurement.

and just in case its needed:
state_class: measurement
friendly_name: Plant Sensor Basilikum Moisture
unit_of_measurement: ‘%’

If someone could help me pleas I really appriciate.

  - platform: template
    sensors:
      plants_need_water:
        friendly_name: 'Pflanzen Wasserbedarf'
        value_template: >
          {% set plants = [
            states.sensor.plant_sensor_basilikum_moisture,
            states.sensor.plant_sensor_cissus_moisture,
            states.sensor.plant_sensor_dracaena_moisture,
            states.sensor.plant_sensor_dracaena_mini_moisture,
            states.sensor.plant_sensor_epipremnum_moisture,
            states.sensor.plant_sensor_ficus_moisture,
            states.sensor.plant_sensor_lobbianus_moisture,
            states.sensor.plant_sensor_lyrata_moisture,
            states.sensor.plant_sensor_monstera_moisture
            ] %}
          {{ plants | selectattr('state','<20','on') | list | count }}

We need to see the plant sensor’s available information. Go to Developer Tools > States, find sensor.plant_sensor_basilikum_moisture and post a screenshot of the displayed information.

See attached,

Thankd a lot already…

What do you mean by “return the on state”? The screenshot shows that the only available information is the sensor’s state value which is a number.

Is this what you want: Report the quantity of plant sensors with a state value less than 20.

- platform: template
    sensors:
      plants_need_water:
        friendly_name: 'Pflanzen Wasserbedarf'
        value_template: >
          {{ expand('sensor.plant_sensor_basilikum_moisture',
            'sensor.plant_sensor_cissus_moisture',
            'sensor.plant_sensor_dracaena_moisture',
            'sensor.plant_sensor_dracaena_mini_moisture',
            'sensor.plant_sensor_epipremnum_moisture',
            'sensor.plant_sensor_ficus_moisture',
            'sensor.plant_sensor_lobbianus_moisture',
            'sensor.plant_sensor_lyrata_moisture',
            'sensor.plant_sensor_monstera_moisture')
            | map(attribute='state') | map('float', 0)
            | select('lt', 20) | list | count }}

Thanks almost. I want a sensor which has on and off state. “Off” if every moisture is above 20% and on if one or more moisture sensors are below 20%.

The count came only because i tried to make the template using an other sensor i had for counting lights on. I have no idea how to change this to something else.

template:
  - binary_sensor:
      - name: 'Pflanzen Wasserbedarf'
        state: >
          {{ expand('sensor.plant_sensor_basilikum_moisture',
            'sensor.plant_sensor_cissus_moisture',
            'sensor.plant_sensor_dracaena_moisture',
            'sensor.plant_sensor_dracaena_mini_moisture',
            'sensor.plant_sensor_epipremnum_moisture',
            'sensor.plant_sensor_ficus_moisture',
            'sensor.plant_sensor_lobbianus_moisture',
            'sensor.plant_sensor_lyrata_moisture',
            'sensor.plant_sensor_monstera_moisture')
            | map(attribute='state') | map('float', 0)
            | select('lt', 20) | list | count > 0 }}

The example I posted is a Template Binary Sensor in modern format. The format of your example is now called legacy. Any future improvements to the Template integration will be exclusively supported by modern format. I advise you to consider using modern format when creating new Template entities.

Thanks a lot @123 . That actually worked how to be intended. Have a good one…

1 Like