Simple automation won't start/trigger

My automation won’t start.

It is enabled and if I click on run actions it works perfect.
But it won’t start. The trigger never fires.

Can anyone help. What am I missing?

Its a simple automation.
If sensor numeric state is below 50% then fire action.

YAML code:

alias: water
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.xiaomi_miflora_moisture
    for:
      hours: 0
      minutes: 0
      seconds: 1
    below: '50'
condition:
  - condition: state
    entity_id: switch.lumi_lumi_plug_mmeu01_on_off
    state: 'Off'
action:
  - service: switch.turn_on
    target:
      device_id: 19ceb5c376dcdd0af98ea9fa70ba2f29
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - service: switch.turn_off
    target:
      device_id: 19ceb5c376dcdd0af98ea9fa70ba2f29
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
mode: single
initial_state: 'on'

Are you sure you can wrap a number with '? I believe this will cause it to be handled as a string instead of an integer.

But I recommend adding an unique id to the automation so you can debug it, read more about it here:

Actually, if sensor numeric state falls below 30% (or 50 as absolute value). If it is already below that threshold, it will not trigger

Even if it falls from 80 to 10 it wont trigger the automation.

I used an integer.
Yaml makes the ’ value ’
Even if I remove the ’ ’ the automation wont trigger

What does the trace look like?

  "trace": {
    "last_step": "condition/0/entity_id/0",
    "run_id": "25342e29e2f4b709113a9ede19413949",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2022-01-21T22:18:33.023515+00:00",
      "finish": "2022-01-21T22:18:33.024765+00:00"
    },
    "domain": "automation",
    "item_id": "1642793150212",
    "trigger": "numeric state of sensor.xiaomi_miflora_moisture",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-01-21T22:18:33.023939+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.water",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-21T21:36:19.789184+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642793150212",
                "friendly_name": "water"
              },
              "last_changed": "2022-01-21T22:17:22.320867+00:00",
              "last_updated": "2022-01-21T22:17:22.320867+00:00",
              "context": {
                "id": "1ccc3d53037bdaf43cbb616709c91c5a",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "numeric_state",
              "entity_id": "sensor.xiaomi_miflora_moisture",
              "below": 20,
              "above": null,
              "from_state": {
                "entity_id": "sensor.xiaomi_miflora_moisture",
                "state": "unavailable",
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "%",
                  "icon": "mdi:water-percent",
                  "friendly_name": "Bodemvocht"
                },
                "last_changed": "2022-01-21T22:18:32.414636+00:00",
                "last_updated": "2022-01-21T22:18:32.414636+00:00",
                "context": {
                  "id": "64575d13a4cf2ce5e3797d73ac4b36dc",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.xiaomi_miflora_moisture",
                "state": "0",
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "%",
                  "icon": "mdi:water-percent",
                  "friendly_name": "Bodemvocht"
                },
                "last_changed": "2022-01-21T22:18:33.017791+00:00",
                "last_updated": "2022-01-21T22:18:33.017791+00:00",
                "context": {
                  "id": "3c6a2056816f6db9f26b3b0931347153",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 0
              },
              "description": "numeric state of sensor.xiaomi_miflora_moisture"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2022-01-21T22:18:33.024210+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2022-01-21T22:18:33.024374+00:00",
          "result": {
            "result": false,
            "state": "off",
            "wanted_state": "Off"
          }
        }
      ]
    },
    "config": {
      "id": "1642793150212",
      "alias": "water",
      "description": "",
      "trigger": [
        {
          "platform": "numeric_state",
          "entity_id": "sensor.xiaomi_miflora_moisture",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 0
          },
          "below": "20"
        }
      ],
      "condition": [
        {
          "condition": "state",
          "entity_id": "switch.lumi_lumi_plug_mmeu01_on_off",
          "state": "Off"
        }
      ],
      "action": [
        {
          "service": "switch.turn_on",
          "target": {
            "device_id": "19ceb5c376dcdd0af98ea9fa70ba2f29"
          }
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 3,
            "milliseconds": 0
          }
        },
        {
          "service": "switch.turn_off",
          "target": {
            "device_id": "19ceb5c376dcdd0af98ea9fa70ba2f29"
          }
        },
        {
          "delay": {
            "hours": 4,
            "minutes": 0,
            "seconds": 2,
            "milliseconds": 0
          }
        }
      ],
      "mode": "single",
      "initial_state": "on"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "27618ddd81410071002ecb0493f8ba27",
      "parent_id": "3c6a2056816f6db9f26b3b0931347153",
      "user_id": null
    }
  },
  "logbookEntries": []
}

This condition will never be true:

condition:
  - condition: state
    entity_id: switch.lumi_lumi_plug_mmeu01_on_off
    state: 'Off'

The state of the switch is off not Off.

Letter case (upper/lower) is important.

I deleted the condition to make sure.
It still won’t trigger

What does the trace look like now?


