Determine which automation condition returned true

Hi!
I am new to the forum and couldn’t find a solution to my problem in the documentations or existing topics. Unfortunately I am not very experienced in Home-Assistant. So that might be the reason I haven’t found it …

I created an automation to check whether the battery voltage (respectively the moisture in a second automation) of my soil moisture sensors is above a certain limit (= low battery warning). No problem at first, when the number of sensors was 8. Meanwhile this number increased to 56. Now it would be helpful to know, which sensors have low battery. ‘Traces’ is not much of a help.

Here my automation:

alias: WH51 Battery Check
description: ""
trigger:
  - platform: time_pattern
    minutes: "01"
condition:
  - condition: time
    after: "08:00:00"
    before: "22:31:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_1
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_2
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_3
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_4
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_5
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_6
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_7
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_8
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_9
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_10
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_11
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_12
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_13
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_14
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_15
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_16
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_17
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_18
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_19
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_20
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_21
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_22
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_23
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_24
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_25
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_26
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_27
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_28
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_29
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_30
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_31
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_32
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_33
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_34
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_35
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_36
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_37
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_38
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_39
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_40
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_41
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_42
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_43
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_44
        below: 1450
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_45
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_46
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_47
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.spannung_batterie_sensor3_48
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_1
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_2
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_3
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_4
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_5
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_6
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_7
        below: 1.45
      - condition: numeric_state
        entity_id: sensor.gw2000a_v2_2_4_soil_battery_8
        below: 1.45
action:
  - service: rest_command.tts
    data:
      payload: Batterie-Spannung Bodenfeuchte Sensor niedrig
  - service: telegram_bot.send_message
    data:
      message: " Batterie-Spannung Bodenfeuchte Sensor niedrig !!"
mode: single

Help would be appreciated.

Sincerely

Mike

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Remove the time pattern trigger.

Change all the numeric state conditions to numeric state triggers.

Then in your action you can include which trigger caused the automation to fire like this:

data:
  message: "{{ trigger.to_state.name }} low battery level: {{ trigger.to_state.state }}"

You may miss this if your time condition is not true though. So consider removing that. If you are worried about this waking you at night just enable the do not disturb mode of your phone.

Thanks for your fast response.
I dabbled in this (using numeric state triggers instead of conditions) already a few months ago, but couldn’t get it to work. Probably due to lack of personal skills. Unfortunately I don’t remember, what exactly the problem was.

Will give it another try; my skills-set should have improved since then …
The time pattern trigger is mainly preventing the voice-assistant from speaking up at night …

Mike

In that case you can move the time condition to in-line with the actions, like this:

action:
  - service: telegram_bot.send_message
    data:
      message: "{{ trigger.to_state.name }} low battery level: {{ trigger.to_state.state }}"
  - condition: time
    after: "08:00:00"
    before: "22:31:00"
  - service: rest_command.tts
    data:
      payload: "{{ trigger.to_state.name }} low battery level: {{ trigger.to_state.state }}"
mode: single

It will stop the following actions if false.

1 Like

Or instead of triggering every minute and doing 25 condition checks, move those tests to the trigger and only trigger when one of those conditions are met?
Use a Trigger id and/or the trigger.entity to do your action.

WAY simpler and more efficient besides.

What am I?

Chopped liver?

Sorry.
Missed it. or didn’t read it, but I totally agree with what you said.
That Automation is a hot mess.

I think I read your last word where they marked solution, not the stuff in the middle.
I beg your forgiveness.

1 Like