jcallaghan / home-assistant-config

My Home Assistant configuration & documentation.
https://www.jcallaghan.com/
MIT License
175 stars 8 forks source link

Weather station - Environmental noise (dB) 🎤 #40

Open jcallaghan opened 4 years ago

jcallaghan commented 4 years ago

Environmental noise (dB)

Notes

I had planned to use an Omnidirectional Microphone Module I2S Interface INMP441 but the I2S interface seems to have poor documentation and community traction. Instead, I opted for a more sensitive decibel meter which I think will perform better for this project.

Research

Originally posted by @jcallaghan in https://github.com/jcallaghan/home-assistant-config/issues/13#issuecomment-624065984

jcallaghan commented 4 years ago

Install steps

pip3 install pyusb
git clone https://github.com/mepster/wensn.git
cd wensn/
sudo python wensn.py
jcallaghan commented 4 years ago

Device issues Wrong model

Had to change the device information in the wensn.py script.

    dev = usb.core.find(idVendor=0x64bd, idProduct=0x74e3)

Now getting the following error.

pi@raspberrypi:~/wensn $ sudo python3 wensn.py
DEVICE ID 64bd:74e3 on Bus 001 Address 010 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x110 USB 1.1
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :    0x8 (8 bytes)
 idVendor               : 0x64bd
 idProduct              : 0x74e3
 bcdDevice              :    0x0 Device 0.0
 iManufacturer          :    0x1 SM
 iProduct               :    0x2 SM
 iSerialNumber          :    0x0 
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 50 mA ===================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x29 (41 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0 
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0x19 (50 mA)
    INTERFACE 0: Human Interface Device ====================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :    0x3 Human Interface Device
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0 
      ENDPOINT 0x2: Interrupt OUT ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x8 (8 bytes)
       bInterval        :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x8 (8 bytes)
       bInterval        :    0x0
setMode: range:50-100 weight:C speed:slow maxMode:instant
Traceback (most recent call last):
  File "wensn.py", line 88, in <module>
    setMode(dev)
  File "wensn.py", line 58, in setMode
    dev.ctrl_transfer(0xC0, 3, wvalue, 0, 200)
  File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out

Turns out that I had the wrong model for this to work.

jcallaghan commented 4 years ago

Forking the project and adding MQTT

Ensure you have the paho MQTT library available pip3 install paho-mqtt.

Useful link

jcallaghan commented 4 years ago

Shared video on Twitter.

image

jcallaghan commented 4 years ago

Home Assistant integration and panel cards

image