{
  "trace": {
    "last_step": "action/3",
    "run_id": "a1fb9b5b3c40852a8fc219ab54bf951e",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-01-21T22:38:35.558442+00:00",
      "finish": "2022-01-21T22:40:54.231135+00:00"
    },
    "domain": "automation",
    "item_id": "1642793150212",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2022-01-21T22:38:35.559467+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.water",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-21T21:36:19.789184+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642793150212",
                "friendly_name": "water"
              },
              "last_changed": "2022-01-21T22:38:22.542567+00:00",
              "last_updated": "2022-01-21T22:38:22.542567+00:00",
              "context": {
                "id": "25f64c6dc45782a88a5127bd44e19f2e",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-01-21T22:38:35.562617+00:00",
          "changed_variables": {
            "context": {
              "id": "eb2f91f516f8622caf96ada4a9e07eed",
              "parent_id": "480e21b851c5910865172805fe1d1824",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "device_id": [
                  "19ceb5c376dcdd0af98ea9fa70ba2f29"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-01-21T22:38:35.615458+00:00",
          "result": {
            "delay": 3,
            "done": true
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2022-01-21T22:38:38.619482+00:00",
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "device_id": [
                  "19ceb5c376dcdd0af98ea9fa70ba2f29"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2022-01-21T22:38:38.666008+00:00",
          "result": {
            "delay": 14402,
            "done": false
          }
        }
      ]
    },
    "config": {
      "id": "1642793150212",
      "alias": "water",
      "description": "",
      "trigger": [
        {
          "platform": "numeric_state",
          "entity_id": "sensor.xiaomi_miflora_moisture",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 0
          },
          "below": "40",
          "id": "warerpomp"
        }
      ],
      "condition": [],
      "action": [
        {
          "service": "switch.turn_on",
          "target": {
            "device_id": "19ceb5c376dcdd0af98ea9fa70ba2f29"
          }
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 3,
            "milliseconds": 0
          }
        },
        {
          "service": "switch.turn_off",
          "target": {
            "device_id": "19ceb5c376dcdd0af98ea9fa70ba2f29"
          }
        },
        {
          "delay": {
            "hours": 4,
            "minutes": 0,
            "seconds": 2,
            "milliseconds": 0
          }
        }
      ],
      "mode": "single",
      "initial_state": "on"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "eb2f91f516f8622caf96ada4a9e07eed",
      "parent_id": "480e21b851c5910865172805fe1d1824",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "water",
      "message": "has been triggered",
      "source": null,
      "entity_id": "automation.water",
      "context_id": "eb2f91f516f8622caf96ada4a9e07eed",
      "when": "2022-01-21T22:38:35.560025+00:00",
      "domain": "automation"
    },
    {
      "when": "2022-01-21T22:38:35.608454+00:00",
      "name": "Stopcontact_Waterpomp on_off",
      "state": "on",
      "entity_id": "switch.lumi_lumi_plug_mmeu01_on_off",
      "context_entity_id": "automation.water",
      "context_entity_id_name": "water",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "water",
      "message": "turned on"
    },
    {
      "when": "2022-01-21T22:38:38.658783+00:00",
      "name": "Stopcontact_Waterpomp on_off",
      "state": "off",
      "entity_id": "switch.lumi_lumi_plug_mmeu01_on_off",
      "context_entity_id": "automation.water",
      "context_entity_id_name": "water",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "water",
      "message": "turned off"
    }
  ]
}

Can you show your automation config now, exactly as it it, unedited.

Also how are you getting the sensor to change to trigger it?

Your last action is a loooong delay according to this:

delay: 14402

That’s 4 hours.

And because of that the automation is still running. And because you have the automation mode set so single the automation wont run again until this delay has finished.

Removed the timer on the end.
Still dont triiger.

Here is the code.

alias: water
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.xiaomi_miflora_moisture
    for:
      hours: 0
      minutes: 0
      seconds: 0
    below: '50'
    id: warerpomp
condition: []
action:
  - service: switch.turn_on
    target:
      device_id: 19ceb5c376dcdd0af98ea9fa70ba2f29
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: switch.turn_off
    target:
      device_id: 19ceb5c376dcdd0af98ea9fa70ba2f29
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
mode: single
initial_state: 'on'

Could you please answer this:

Not sure what you mean.

I gues home assistent looks at the last sensor value and if that is below 30% the automation triggers.

The sensor (xiaomi mi flower sensor) send the sensor Data to a esp32 by bluetooth.
The esp32 send the data through mqtt to my home assitant.
On the home assitant the automation should trigger it when the value is less than 30

I meant how are you manually testing it?

Can you post the graphic of the automation trace?

I’m pretty sure it is triggering but your actions are device actions (which are an abomination). Try using service calls for entity_ids instead.

e.g. instead of:

  - service: switch.turn_on
    target:
      device_id: 19ceb5c376dcdd0af98ea9fa70ba2f29

do this:

  - service: switch.turn_on
    target:
      entity_id: switch.your_switch_entity_id_here

You can find the entity ids in the Developer Tools / States page.