Sound level sensor

I should have a few updated Hubitat groovy drivers and an example sketch for you to try out this evening.

I am looking forward to hearing what the children think of your new use for home automation! :wink:

1 Like

Question though. Frequently their outbursts are a quick yell or scream. Does the HE poll the Hubduino device, or does the device send data on a regular interval to the HE?

Either way, since it will probably be on an interval, I would need the peak level during the last interval, not the current SPL value.

The HubDuino microcontroller is configured to poll at a certain frequency. Each time it polls, it sends data to Hubitat. So, yea, it is possible we'd miss a short, but loud, outburst...

We'll be starting by simply using the PS_Voltage HubDuino device. If it needs to be modified, or a new device created specifically for SPL measurements, we can cross that bridge when we get to it.

Here is the PS_Voltage device source code that you may want to take a look at.

We've got lots of options available! :wink:

Here's an example of how to use this thing:

https://wiki.dfrobot.com/Gravity__Analog_Sound_Level_Meter_SKU_SEN0232

Pretty simple, just multiply the voltage by 50 to get the dBa. What is the minimum polling frequency on the Hubduino, and how does short polling intervals affect performance of the HE?

I'm thinking I may have to track the max dBa with a variable that gets reset on each poll so I don't miss quick outbursts or when a kid hits the coffee table when he's frustrated playing a game.

OK, so I have the basic functionality up and running successfully on my test hub. I have update the "HubDuino Parent Ethernet" driver and I have added the "Child Sound Pressure Level" driver. Please update/add these new drivers your Hubitat system.

The Child Sound Pressure Level driver supports the Contact Sensor capability in addition to the SPL capability. You can set a max SPL threshold, above which the contact attribute will read CLOSED, otherwise it will read OPEN.

I have written the following simple sketch that will allow you to at least start your testing. I agree that it is unlikely to catch short-loud outbursts. But this will at least provide a proof of concept. I'll work on a SPL specific device that samples at a high rate, stores the MAX SPL, and then transmits it at a lower frequency.

The sketch is configured to read & average 3 samples every 30 seconds, and then transmit the SPL level to Hubitat. I scaled the SPL board's .6v to 2.6v to the full scale 3.3v capable on my NodeMCU ESP8266 board's AO input. The scaling will result in the correct SPL values per the spec sheet (I believe! Please verify.)

Sample sketch:

//******************************************************************************************
//  File: ST_Anything_SPL_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_SPL implements the following Hubitat Capability as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Sound Pressure Level device (using a simple analog output)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-07-08  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_VOLTAGE_1               A0  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                            //  <---You must edit this line!
String str_password = "yourPASSWORDhere";                          //  <---You must edit this line!
IPAddress ip(192, 168, 1, 227);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 1, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
//IPAddress hubIp(192, 168, 1, 149);  // smartthings hub ip       //  <---You must edit this line!
//const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
IPAddress hubIp(192, 168, 1, 145);    // hubitat hub ip         //  <---You must edit this line!
const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
    static st::PS_Voltage sensor1(F("soundPressureLevel1"), 30, 0, PIN_VOLTAGE_1, 0, 1024, 0.0, 165.0, 3);  
    
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString, "OfficeESP");
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
    
  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}
1 Like

@signal15 - I have finished the development of a high-speed SPL measurement device for ST_Anything/HubDuino. I have added the new PS_SoundPressureLevel.h and PS_SoundPressureLevel.cpp files to the ST_Anything library.

This new class polls the analog input pin every 50ms (by default) and keeps the MAX SPL value. It then transmits this value ~every 30 seconds (defined in the example sketch) to Hubitat and then resets the local variable to gather the next MAX value.

The new example sketch is named ST_Anything_SPL_ESP8266WiFi.ino.

This should get you going. Can't wait to hear how the children react! :wink:

Here is the documentation for the new SPL class/device.

//  Summary:  PS_SoundPressureLevel is a class which implements the "Sound Pressure Level" device capability.
//			  It inherits from the st::PollingSensor class.  The current version uses an analog input to measure the 
//			  voltage on an anlog input pin and then scale it to engineering units.
//
//			  The last four arguments of the constructor are used as arguments to an Arduino map() function which 
//			  is used to scale the analog input readings (e.g. 0 to 1024) to Engineering Units before sending to SmartThings. 
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example: static st::PS_SoundPressureLevel sensor1(F("soundPressureLevel1"), 60, 0, PIN_SPL, 0, 1024, 0.0, 165.0, 50);
//
//			  st::PS_SoundPressureLevel() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used as an analog input
//				- double s_l - OPTIONAL - first argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - minimum raw AI value
//				- double s_h - OPTIONAL - second argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - maximum raw AI value
//				- double m_l - OPTIONAL - third argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Min (or Max if inverting)
//				- double m_h - OPTIONAL - fourth argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Max (or Min if inverting)
//              - long m_nHighSpeedPollingInterval - OPTIONAL - number of milliseconds between high speed analog reads - defaults to 50ms

Ok, all installed. Man, the HE guys need to work on the driver import stuff, that's a whole lot of clicking and copy pasta. Too bad we can't just feed it a list of URL's or a JSON file that details where to get everything (with regular update checks). :slight_smile:

