Sensor Similarity Calculator Skill
Guidance for working with SensorSimilarityCalculator in the lib-electronic-components library.
For metadata-driven similarity architecture, see /similarity-metadata:
- SpecImportance levels (CRITICAL, HIGH, MEDIUM, LOW, OPTIONAL)
- ToleranceRule types (exactMatch, percentageTolerance, minimumRequired, etc.)
- SimilarityProfile contexts (DESIGN_PHASE, REPLACEMENT, COST_OPTIMIZATION, etc.)
- Calculator integration patterns and gotchas
Overview
The SensorSimilarityCalculator compares sensors based on:
- Sensor family - Temperature, accelerometer, humidity, pressure, etc.
- Equivalent parts - Known interchangeable sensors
- Package variants - Same sensor in different packages
Applicable Types
ComponentType.SENSOR
ComponentType.TEMPERATURE_SENSOR
ComponentType.ACCELEROMETER
// Any type starting with "SENSOR_", "TEMPERATURE_SENSOR_", "ACCELEROMETER_"
Returns false for null type.
Similarity Thresholds
HIGH_SIMILARITY = 0.9; // Same sensor, compatible packages
MEDIUM_SIMILARITY = 0.7; // Same sensor, incompatible packages
LOW_SIMILARITY = 0.3; // Different sensor families
Sensor Families
| Family |
Detection Patterns |
| Temperature |
LM35*, DS18*, TMP*, MAX318* |
| Accelerometer |
ADXL*, MMA*, LIS2*, LIS3*, BMI*, ICM* |
| Gyroscope |
L3GD*, ITG*, MPU* |
| Humidity |
SHT*, HIH*, AM*, HDC* |
| Pressure |
BMP*, BME*, MS56*, LPS* |
| Combined |
BME* (temp+humidity+pressure), MPU* (accel+gyro) |
Different sensor families always return LOW_SIMILARITY (0.3)
Temperature Sensor Equivalents
| Sensor |
Equivalents |
| DS18B20 |
DS18B20+, DS18B20Z, DS18B20/T |
| DS18B20 |
MAX31820 (compatible) |
| LM35 |
LM35D, LM35C, LM35A (grade variants) |
| TMP36 |
TMP36GT9Z, TMP36FS |
calculator.calculateSimilarity("DS18B20+", "DS18B20Z", registry);
// Returns 0.9 (same sensor, package variants)
Accelerometer Rules
Accelerometers are compared strictly by model:
// Same accelerometer
calculator.calculateSimilarity("ADXL345BCCZ", "ADXL345BCCZ-RL", registry);
// Returns 0.9 (same part, reel variant)
// Different models
calculator.calculateSimilarity("ADXL345", "ADXL346", registry);
// Returns 0.3 (different accelerometer)
Humidity Sensor Equivalents
| Family |
Compatible Parts |
| SHT3x |
SHT30, SHT31, SHT35 (within accuracy grades) |
| HIH613x |
HIH6130, HIH6131 |
| HDCx080 |
HDC1080, HDC2080 |
Pressure Sensor Equivalents
| Family |
Compatible Parts |
| BMx280 |
BMP280, BME280 (pressure compatible) |
| MS56xx |
MS5611, MS5607 |
Package Handling
Package compatibility is considered:
TO-92, TO-226 - Through-hole, compatible
SOT-23, TO-236 - SMD, compatible
LCC, LGA, LFCSP, QFN, BCC - MEMS packages, compatible within group
Test Examples
// Same sensor
calculator.calculateSimilarity("DS18B20", "DS18B20", registry);
// Returns 0.9
// Temperature variants
calculator.calculateSimilarity("LM35D", "LM35C", registry);
// Returns >= 0.7
// Cross-family (different families)
calculator.calculateSimilarity("DS18B20", "ADXL345", registry);
// Returns 0.3
// Same accelerometer, reel variant
calculator.calculateSimilarity("ADXL345BCCZ", "ADXL345BCCZ-RL", registry);
// Returns 0.9
Metadata-Driven Implementation (January 2026)
Status: ✅ Converted (PR #120)
The SensorSimilarityCalculator now uses a metadata-driven approach with spec-based comparison.
Specs Compared
| Spec |
Importance |
Tolerance Rule |
Description |
| sensorType |
CRITICAL |
exactMatch |
TEMPERATURE, ACCELEROMETER, GYROSCOPE, HUMIDITY, PRESSURE, COMBINED |
| family |
HIGH |
exactMatch |
LM35, DS18, ADXL, MMA, SHT, BME, BMP, etc. |
| interface |
MEDIUM |
exactMatch |
I2C, SPI, 1-Wire, Analog |
| package |
LOW |
exactMatch |
TO-92, SOIC, LGA, QFN, BCC, etc. |
Implementation Pattern
// Short-circuit check for CRITICAL incompatibility
if (!sensorType1.isEmpty() && !sensorType2.isEmpty() && !sensorType1.equals(sensorType2)) {
return LOW_SIMILARITY;
}
// Extract sensor type from MPN
private String extractSensorType(String mpn) {
SensorFamily family = determineSensorFamily(mpn);
return family.name(); // TEMPERATURE, ACCELEROMETER, etc.
}
// Extract sensor family with specific model number
private String extractSensorFamily(String mpn) {
if (mpn.matches("^ADXL[0-9]+.*")) return "ADXL345", "ADXL362", etc.;
if (mpn.matches("^DS18.*")) return "DS18B20", "DS18";
// ... returns specific sensor model
}
// Equivalent sensor boost
if (areEquivalentSensorsByFamily(mpn1, mpn2, family1, family2)) {
similarity = Math.max(similarity, HIGH_SIMILARITY);
}
Behavior Changes
| Comparison |
Legacy Result |
Metadata Result |
Notes |
| DS18B20 vs DS18B20 |
0.9 |
1.0 |
Identical sensor |
| DS18B20+ vs DS18B20Z |
0.9 |
1.0 |
Equivalent variants boost |
| ADXL345 vs ADXL345 |
0.9 |
1.0 |
Identical |
| ADXL345 vs ADXL346 |
0.3 |
0.703 |
Same type + interface = MEDIUM |
| ADXL345BCCZ vs ADXL345BCCZ-RL |
0.9 |
0.976 |
Same sensor, packaging variant |
| LM35 vs ADXL345 |
0.3 |
0.3 |
Short-circuit on sensor type |
Why more accurate: Metadata approach recognizes that ADXL345 vs ADXL346 share sensor type (ACCELEROMETER) and interface (SPI/I2C), giving them MEDIUM similarity instead of LOW. This is more accurate than treating them as completely different sensors.
Equivalent Sensor Groups
The calculator maintains equivalent sensor families:
- DS18B20 variants: DS18B20, DS18B20+, DS18B20Z all equivalent
- LM35 grades: LM35D, LM35C, LM35A all equivalent
- TMP36 variants: TMP36, TMP36GT9Z all equivalent
- MAX31820: Compatible with DS18B20
- SHT3x series: SHT30/31/35 within accuracy grades
- BMP/BME pressure: BMP280 ≈ BME280 for pressure
Learnings & Quirks
Temperature Sensors
- DS18B20: Digital, 1-Wire interface, ±0.5°C accuracy
- LM35: Analog output, 10mV/°C
- TMP36: Analog output, 10mV/°C, -40 to +125°C
- MAX31820: Drop-in replacement for DS18B20
Accelerometer Grades
- ADXL345B vs ADXL345: B is different interface option
- Different grades (BCCZ, BCCZ-RL) are same sensor
Humidity Sensor Accuracy
- SHT30: ±3% RH typical
- SHT31: ±2% RH typical
- SHT35: ±1.5% RH typical
- Higher number = better accuracy
Sensors Not Fully Supported
- HDC sensors may not be recognized by
isSensor() method
- Some newer sensors may need pattern updates
1---2name: similarity-sensor3description: Use when working with sensor similarity calculations - comparing temperature/accelerometer/humidity sensor MPNs, understanding sensor families, equivalent parts, or sensor-specific similarity logic.4---5
6# Sensor Similarity Calculator Skill
7
8Guidance for working with `SensorSimilarityCalculator` in the lib-electronic-components library.
9
10---
11
12**For metadata-driven similarity architecture**, see `/similarity-metadata`:
13- SpecImportance levels (CRITICAL, HIGH, MEDIUM, LOW, OPTIONAL)
14- ToleranceRule types (exactMatch, percentageTolerance, minimumRequired, etc.)
15- SimilarityProfile contexts (DESIGN_PHASE, REPLACEMENT, COST_OPTIMIZATION, etc.)
16- Calculator integration patterns and gotchas
17
18---
19
20## Overview
21
22The `SensorSimilarityCalculator` compares sensors based on:
23- **Sensor family** - Temperature, accelerometer, humidity, pressure, etc.
24- **Equivalent parts** - Known interchangeable sensors
25- **Package variants** - Same sensor in different packages
26
27## Applicable Types
28
29```java
30ComponentType.SENSOR
31ComponentType.TEMPERATURE_SENSOR
32ComponentType.ACCELEROMETER
33// Any type starting with "SENSOR_", "TEMPERATURE_SENSOR_", "ACCELEROMETER_"
34```
35
36Returns `false` for `null` type.
37
38## Similarity Thresholds
39
40```java
41HIGH_SIMILARITY = 0.9; // Same sensor, compatible packages
42MEDIUM_SIMILARITY = 0.7; // Same sensor, incompatible packages
43LOW_SIMILARITY = 0.3; // Different sensor families
44```
45
46## Sensor Families
47
48| Family | Detection Patterns |
49|--------|-------------------|
50| Temperature | LM35*, DS18*, TMP*, MAX318* |
51| Accelerometer | ADXL*, MMA*, LIS2*, LIS3*, BMI*, ICM* |
52| Gyroscope | L3GD*, ITG*, MPU* |
53| Humidity | SHT*, HIH*, AM*, HDC* |
54| Pressure | BMP*, BME*, MS56*, LPS* |
55| Combined | BME* (temp+humidity+pressure), MPU* (accel+gyro) |
56
57**Different sensor families always return LOW_SIMILARITY (0.3)**
58
59## Temperature Sensor Equivalents
60
61| Sensor | Equivalents |
62|--------|-------------|
63| DS18B20 | DS18B20+, DS18B20Z, DS18B20/T |
64| DS18B20 | MAX31820 (compatible) |
65| LM35 | LM35D, LM35C, LM35A (grade variants) |
66| TMP36 | TMP36GT9Z, TMP36FS |
67
68```java
69calculator.calculateSimilarity("DS18B20+", "DS18B20Z", registry);
70// Returns 0.9 (same sensor, package variants)
71```
72
73## Accelerometer Rules
74
75Accelerometers are compared strictly by model:
76
77```java
78// Same accelerometer
79calculator.calculateSimilarity("ADXL345BCCZ", "ADXL345BCCZ-RL", registry);
80// Returns 0.9 (same part, reel variant)
81
82// Different models
83calculator.calculateSimilarity("ADXL345", "ADXL346", registry);
84// Returns 0.3 (different accelerometer)
85```
86
87## Humidity Sensor Equivalents
88
89| Family | Compatible Parts |
90|--------|------------------|
91| SHT3x | SHT30, SHT31, SHT35 (within accuracy grades) |
92| HIH613x | HIH6130, HIH6131 |
93| HDCx080 | HDC1080, HDC2080 |
94
95## Pressure Sensor Equivalents
96
97| Family | Compatible Parts |
98|--------|------------------|
99| BMx280 | BMP280, BME280 (pressure compatible) |
100| MS56xx | MS5611, MS5607 |
101
102## Package Handling
103
104Package compatibility is considered:
105- `TO-92`, `TO-226` - Through-hole, compatible
106- `SOT-23`, `TO-236` - SMD, compatible
107- `LCC`, `LGA`, `LFCSP`, `QFN`, `BCC` - MEMS packages, compatible within group
108
109## Test Examples
110
111```java
112// Same sensor
113calculator.calculateSimilarity("DS18B20", "DS18B20", registry);
114// Returns 0.9
115
116// Temperature variants
117calculator.calculateSimilarity("LM35D", "LM35C", registry);
118// Returns >= 0.7
119
120// Cross-family (different families)
121calculator.calculateSimilarity("DS18B20", "ADXL345", registry);
122// Returns 0.3
123
124// Same accelerometer, reel variant
125calculator.calculateSimilarity("ADXL345BCCZ", "ADXL345BCCZ-RL", registry);
126// Returns 0.9
127```
128
129---
130
131## Metadata-Driven Implementation (January 2026)
132
133**Status**: ✅ Converted (PR #120)
134
135The `SensorSimilarityCalculator` now uses a **metadata-driven approach** with spec-based comparison.
136
137### Specs Compared
138
139| Spec | Importance | Tolerance Rule | Description |
140|------|-----------|----------------|-------------|
141| **sensorType** | CRITICAL | exactMatch | TEMPERATURE, ACCELEROMETER, GYROSCOPE, HUMIDITY, PRESSURE, COMBINED |
142| **family** | HIGH | exactMatch | LM35, DS18, ADXL, MMA, SHT, BME, BMP, etc. |
143| **interface** | MEDIUM | exactMatch | I2C, SPI, 1-Wire, Analog |
144| **package** | LOW | exactMatch | TO-92, SOIC, LGA, QFN, BCC, etc. |
145
146### Implementation Pattern
147
148```java
149// Short-circuit check for CRITICAL incompatibility
150if (!sensorType1.isEmpty() && !sensorType2.isEmpty() && !sensorType1.equals(sensorType2)) {
151 return LOW_SIMILARITY;
152}
153
154// Extract sensor type from MPN
155private String extractSensorType(String mpn) {
156 SensorFamily family = determineSensorFamily(mpn);
157 return family.name(); // TEMPERATURE, ACCELEROMETER, etc.
158}
159
160// Extract sensor family with specific model number
161private String extractSensorFamily(String mpn) {
162 if (mpn.matches("^ADXL[0-9]+.*")) return "ADXL345", "ADXL362", etc.;
163 if (mpn.matches("^DS18.*")) return "DS18B20", "DS18";
164 // ... returns specific sensor model
165}
166
167// Equivalent sensor boost
168if (areEquivalentSensorsByFamily(mpn1, mpn2, family1, family2)) {
169 similarity = Math.max(similarity, HIGH_SIMILARITY);
170}
171```
172
173### Behavior Changes
174
175| Comparison | Legacy Result | Metadata Result | Notes |
176|-----------|--------------|-----------------|-------|
177| DS18B20 vs DS18B20 | 0.9 | 1.0 | Identical sensor |
178| DS18B20+ vs DS18B20Z | 0.9 | 1.0 | Equivalent variants boost |
179| ADXL345 vs ADXL345 | 0.9 | 1.0 | Identical |
180| ADXL345 vs ADXL346 | 0.3 | 0.703 | Same type + interface = MEDIUM |
181| ADXL345BCCZ vs ADXL345BCCZ-RL | 0.9 | 0.976 | Same sensor, packaging variant |
182| LM35 vs ADXL345 | 0.3 | 0.3 | Short-circuit on sensor type |
183
184**Why more accurate**: Metadata approach recognizes that ADXL345 vs ADXL346 share sensor type (ACCELEROMETER) and interface (SPI/I2C), giving them MEDIUM similarity instead of LOW. This is more accurate than treating them as completely different sensors.
185
186### Equivalent Sensor Groups
187
188The calculator maintains equivalent sensor families:
189- **DS18B20 variants**: DS18B20, DS18B20+, DS18B20Z all equivalent
190- **LM35 grades**: LM35D, LM35C, LM35A all equivalent
191- **TMP36 variants**: TMP36, TMP36GT9Z all equivalent
192- **MAX31820**: Compatible with DS18B20
193- **SHT3x series**: SHT30/31/35 within accuracy grades
194- **BMP/BME pressure**: BMP280 ≈ BME280 for pressure
195
196---
197
198## Learnings & Quirks
199
200### Temperature Sensors
201- DS18B20: Digital, 1-Wire interface, ±0.5°C accuracy
202- LM35: Analog output, 10mV/°C
203- TMP36: Analog output, 10mV/°C, -40 to +125°C
204- MAX31820: Drop-in replacement for DS18B20
205
206### Accelerometer Grades
207- ADXL345B vs ADXL345: B is different interface option
208- Different grades (BCCZ, BCCZ-RL) are same sensor
209
210### Humidity Sensor Accuracy
211- SHT30: ±3% RH typical
212- SHT31: ±2% RH typical
213- SHT35: ±1.5% RH typical
214- Higher number = better accuracy
215
216### Sensors Not Fully Supported
217- HDC sensors may not be recognized by `isSensor()` method
218- Some newer sensors may need pattern updates
219
220<!-- Add new learnings above this line -->