[TEMT] Added Temt6000 light sensor using a d1 mini (#1550)
Added light sensor TEMPT6000
This commit is contained in:
1 parent
c12f51ee0e
commit
7bae999435
8 files changed
+175
-4
No files matched your search
@@ -326,6 +326,7 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
|
||||
//#define ZsensorHCSR501 "HCSR501" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
|
||||
//#define ZsensorADC "ADC" //ESP8266, Arduino, ESP32
|
||||
//#define ZsensorBH1750 "BH1750" //ESP8266, Arduino, ESP32
|
||||
//#define ZsensorTEMT6000 "TEMT6000" //ESP8266
|
||||
//#define ZsensorTSL2561 "TSL2561" //ESP8266, Arduino, ESP32
|
||||
//#define ZsensorBME280 "BME280" //ESP8266, Arduino, ESP32
|
||||
//#define ZsensorHTU21 "HTU21" //ESP8266, Arduino, ESP32
|
||||
|
||||
@@ -752,6 +752,29 @@ void pubMqttDiscovery() {
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorTEMT6000
|
||||
# define TEMT6000parametersCount 3
|
||||
Log.trace(F("TEMT6000Discovery" CR));
|
||||
char* TEMT6000sensor[TEMT6000parametersCount][8] = {
|
||||
{"sensor", "lux", "TEMT6000", "illuminance", jsonLux, "", "", "lx"},
|
||||
{"sensor", "ftcd", "TEMT6000", "", jsonFtcd, "", "", ""},
|
||||
{"sensor", "wattsm2", "TEMT6000", "", jsonWm2, "", "", "wm²"}
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
};
|
||||
|
||||
for (int i = 0; i < TEMT6000parametersCount; i++) {
|
||||
//trc(TEMT6000sensor[i][1]);
|
||||
createDiscovery(TEMT6000sensor[i][0],
|
||||
subjectTEMT6000toMQTT, TEMT6000sensor[i][1], (char*)getUniqueId(TEMT6000sensor[i][1], TEMT6000sensor[i][2]).c_str(),
|
||||
will_Topic, TEMT6000sensor[i][3], TEMT6000sensor[i][4],
|
||||
TEMT6000sensor[i][5], TEMT6000sensor[i][6], TEMT6000sensor[i][7],
|
||||
0, Gateway_AnnouncementMsg, will_Message, true, "",
|
||||
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
|
||||
stateClassNone //State Class
|
||||
);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorTSL2561
|
||||
# define TSL2561parametersCount 3
|
||||
Log.trace(F("TSL2561Discovery" CR));
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
This is the Light Meter Addon based on modules with a TEMT6000:
|
||||
- Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2)
|
||||
- Required Hardware Module: TEMT6000
|
||||
- Dependencies: none
|
||||
|
||||
Connection Scheme:
|
||||
--------------------
|
||||
|
||||
TEMT6000------> ESP8266
|
||||
==============================================
|
||||
Vcc ---------> 3.3V
|
||||
GND ---------> GND
|
||||
SIG ---------> A0
|
||||
|
||||
Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema
|
||||
|
||||
This file is part of OpenMQTTGateway.
|
||||
|
||||
OpenMQTTGateway is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorTEMT6000
|
||||
|
||||
# include "Wire.h"
|
||||
# include "math.h"
|
||||
|
||||
void setupZsensorTEMT6000() {
|
||||
Log.notice(F("Setup TEMT6000 on pin: %i" CR), TEMT6000LIGHTSENSORPIN);
|
||||
pinMode(TEMT6000LIGHTSENSORPIN, INPUT);
|
||||
}
|
||||
|
||||
void MeasureLightIntensityTEMT6000() {
|
||||
if (millis() > (timetemt6000 + TimeBetweenReadingtemt6000)) {
|
||||
static uint32_t persisted_lux;
|
||||
timetemt6000 = millis();
|
||||
|
||||
Log.trace(F("Creating TEMT6000 buffer" CR));
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject TEMT6000data = jsonBuffer.to<JsonObject>();
|
||||
|
||||
float volts = analogRead(TEMT6000LIGHTSENSORPIN) * 5.0 / 1024.0;
|
||||
float amps = volts / 10000.0; // across 10,000 Ohms
|
||||
float microamps = amps * 1000000;
|
||||
float lux = microamps * 2.0;
|
||||
|
||||
if (persisted_lux != lux || temt6000_always) {
|
||||
persisted_lux = lux;
|
||||
|
||||
TEMT6000data["lux"] = (float)lux;
|
||||
TEMT6000data["ftcd"] = (float)(lux) / 10.764;
|
||||
TEMT6000data["wattsm2"] = (float)(lux) / 683.0;
|
||||
|
||||
pub(subjectTEMT6000toMQTT, TEMT6000data);
|
||||
} else {
|
||||
Log.trace(F("Same lux value, do not send" CR));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
This is the Light Meter Addon based on modules with a TEMT6000:
|
||||
- Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2)
|
||||
- Required Hardware Module: TEMT6000
|
||||
- Dependencies: none
|
||||
|
||||
Connection Scheme:
|
||||
--------------------
|
||||
|
||||
TEMT6000 ----> ESP8266
|
||||
==============================================
|
||||
Vcc ---------> 3.3V
|
||||
GND ---------> GND
|
||||
SIG ---------> A0
|
||||
|
||||
Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema
|
||||
|
||||
This file is part of OpenMQTTGateway.
|
||||
|
||||
OpenMQTTGateway is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef config_TEMT6000_h
|
||||
#define config_TEMT6000_h
|
||||
|
||||
extern void setupTEMT6000();
|
||||
extern void TEMT6000toMQTT();
|
||||
|
||||
#define temt6000_always true // if false only send current value if it has changed
|
||||
#define TEMT6000LIGHTSENSORPIN A0 //Ambient light sensor reading = ADC0
|
||||
#define TimeBetweenReadingtemt6000 10000 //10000 ms
|
||||
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectTEMT6000toMQTT "/LIGHTtoMQTT"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timetemt6000 = 0;
|
||||
|
||||
#endif
|
||||
@@ -109,6 +109,9 @@ struct GfSun2000Data {};
|
||||
#ifdef ZsensorBH1750
|
||||
# include "config_BH1750.h"
|
||||
#endif
|
||||
#ifdef ZsensorTEMT6000
|
||||
# include "config_TEMT6000.h"
|
||||
#endif
|
||||
#ifdef ZsensorTSL2561
|
||||
# include "config_TSL2561.h"
|
||||
#endif
|
||||
@@ -872,6 +875,10 @@ void setup() {
|
||||
setupZsensorBH1750();
|
||||
modules.add(ZsensorBH1750);
|
||||
#endif
|
||||
#ifdef ZsensorTEMT6000
|
||||
setupZsensorTEMT6000();
|
||||
modules.add(ZsensorTEMT6000);
|
||||
#endif
|
||||
#ifdef ZsensorTSL2561
|
||||
setupZsensorTSL2561();
|
||||
modules.add(ZsensorTSL2561);
|
||||
@@ -1638,6 +1645,9 @@ void loop() {
|
||||
#ifdef ZsensorBH1750
|
||||
MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750
|
||||
#endif
|
||||
#ifdef ZsensorTEMT6000
|
||||
MeasureLightIntensityTEMT6000();
|
||||
#endif
|
||||
#ifdef ZsensorTSL2561
|
||||
MeasureLightIntensityTSL2561();
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user