Skip to content

Commit 8b91b8a

Browse files
committed
Add case-insensitive name matching to find template entities
The script now also searches for entities by their friendly name (e.g., "name: activity in living room" for entity_id "binary_sensor.activity_in_living_room"). This finds more entities defined in templates.yaml without unique_id. Note: Some entities still can't be found due to naming mismatches (e.g., entity_id has "activity_in_living_room" but template name is "Activity in the living room" with extra "the"). These would need unique_id added to templates.yaml to be found reliably.
1 parent ab0f4e5 commit 8b91b8a

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
535535
- [input_boolean.wake_up_light](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L75)
536536
- [input_boolean.wake_up_with_spotify](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L99)
537537
- [input_select.sleep_mode](https://github.com/basnijholt/home-assistant-config/blob/07c0fdd72fdd676ab1b95db36f7baef313f7cff6/includes/input_selects.yaml#L11)
538+
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L29)
538539
- [sensor.ten_minutes_before_alarm](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L447)
539540
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L299)
540541

@@ -619,6 +620,7 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
619620

620621
*which uses:*
621622
- [input_datetime.bike_charger_off](https://github.com/basnijholt/home-assistant-config/blob/07e1a85beb7396dd12290030ba48064f386899a8/includes/input_datetimes.yaml#L51)
623+
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L29)
622624
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L299)
623625

