Automation help: Why won't my threshold automation trigger?

Hi everyone.

I’ve had this automation running fine for a good year on Z2M, but after changing to ZHA it stopped working. Can anyone help me figure out why and what I should change:

The goal is to have a presence sensor in the kitchen, that determines if the lights should go on or not. There are three thresholds based on lux, that determines what level of brightness that should go on or whether the lights should turn off.

Two of the thresholds should trigger only if there is presence in the room, and the third, turning off the ligths, should happen regardless.

alias: Køkken Dagligdagsbelysning
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.kokken_dagsbelysning_mellem_0_og_40
    to: "on"
    enabled: true
  - trigger: state
    entity_id:
      - binary_sensor.threshold_kokken_dagsbelysning_mellem_70_og_140
    to: "on"
    enabled: true
  - trigger: state
    entity_id:
      - binary_sensor.kokken_dagsbelysning_sluk_hvis_over_170
    to: "on"
    enabled: true
conditions:
  - condition: state
    entity_id: binary_sensor.presence_sensor_kokken
    state:
      - "on"
  - condition: or
    conditions:
      - condition: state
        entity_id: input_select.hus_tilstand
        state: Hjemme
      - condition: state
        entity_id: input_select.hus_tilstand
        state: Gæster
actions:
  - alias: Lux mellem 0 og 40
    if:
      - condition: state
        entity_id: binary_sensor.kokken_dagsbelysning_mellem_0_og_40
        state:
          - "on"
    then:
      - action: light.turn_on
        metadata: {}
        data:
          brightness_pct: 70
          transition: 12
          color_temp_kelvin: 2451
        target:
          entity_id:
            - light.home_assistant_connect_zbt_2_kokkenbordet
      - data:
          brightness_pct: 100
          transition: 12
        action: light.turn_on
        target:
          entity_id:
            - light.spisebordet_1
            - light.spisebordet_2
    enabled: true
  - alias: Lux mellem 30 og 80
    if:
      - condition: state
        entity_id: binary_sensor.threshold_kokken_dagsbelysning_mellem_70_og_140
        state: "on"
      - type: is_occupied
        condition: device
        device_id: 6d1689c002eeac1fb41a6f99f823c7b1
        entity_id: 8b4692a4827bfbe5784e4dd7291bd4b4
        domain: binary_sensor
    then:
      - data:
          brightness_pct: 70
          transition: 12
        target:
          entity_id:
            - light.home_assistant_connect_zbt_2_spisebordet
        action: light.turn_on
      - target:
          entity_id:
            - light.home_assistant_connect_zbt_2_kokkenbordet
        data:
          transition: 12
        action: light.turn_off
    enabled: true
  - alias: Sluk hvis over 90
    if:
      - condition: state
        entity_id: binary_sensor.kokken_dagsbelysning_sluk_hvis_over_170
        state:
          - "on"
        enabled: true
    then:
      - data:
          transition: 20
        target:
          entity_id:
            - light.home_assistant_connect_zbt_2_kokken_alle_lys
        action: light.turn_off
    enabled: true
mode: single

Did you look at the automation trace?

I would at least change the device condition to only entity condition

and indeed check the traces

Probably because when you went Z2M to ZHA the names changed, the features of the entities changed, and something is no longer correct.

You have the flowchart of what you want to do, just spend 5 minutes building it over in the UI so it works with the new hardware, because flipping coordinator schemes means the hardware is new…

Already did that, rebuilding everything and checking all the names. Yet it doesn’t want to run. So I was hoping someone could spot something I haven’t when I rebuilt the thing.

Please download the automation’s most recent trace file and paste it here so we can examine it.

If there are no recent traces then it means the automation never triggered.

