بنقرة واحدة
hub-temperature-scale-honoring
Convert sensor temperatures to hub's configured scale (°C or °F) before emitting events
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Convert sensor temperatures to hub's configured scale (°C or °F) before emitting events
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Pattern for keeping a rolling temperature-trend sample buffer in Hubitat state, computing slope over a configurable window, and classifying rising/falling/steady/unknown.
Implement Tuya Local v3.3 Groovy drivers on Hubitat using rawSocket, AES-128-ECB, queued retries, and defensive frame parsing.
Use Hubitat async HTTP plus a request queue to authenticate with Cognito, cache tokens in state, refresh proactively, and replay a single 401-failed request.
When two agents produce overlapping skills in one session, consolidate by merging unique content into the highest-confidence existing skill.
Never let cached-state dedup bypass session validity in cloud-backed Hubitat drivers.
Standard guard pattern for async HTTP response callbacks in Hubitat drivers
| name | Hub Temperature Scale Honoring |
| description | Convert sensor temperatures to hub's configured scale (°C or °F) before emitting events |
| domain | events, temperature, units |
| confidence | high |
| source | validated in PurpleAir v0.4.0 (commit 2d62b05) and Honeywell T6 Pro production use |
Hubitat hubs can be configured in either Celsius or Fahrenheit. When a driver receives temperature data from an API or device (often in a specific unit), it must convert to the hub's configured scale before emitting the attribute.
Failing to do this confuses apps (they expect temp in hub scale), breaks automations (thermostat rules assume matching scale), and creates poor UX (dashboard shows nonsensical values).
Store the hub's temperature scale on driver install or update:
void updated() {
unschedule()
// Discover hub temperature scale once
String tempScale = location.temperatureScale ?: "F"
// ... rest of initialization ...
}
Create a reusable helper for API-to-hub conversion:
/**
* Convert temperature from one scale to another.
*
* @param temp Temperature value (BigDecimal for precision)
* @param fromScale Source scale ("C" or "F")
* @param toScale Target scale ("C" or "F")
* @return Converted temperature (BigDecimal)
*/
BigDecimal convertTemperature(BigDecimal temp, String fromScale, String toScale) {
if (fromScale == toScale) return temp
if (fromScale == "F" && toScale == "C") {
return ((temp - 32) * 5 / 9).setScale(2, BigDecimal.ROUND_HALF_UP)
} else if (fromScale == "C" && toScale == "F") {
return ((temp * 9 / 5) + 32).setScale(2, BigDecimal.ROUND_HALF_UP)
}
return temp // No conversion needed
}
void parseApiResponse(def json) {
// API returns temp in Fahrenheit
BigDecimal apiTemp = json.temperature as BigDecimal
String hubScale = location.temperatureScale ?: "F"
// Convert if needed
BigDecimal emitTemp = convertTemperature(apiTemp, "F", hubScale)
String unitString = hubScale == "C" ? "°C" : "°F"
sendEvent(
name: "temperature",
value: emitTemp.toFloat(),
unit: unitString,
descriptionText: "Temperature is ${emitTemp}${unitString}"
)
}
Applied in PurpleAir AQI v0.4.0 (commit 2d62b05):
Applied in Honeywell T6 Pro v0.4.0+:
location.temperatureScale❌ Hard-coded unit assumption:
sendEvent(name: "temperature", value: 72, unit: "°F") // Breaks if hub is °C
❌ Missing conversion:
BigDecimal apiTemp = json.temperature // API in °C, hub expects °F
sendEvent(name: "temperature", value: apiTemp, unit: location.temperatureScale)
❌ Conversion at every emit:
for (sensor in sensors) {
BigDecimal temp = convertTemperature(sensor.temp, "F", location.temperatureScale)
// ... repeat in multiple event handlers ...
}
Instead: store the hub scale once, reuse it.
A missed conversion can go unnoticed for months if a user has only one temperature device and few automations. Scale-aware auditing should be part of any temperature-emitting driver review.