624626
[^ toc](#automations---table-of-content)
@@ -632,6 +634,7 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
632634
- [input_boolean.automatic_temperature](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L49)
633635
- [input_number.temperature_high](https://github.com/basnijholt/home-assistant-config/blob/364858031f698404bdff4dc6acc7a72c2c70961b/includes/input_numbers.yaml#L20)
634636
- [script.set_high_temperature](https://github.com/basnijholt/home-assistant-config/blob/160be5f914b2dde4a8e8278c3aa03db2ea3210fa/scripts.yaml#L411)
637+
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L29)
635638
- [sensor.half_hour_before_alarm](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L439)
636639
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L299)
637640

@@ -730,6 +733,7 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
730733
- [script.set_low_temperature](https://github.com/basnijholt/home-assistant-config/blob/160be5f914b2dde4a8e8278c3aa03db2ea3210fa/scripts.yaml#L402)
731734
- [script.start_spotify](https://github.com/basnijholt/home-assistant-config/blob/160be5f914b2dde4a8e8278c3aa03db2ea3210fa/scripts.yaml#L38)
732735
- [script.turn_off_everything_non_automatic](https://github.com/basnijholt/home-assistant-config/blob/160be5f914b2dde4a8e8278c3aa03db2ea3210fa/scripts.yaml#L263)
736+
- [sensor.favorite_playlist_of_nearest_person](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L278)
733737

734738
### [Guest room IKEA Switch](https://github.com/basnijholt/home-assistant-config/blob/639ccfed5963266a6fb46f2af1b288e39d41516d/automations/control_switches.yaml#L467)
735739

@@ -853,6 +857,8 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
853857
- [input_boolean.automatic_dinner_area_light](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L46)
854858
- [input_boolean.guest_mode](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L22)
855859
- [input_select.sleep_mode](https://github.com/basnijholt/home-assistant-config/blob/07c0fdd72fdd676ab1b95db36f7baef313f7cff6/includes/input_selects.yaml#L11)
860+
- [sensor.activity_in_dinner_area](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L57)
861+
- [binary_sensor.activity_in_dinner_area](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L57)
856862

857863
### [Turn off automatic dinner area lights when turning off lights after 18:00](https://github.com/basnijholt/home-assistant-config/blob/67f798ec0349ca4be1ffafff16e4cc429ddb5c2f/automations/light.yaml#L111)
858864

@@ -943,9 +949,19 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
943949

944950
### [Turn on utility room / garage outside](https://github.com/basnijholt/home-assistant-config/blob/67f798ec0349ca4be1ffafff16e4cc429ddb5c2f/automations/light.yaml#L384)
945951

952+
*which uses:*
953+
- [sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
954+
- [sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
955+
- [binary_sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
956+
- [binary_sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
946957

947958
### [Turn off utility room / garage outside](https://github.com/basnijholt/home-assistant-config/blob/67f798ec0349ca4be1ffafff16e4cc429ddb5c2f/automations/light.yaml#L411)
948959

960+
*which uses:*
961+
- [sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
962+
- [sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
963+
- [binary_sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
964+
- [binary_sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
949965

950966
### [Turn on the outside front side of house](https://github.com/basnijholt/home-assistant-config/blob/67f798ec0349ca4be1ffafff16e4cc429ddb5c2f/automations/light.yaml#L437)
951967

@@ -990,6 +1006,11 @@ I run a [Supervised install](https://www.home-assistant.io/getting-started/) wit
9901006

9911007
In case the other automation failed
9921008

1009+
*which uses:*
1010+
- [sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
1011+
- [sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
1012+
- [binary_sensor.activity_outside_front_door](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L110)
1013+
- [binary_sensor.activity_outside_garage](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L116)
9931014

9941015
### [Update Zigbee2MQTT lights input_select options](https://github.com/basnijholt/home-assistant-config/blob/67f798ec0349ca4be1ffafff16e4cc429ddb5c2f/automations/light.yaml#L620)
9951016

@@ -1125,6 +1146,7 @@ to "Opt".
11251146
### [No one is home but high power usage](https://github.com/basnijholt/home-assistant-config/blob/e1ac0ba31e87fbe4e7fc9ddafc20681919bfe70e/automations/security.yaml#L74)
11261147

11271148
*which uses:*
1149+
- [sensor.power_consumption](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L311)
11281150
- [sensor.no_one_home](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L193)
11291151
- [binary_sensor.no_one_home](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L193)
11301152

@@ -1144,6 +1166,9 @@ to "Opt".
11441166

11451167

11461168

1169+
*which uses:*
1170+
- [sensor.door_to_outside_open](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L138)
1171+
- [binary_sensor.door_to_outside_open](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L138)
11471172

11481173
[^ toc](#automations---table-of-content)
11491174

@@ -1219,6 +1244,8 @@ to "Opt".
12191244

12201245
Check whether we are receiving messages over MQTT from my other HA instance.
12211246

1247+
*which uses:*
1248+
- [sensor.power_consumption](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L311)
12221249

12231250
### [Battery level low](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/system.yaml#L85)
12241251

@@ -1233,11 +1260,13 @@ to "Opt".
12331260
### [Time](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/test.yaml#L30)
12341261

12351262
*which uses:*
1263+
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L29)
12361264
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L299)
12371265

12381266
### [Flash lights](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/test.yaml#L43)
12391267

12401268
*which uses:*
1269+
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/sensors.yaml#L29)
12411270
- [sensor.time](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L299)
12421271

12431272
### [Call update_entity after light.turn_on/turn_off](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/test.yaml#L64)
@@ -1254,12 +1283,16 @@ to "Opt".
12541283

12551284
*which uses:*
12561285
- [sensor.dishwasher](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L213)
1286+
- [sensor.washing_machine](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L143)
12571287
- [binary_sensor.dishwasher](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L213)
1288+
- [binary_sensor.washing_machine](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L143)
12581289

12591290
### [Washing machine notification](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/utilities.yaml#L29)
12601291

12611292
*which uses:*
12621293
- [script.utility_notification](https://github.com/basnijholt/home-assistant-config/blob/160be5f914b2dde4a8e8278c3aa03db2ea3210fa/scripts.yaml#L524)
1294+
- [sensor.washing_machine](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L143)
1295+
- [binary_sensor.washing_machine](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L143)
12631296

12641297
### [Dishwasher notification](https://github.com/basnijholt/home-assistant-config/blob/896d09e1d72d5a2de280d9b091e72f717846000d/automations/utilities.yaml#L41)
12651298

@@ -1346,6 +1379,8 @@ to "Opt".
13461379

13471380
*which uses:*
13481381
- [input_boolean.work_hour_notification_sent](https://github.com/basnijholt/home-assistant-config/blob/3edc9d32263e8f60edc030c5f3ab8a089c469ea1/includes/input_booleans.yaml#L52)
1382+
- [sensor.worked_enough_today](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L165)
1383+
- [binary_sensor.worked_enough_today](https://github.com/basnijholt/home-assistant-config/blob/1bbf15def312391e65a0645100791d7d294d1265/includes/templates.yaml#L165)
13491384

13501385
### [Reset input_boolean at midnight](https://github.com/basnijholt/home-assistant-config/blob/f7bfc4913cf6e02bc5293357ea6dd41a806b28bb/automations/work.yaml#L32)
13511386

utils/update-readme.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ def line_number(fname, text, regex_check):
5454
raise ValueError(f"Text ({text}) doesn't exist in file {fname}.")
5555

5656

57+
def line_number_icase(fname, text):
58+
"""Case-insensitive line number search."""
59+
assert isinstance(text, str)
60+
text_lower = text.lower()
61+
with fname.open() as f:
62+
for i, line in enumerate(f):
63+
if text_lower in line.lower():
64+
return i + 1
65+
raise ValueError(f"Text ({text}) doesn't exist in file {fname}.")
66+
67+
5768
def permalink(fname):
5869
return URL.format(commit_hash=git_latest_edit_hash(fname), fname=fname)
5970

@@ -66,16 +77,21 @@ def permalink_automation(fname, automation):
6677
SKIP_LIST = {"switch.turn_on", "switch.turn_off"}
6778

6879

80+
def entity_name_to_friendly(name):
81+
"""Convert entity_id name to friendly name pattern (e.g., 'activity_in_living_room' -> 'activity in living room')."""
82+
return name.replace("_", " ")
83+
84+
6985
def permalink_entity(x, yaml_fname):
7086
if x in SKIP_LIST:
7187
raise ValueError("Incorrectly identified entity which is actually a service.")
7288
domain, name = x.split(".")
7389
fname = Path(yaml_fname or f"includes/{domain}s.yaml")
74-
# Try key format (e.g., "script_name:" in scripts.yaml), then unique_id format
75-
# (e.g., "unique_id: entity_name" in templates.yaml)
76-
for pattern in [f"{name}:", f"unique_id: {name}"]:
90+
friendly_name = entity_name_to_friendly(name)
91+
# Try: key format, unique_id format, then name format (case-insensitive via file search)
92+
for pattern in [f"{name}:", f"unique_id: {name}", f"name: {friendly_name}"]:
7793
with suppress(ValueError):
78-
from_line = line_number(fname, pattern, True)
94+
from_line = line_number_icase(fname, pattern)
7995
return permalink(fname) + f"#L{from_line}"
8096
raise ValueError(f"Entity {x} not found in {fname}")
8197

0 commit comments

Comments
 (0)