Skip to content

Commit

Permalink
usermod bme280
Browse files Browse the repository at this point in the history
Added public variables to the BME280 usermod based on those in the Temperature usermod.  Only complication is that this usermod utilises different function calls depending on whether user defines celsius or not.  I have handled this for the temperature, but the Dew Point and Heat Index are relative to the temperature.

I've also addressed some areas where I'd previously assumed Celsius for reporting purposes as my test case is using Farenheit.
  • Loading branch information
albarlow committed Jul 19, 2022
1 parent bee48da commit 9d57439
Showing 1 changed file with 63 additions and 8 deletions.
71 changes: 63 additions & 8 deletions usermods/BME280_v2/usermod_bme280.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,23 @@ bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Inform

String t = String("homeassistant/sensor/") + mqttClientID + "/temperature/config";

_createMqttSensor("Temperature", mqttTemperatureTopic, "temperature", "°C");
#ifdef Celsius
_createMqttSensor("Temperature", mqttTemperatureTopic, "temperature", "°C");
#else
_createMqttSensor("Temperature", mqttTemperatureTopic, "temperature", "°F");
#endif
_createMqttSensor("Pressure", mqttPressureTopic, "pressure", "hPa");
_createMqttSensor("Humidity", mqttHumidityTopic, "humidity", "%");
_createMqttSensor("HeatIndex", mqttHeatIndexTopic, "temperature", "°C");
_createMqttSensor("DewPoint", mqttDewPointTopic, "temperature", "°C");
#ifdef Celsius
_createMqttSensor("HeatIndex", mqttHeatIndexTopic, "temperature", "°C");
#else
_createMqttSensor("HeatIndex", mqttHeatIndexTopic, "temperature", "°F");
#endif
#ifdef Celsius
_createMqttSensor("DewPoint", mqttDewPointTopic, "temperature", "°C");
#else
_createMqttSensor("DewPoint", mqttDewPointTopic, "temperature", "°F");
#endif
}

// Create an MQTT Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop.
Expand Down Expand Up @@ -260,13 +272,43 @@ bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Inform
}
}
}

/*
* API calls te enable data exchange between WLED modules
*/
inline float getTemperatureC() {
#ifdef Celsius
return (float)sensorTemperature;
#else
return (float)sensorTemperature * 1.8f + 32;
#endif

}
inline float getTemperatureF() {
#ifdef Celsius
return ((float)sensorTemperature -32) * 0.56f;
#else
return (float)sensorTemperature;
#endif
}
inline float getHumidity() {
return (float)sensorHumidity;
}
inline float getPressure() {
return (float)sensorPressure;
}
inline float getDewPoint() {
return (float)sensorDewPoint;
}
inline float getHeatIndex() {
return (float)sensorHeatIndex;
}

// Publish Sensor Information to Info Page
void addToJsonInfo(JsonObject &root)
{
JsonObject user = root[F("u")];
if (user.isNull())
user = root.createNestedObject(F("u"));
if (user.isNull()) user = root.createNestedObject(F("u"));

if (sensorType==0) //No Sensor
{
Expand All @@ -292,14 +334,27 @@ bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Inform
JsonArray heatindex_json = user.createNestedArray("Heat Index");
JsonArray dewpoint_json = user.createNestedArray("Dew Point");
temperature_json.add(sensorTemperature);
temperature_json.add(F("°C"));
#ifdef Celsius
temperature_json.add(F("°C"));
#else
temperature_json.add(F("°F"));
#endif
humidity_json.add(sensorHumidity);
humidity_json.add(F("%"));
pressure_json.add(sensorPressure);
pressure_json.add(F("°C"));
pressure_json.add(F("hPa"));
heatindex_json.add(sensorHeatIndex);
heatindex_json.add(F("°C"));
#ifdef Celsius
heatindex_json.add(F("°C"));
#else
heatindex_json.add(F("°F"));
#endif
dewpoint_json.add(sensorDewPoint);
#ifdef Celsius
dewpoint_json.add(F("°C"));
#else
dewpoint_json.add(F("°F"));
#endif
dewpoint_json.add(F("°C"));
}
return;
Expand Down

0 comments on commit 9d57439

Please sign in to comment.