I hope this is correct?

	
trace	
last_step	"action/2/if/condition/0/entity_id/0"
run_id	"83f5d5b14e6b2467cfa39976731823a3"
state	"stopped"
script_execution	"finished"
timestamp	
start	"2026-02-01T14:48:32.059395+00:00"
finish	"2026-02-01T14:48:32.260570+00:00"
domain	"automation"
item_id	"1698956665844"
trigger	null
trace	
trigger	
0	
path	"trigger"
timestamp	"2026-02-01T14:48:32.059585+00:00"
changed_variables	
this	
entity_id	"automation.kokken_dagligdagsbelysning_test"
state	"on"
attributes	
id	"1698956665844"
last_triggered	"2026-02-01T14:32:56.264537+00:00"
mode	"single"
current	0
friendly_name	"Køkken Dagligdagsbelysning"
last_changed	"2026-02-01T14:48:08.938152+00:00"
last_reported	"2026-02-01T14:48:08.938152+00:00"
last_updated	"2026-02-01T14:48:08.938152+00:00"
context	
id	"01KGCTSTZAWJATZA9M89Q4SH07"
parent_id	null
user_id	null
trigger	
platform	null
action/0	
0	
path	"action/0"
timestamp	"2026-02-01T14:48:32.060907+00:00"
changed_variables	
context	
id	"01KGCTTHHVC8092XN6Q1WVRFEW"
parent_id	"01KGCTTHHTZJ6TH0YY98CZJ55W"
user_id	null
result	
choice	"then"
action/0/if	
0	
path	"action/0/if"
timestamp	"2026-02-01T14:48:32.061542+00:00"
result	
result	true
action/0/if/condition/0	
0	
path	"action/0/if/condition/0"
timestamp	"2026-02-01T14:48:32.061755+00:00"
result	
result	true
action/0/if/condition/0/entity_id/0	
0	
path	"action/0/if/condition/0/entity_id/0"
timestamp	"2026-02-01T14:48:32.061935+00:00"
result	
result	true
state	"on"
wanted_state	"on"
action/0/if/condition/1	
0	
path	"action/0/if/condition/1"
timestamp	"2026-02-01T14:48:32.062197+00:00"
result	
result	null
action/0/then/0	
0	
path	"action/0/then/0"
timestamp	"2026-02-01T14:48:32.062993+00:00"
result	
params	
domain	"light"
service	"turn_on"
service_data	
brightness_pct	100
transition	12
entity_id	[ "light.spisebordet_1", "light.spisebordet_2" ]
target	
entity_id	[ "light.spisebordet_1", "light.spisebordet_2" ]
running_script	false
action/0/then/1	
0	
path	"action/0/then/1"
timestamp	"2026-02-01T14:48:32.206824+00:00"
result	
params	
domain	"light"
service	"turn_on"
service_data	
brightness_pct	70
transition	12
color_temp_kelvin	2451
entity_id	[ "light.home_assistant_connect_zbt_2_kokkenbordet" ]
target	
entity_id	[ "light.home_assistant_connect_zbt_2_kokkenbordet" ]
running_script	false
action/1	
0	
path	"action/1"
timestamp	"2026-02-01T14:48:32.249818+00:00"
action/1/if	
0	
path	"action/1/if"
timestamp	"2026-02-01T14:48:32.251239+00:00"
result	
result	false
action/1/if/condition/0	
0	
path	"action/1/if/condition/0"
timestamp	"2026-02-01T14:48:32.251493+00:00"
result	
result	false
action/1/if/condition/0/entity_id/0	
0	
path	"action/1/if/condition/0/entity_id/0"
timestamp	"2026-02-01T14:48:32.251715+00:00"
result	
result	false
state	"off"
wanted_state	"on"
action/2	
0	
path	"action/2"
timestamp	"2026-02-01T14:48:32.252278+00:00"
action/2/if	
0	
path	"action/2/if"
timestamp	"2026-02-01T14:48:32.252927+00:00"
result	
result	false
action/2/if/condition/0	
0	
path	"action/2/if/condition/0"
timestamp	"2026-02-01T14:48:32.253178+00:00"
result	
result	false
action/2/if/condition/0/entity_id/0	
0	
path	"action/2/if/condition/0/entity_id/0"
timestamp	"2026-02-01T14:48:32.253351+00:00"
result	
result	false
state	"off"
wanted_state	"on"
config	
id	"1698956665844"
alias	"Køkken Dagligdagsbelysning"
description	""
triggers	
0	
trigger	"state"
entity_id	
0	"binary_sensor.kokken_dagsbelysning_mellem_0_og_40"
to	"on"
enabled	false
1	
trigger	"state"
entity_id	
0	"binary_sensor.threshold_kokken_dagsbelysning_mellem_70_og_140"
to	"on"
enabled	false
2	
trigger	"state"
entity_id	
0	"binary_sensor.kokken_dagsbelysning_sluk_hvis_over_170"
to	"on"
enabled	false
conditions	
0	
condition	"or"
conditions	
0	
condition	"state"
entity_id	"input_select.hus_tilstand"
state	"Hjemme"
1	
condition	"state"
entity_id	"input_select.hus_tilstand"
state	"Gæster"
actions	
0	
alias	"Lux mellem 0 og 40"
if	
0	
condition	"state"
entity_id	"binary_sensor.kokken_dagsbelysning_mellem_0_og_40"
state	
0	"on"
1	
type	"is_occupied"
condition	"device"
device_id	"6d1689c002eeac1fb41a6f99f823c7b1"
entity_id	"8b4692a4827bfbe5784e4dd7291bd4b4"
domain	"binary_sensor"
enabled	false
then	
0	
data	
brightness_pct	100
transition	12
action	"light.turn_on"
target	
entity_id	[ "light.spisebordet_1", "light.spisebordet_2" ]
1	
action	"light.turn_on"
metadata	{}
data	
brightness_pct	70
transition	12
color_temp_kelvin	2451
target	
entity_id	[ "light.home_assistant_connect_zbt_2_kokkenbordet" ]
1	
alias	"Lux mellem 30 og 80"
if	
0	
condition	"state"
entity_id	"binary_sensor.threshold_kokken_dagsbelysning_mellem_70_og_140"
state	"on"
1	
type	"is_occupied"
condition	"device"
device_id	"6d1689c002eeac1fb41a6f99f823c7b1"
entity_id	"8b4692a4827bfbe5784e4dd7291bd4b4"
domain	"binary_sensor"
then	
0	
data	
brightness_pct	70
transition	12
target	
entity_id	[ "light.home_assistant_connect_zbt_2_spisebordet" ]
action	"light.turn_on"
1	
target	
entity_id	[ "light.home_assistant_connect_zbt_2_kokkenbordet" ]
data	
transition	12
action	"light.turn_off"
2	
alias	"Sluk hvis over 90"
if	
0	
condition	"state"
entity_id	"binary_sensor.kokken_dagsbelysning_sluk_hvis_over_170"
state	
0	"on"
enabled	true
then	
0	
data	
transition	20
target	
entity_id	[ "light.home_assistant_connect_zbt_2_kokken_alle_lys" ]
action	"light.turn_off"
mode	"single"
blueprint_inputs	null
context	
id	"01KGCTTHHVC8092XN6Q1WVRFEW"
parent_id	"01KGCTTHHTZJ6TH0YY98CZJ55W"
user_id	null
logbookEntries	
0	
name	"Køkken Dagligdagsbelysning"
message	"triggered"
source	null
entity_id	"automation.kokken_dagligdagsbelysning_test"
context_id	"01KGCTTHHVC8092XN6Q1WVRFEW"
domain	"automation"
when	1769957312.0598161
1	
state	"on"
entity_id	"light.spisebordet_1"
when	1769957312.1932092
context_event_type	"automation_triggered"
context_domain	"automation"
context_name	"Køkken Dagligdagsbelysning"
context_message	"triggered"
context_entity_id	"automation.kokken_dagligdagsbelysning_test"
2	
state	"on"
entity_id	"light.spisebordet_2"
when	1769957312.20046
context_event_type	"automation_triggered"
context_domain	"automation"
context_name	"Køkken Dagligdagsbelysning"
context_message	"triggered"
context_entity_id	"automation.kokken_dagligdagsbelysning_test"
3	
state	"on"
entity_id	"light.home_assistant_connect_zbt_2_kokkenbordet"
when	1769957312.2319226
context_event_type	"automation_triggered"
context_domain	"automation"
context_name	"Køkken Dagligdagsbelysning"
context_message	"triggered"
context_entity_id	"automation.kokken_dagligdagsbelysning_test"

It’s the correct information but it is unformatted so it’s difficult to read.

Instructions

  1. Display the automation’s latest trace.
  2. In the upper righthand corner is an icon with three dots.
  3. Click it and you will be presented with the following menu:


4. Click “Download trace”
5. It will create a file that ends with .json. Open the file and copy-paste its contents in your forum reply.
6. Before the first line of the trace, add three backticks and the word json

7. After the last line of the trace, add three backticks.

After you click the “Reply” button, the trace will look something like this:

{
  "trace": {
    "last_step": "action/1",
    "run_id": "8f212b7b81c273be290130432e891b40",
    "state": "stopped",
    "script_execution": "aborted",
    "timestamp": {
      "start": "2026-02-01T12:50:10.516321+00:00",
      "finish": "2026-02-01T12:50:10.520228+00:00"
    },
    "domain": "automation",
    "item_id": "upb_scene_morning_interior",
    "trigger": "event 'upb.scene_changed'",
    "trace": {
      "trigger/1": [
        {
... etc ...