Outdoor Lux Sensor

@groston and @terryhonn Here is how I created my outside light sensor:

Hook-up the BH1750 to your ESP as follows:

Load up this config to your ESP:

esphome:
  name: lux-sensor
  platform: ESP32
  board: mhetesp32minikit

wifi:
  ssid: 'WAPLO'  # CHANGE THIS SECTION TO SUIT YOUR NETWORK
  password: !secret wifi_pwd
  manual_ip:
    static_ip: 10.1.1.76
    gateway: 10.1.1.1
    subnet: 255.255.255.0

api:
  # password: !secret api_password ## No longer recommended if using encryption. ##
  encryption:
    key: !secret api_encryption_key

logger:

ota:
  password: !secret esp_pwd

binary_sensor:
  - platform: status
    name: "Lux Sensor Status"

i2c:
  sda: 21
  scl: 22
  scan: False

sensor:
  - platform: wifi_signal
    name: "Outside Light Level WiFi Signal"
    id: os_ll
    update_interval: 15s
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 15
          send_first_at: 1

  - platform: bh1750
    name: "Outside Light Level"
    address: 0x23
    update_interval: 1s
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
          send_first_at: 1
      - or:
          - throttle: 60s
          - delta: 5

switch:
  - platform: restart
    name: "Lux Sensor Restart"

Install it somewhere facing north if you are in the southern hemisphere, or facing south if in the northern hemisphere. Tilted at 90° minus your latitude is optimal but not essential.

IMG_5780

Add the integration in Home Assistant:

Notes:

You should keep the I2C connections (SDA and SCL) shorter than 30cm. However if you need to extend the length you can get up to 2m if you use twisted pair cat5 cable like this:

I2C cabling

I have my ESP a meter away in the roof where I have wifi:

IMG_5781

Initially I used outdoor two pair telephone cable to connect between the ESP and BH1750. As I had power on one pair and SDA and SCL on the other pair I ended up with the connection shown as “BAD” in the above image. This caused loads of crosstalk between SDA and SCL which caused the connection to fail. Even lowering the I2C speed to 10kHz I could only get 30cm and there were still many errors. After changing to some Cat6 cable, with more pairs, connected as shown in the “GOOD” diagram I got 1.5m easy. No errors.

Ideally you would use Cat5/6 cable like this:

  • Orange: 3.3V
  • Orange-white: GND
  • Brown: GND SDA
  • Brown-white: GND
  • Blue: SCL
  • Blue-white: GND
  • Green: SDA GND
  • Green-white: GND

This should minimise the crosstalk between SDA and SCL as the green and blue pairs have the biggest twist ratio difference.

EDIT: actually it is blue and brown pairs that have the biggest twist ratio difference.

24 Likes

Thanks for pointing me to you post. I had figured out the ‘difficult’ hardware stuff, but the part where I am a confused is your line ‘Load up this config to your ESP’. The posted code looks like a .yaml file, but I was planning to have the BH1750/ESP simply be a sensor that communicates with my HA system. Are you suggesting that the ESP becomes a HA system and that it communicates with the other?

No. I am suggesting you use ESPHome.

The yaml file is complied by esphome and uploaded to the ESP board. This then communicates with Home Assistant via the ESPHome API. It supports discovery so it is very easy to get going.

Thanks – I had confused ESPHome and HA.

Anyway, I edited your yaml file a tad, had ESPHome create the .bin file, plugged the NodeMCU into my computer, but then ran into a problem. I launched Chromium, went to Web - ESPHome, and my computer it readily connected with the NodeMCU (pop-up window showed ‘CP2102 USB to UART Bridge Controller (COM23) – paired’). I then clicked Install, selected the .bin file, clicked Install, saw the blue LED on the NodeMCU flash several times, but was then shown a window with ‘Failed to initialize’. Same thing happened when I clicked ‘Prepare for adoption’. I tried holding down the flash button as the device was plugged into the USB, holding down the flash button until I saw the error message, and tried two USB cables. Now what???

I’ve personally never used (or even heard of) ESPHome Web.

I use either NodeMCU-PyFlasher or ESPHome-Flasher.

Both are standalone programs you download to your PC and use like any other app.

ESPHome-Flasher seems to work a bit better because it will bring up the logs in the app window after the .bin file is uploaded and the ESP board reboots.

Sorry - should have posted this a few days ago: When I looked at the ESPHome UI carefully, I saw, under Install, the option ‘Plug into the computer running ESPHome Dashboard’ - I used this (first time) and everything did as expected.

Hi @tom_l ,

thank you very much for your detailed guide. Would you mind sharing you STL 3D-model file for the housing, too?

Thanks in advance!

Kay

Not sure where you got the idea that I printed anything. I did not.

It’s just an off the shelf IP68 box.

Ok, thX!

(Was pretty far away on your roof pic and looked to me like you printed it yourself :wink: )

Random Question - does it need the dome?
Or would something like this be okay?
HALJIA 3PCS GY-302 BH1750 Digital Light Intensity Sensor Illumination Detector Module 3V-5V Compatible with Arduino GY302 BH1750FVI : Amazon.co.uk: Business, Industry & Science

It will work with any BH1750 board.

That’s a clean install. How are you powering your esp? Looks like cat5 going into the enclosure but I assume that’s just carrying 5v from somewhere?

I assume that the cable carries 12-24V power, and in the black box there is a development board and a DC-DC converter, this would be correct to avoid voltage losses

You know what they say about assumptions :wink:

I have 12V and 5V DC power supplies in my 19" rack that I distribute to devices around the house on cat6 and alarm cabling. In this case the current draw is low enough to power the ESP with 5V without any detrimental voltage drop.

And down the rabbit hole we go…

Love the idea of a central distributed PSU - are you using colour coded Cat6 so you don’t let the smoke out of stuff that doesn’t expect 12v on its Ethernet port?

Is that a home-built PSU?

What are the ‘ickle buttons for? (Love the power switches!) short circuit reset?

How are you terminating fiddle cat6 at the back of a rack for the power? A bus of some sort? RJ45 patch and a bus?

None of the DC cabling terminates at network ports. It’s all hard wired to the devices in the floor or roof space.

“Home assembled”. Off-the-shelf PSUs, displays and an ESP32 for current and voltage monitoring bunged in a 19" rack case.

Yes, main circuit breakers for each supply. The rocket launch power switches are assembled upside down so you have to flip the cover to turn them off.

Panel mount terminal blocks on the back of the rack case go to a custom i/o distribution PCBs. ESP32 Ethernet with SPI I/O expanders and terminal blocks for i/o and jumperable 5 or 12V DC for each set of I/O. The whole thing has gone through a few iterations. I used to use Rasberry Pis for the i/o. I removed them andbuilt daughter boards for the ESP32 and i/o expanders that fit in the 40 pin sockets.

Old:

New:

6 Likes

This is very cool inspiration - thanks for taking the time to share the photos and the details. Gives me some great ideas of how to achieve some similar goals for distributed LV power.

1 Like

This might be a naive question, but can this be done with an ESP-8266

Sure can.

1 Like

Thanks - same method / pins? Or does the code need changing?

  platform: ESP32
  board: mhetesp32minikit

Presumably these two lines need to represent the 8266 instead, but otherwise looks sound?