I needed to compile this for an ESP32, so I made some modifications to the sketch you posted. I'm seeing 2 problems:

  1. The dBA level is like 600 something, so it's not being calculated correctly.
  2. The child device only gets on dBA update, and then no more. See Event table below.

Here's my sketch for the ESP32:

//******************************************************************************************
//  File: ST_Anything_SPL_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_SPL implements the following Hubitat Capability as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Sound Pressure Level device (using a simple analog output)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-07-08  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP32WiFi
//******************************************************************************************
#include <SmartThingsESP32WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_VOLTAGE_1               A19  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "**";                            //  <---You must edit this line!
String str_password = "***";                          //  <---You must edit this line!
IPAddress ip(*****);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(***);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(8, 8, 8, 8);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
//IPAddress hubIp(192, 168, 1, 149);  // smartthings hub ip       //  <---You must edit this line!
//const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
IPAddress hubIp(***);    // hubitat hub ip         //  <---You must edit this line!
const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
static st::PS_Voltage sensor1(F("soundPressureLevel1"), 30, 0, PIN_VOLTAGE_1, 0, 1024, 0.0, 165.0, 3);  

  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
//STATIC IP Assignment - Recommended
//    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString, "OfficeESP");
st::Everything::SmartThing = new st::SmartThingsESP32WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);

//DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
//st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
  
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************

  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}
1 Like

Please see my post just prior to your most recent one for the latest files. You'll want to use my new PS_SoundPressureLevel device instead of the PS_Voltage device.

Also, to fix the scaling issue, change the "1024" to "4096" as the ESP32 has a 12bit ADC versus the ESP8266's 10bit ADC.

I used the new file and converted it to ESP32 just like the last one. I changed the 1024 to 4096:

static st::PS_SoundPressureLevel sensor1(F("soundPressureLevel1"), 30, 0, PIN_SPL, 0, 4096, 0.0, 165.0, 50);

Still getting a pretty large value for the sound level, and only one update. Plus, it says 30 seconds above, but if you note the timestamps, it's only checking in once a minute.

How are you calculating the SPL? It should be the voltage * 50. I didn't see anywhere in your code where this was happening.

I was just thinking, when my kids become teenagers, this house is pretty much partyproof, unlike my parent's house was. :slight_smile:

Edit: hold up, looks like the pinout I was looking at might have been incorrect.

Edit 2: Looks like it's fine. The pinout image I was looking at for this board has 3 GND pins. But one of them on the board is labeled "SND". I switched it to another pin, but no change. I'm getting checkins, but no soundPressureLevel attribute updates.

Edit 3: Pin problem! I was using A19/pin 26. Switched it to pin 36 and now it works. Here's the pinouts for my board:

Here's the events:

If I change the polling interval to something like 1 or 2 seconds, what will happen? Is that all I need to change? Is it going to hammer my HE to death? In order to change behavior, I need the consequences to be pretty immediate.

Is the contact sensor implemented yet? If not, that's probably fine. I can just create a rule that compares the value instead.

It doesn't seem to close the contact when I make a bunch of noise. I have this for now:

Hehehehehehe.

Is this how the PS_Illuminance library works too? If not, could it? I tried to implement a lum sensor a while ago and it wasn't very consistent. I had a feeling if the a cloud happened to be passing over or a bird was flying by I seemed to get vastly different readings. But it also could have been my sensor. But if this type of architecture isn't used for the lum library, that would totally explain my odd results.

Yes, sending data to Hubitat every 1-2 seconds is excessive and may lead to problems on your hub. I wouldn't do that. That is why I spent hours last night writing a new PS_SoundPressureLevel device for you that still reads the analog input very quickly, but can be controlled as to how frequently data is sent to the hub. I understand the desire for instant feedback to the little ones, but is 15 to 30 seconds really that much of a delay?

Yes, the contact sensor feature is implemented inside the Groovy Driver for the Sound Pressure Level child device. Did you configure the user setting for the SPL threshold in the child device?

No, the Illuminance device just reads the sensor value and transmits the result. There is no logic built into that device to perform filtering/averaging. If you want a more sophisticated illuminance sensor you could simply use the PS_Voltage device, but still use the "illuminance1" name when you declare it in the setup() routine of the sketch. The PS_Voltage device has a lot of options for filtering that will help eliminate high levels of variability. Just read through the comments at the top of the PS_Voltage.cpp file for all of the details.

I did configure the threshold. However, under current states in the device screen, there is no attribute listed for contact. And, when I exceed the threshold, the rule I had that used it never triggers.

Please show me a screenshot of the Device Details page for the Sound Pressure Level device. I tested it last night and the contact sensor works perfectly, assuming you set the max spl value and SAVE the device afterwards. Then, it simply needs an update from the HubDuino board to populate the contact sensor attribute on the screen.

See...that's why you're the master and I'm still the Padawan. :wink: That's brilliant! I will give that a try later today. Thanks!!

Threshold set to 75 and saved. I even went back out of it and back in to make sure. Just tripped it with a 93db clap.

Also seeing a bunch of these in the logs:

Try entering 75.0 instead of just 75 and see if that clears up the error. I will debug that issue later tonight.

I changed line 57 to this:

        if (tmpValue >= Float.valueOf(maxSPL)) {

This seems to have fixed the problem. The contact sensor seems to be working now.

1 Like

Thanks, I updated my GitHub repo with that change.