Sure,
I am using an esp32 mini with the following sensors:
- PIR for motion
- BME280 for temperature, humidity and “feels like” temperature calculation using the dewpint
- BH1750 for light intensity
- SGP30 for airquality with TVOC, eCO2, “raw H2” and “raw ethanol”
- INMP441 for noise level measurement and fft to detect specific sounds as seen here
- and the AMG8833 for room presence
Everything gets sent to HA with MQTT and are included in the recorder.
I am using the <Adafruit_AMG88xx.h>
library, so the usage is as in their examples.
The roompresence part hereby is:
unsigned int readAMG8833(float temperature)
{
unsigned int presence = 0u;
/* read amg8833 */
amg.readPixels(pixels);
/*calculate mean and std */
float sum = 0.0;
float amg_mean = 0.0;
float temp = 0.0;
for(int i = 0; i<64; ++i)
{
sum += pixels[i];
}
amg_mean = sum/64;
for(int i = 0; i<64; ++i)
{
temp = pixels[i] - amg_mean;
amg_STD += temp*temp;
}
amg_STD = sqrt(amg_STD/64);
/* check for presence */
if( amg_STD > amg_STD_THD )
{
presence = 1u;
}
else if( amg_mean > (temperature + temperature_offset) )
{
presence = 1u;
}
else
{
presence = 0u;
}
return presence;
}
Basically if either the standard deviation is higher than a threshold, or the mean is higher than the temperature reading + some offset (imagine being really close to the amg8833), I claim room presence.
I am polling the sensor every second and wait for a number of consecutive presence detections before I really claim room presence.
Data is sent every minute with MQTT.
The MQTT part is done with <PubSubClient.h>
and MQTT Discovery
So far it seems to have been working stable for a month, but I am still testing and experimenting
I am still playing a lot with the machine learning part, so I do not want to share the code yet before I have some real testing done, but I opted for DL to see if I can trim it down with int8/int16 quantization and L1 regularization to compute the inference on the ESP, but just an overview of what I am doing using python
- I poll the sql database of HA and filter for all the sensors in the living room where the sensornode is up, this also includes e.g. windowcontacts that I get with zigbee
- I preprocess the data, interpolating timestamps, scaling and so on
- For the amg8833 I train it with a CNN, do a globalmaxpool before it joins the other sensors
- The other sensors get your ordinary LSTM and ANN with the binary classification at the end
I have discovered that the SGP30 has great potential for detecting room presence as well (taking into account the open windows), so does the INMP441, but it’s still too early to draw conclusions
hope this was helpful!