Sign inSign up

hvalev/bh1750mqtt-homeassistant

By hvalev

Updated almost 5 years ago

Image
0

3.4K

hvalev/bh1750mqtt-homeassistant repository overview

bh1750 illuminance sensor in a docker container

build Docker Pulls Docker Image Size (latest by date)

This docker container enables you to use the BH1750 illuminance sensor on a GPIO enabled device such as raspberry pi. This container can communicate with an MQTT broker and relay the sensors' values in addition to integrating with home assistants' discovery protocol. Discovery will automatically detect the sensor and make it available for visualizations, automations, etc within your home assistant instance.

How to run it

The following docker run command or docker-compose service will get you up and running with the minimal configuration. docker run --device=/dev/i2c-1:/dev/i2c-1 -e topic=zigbee2mqtt -e device_id=bh1750 -e broker=192.168.X.X hvalev/bh1750mqtt-homeassistant

version: "3.8"
services:
  bh1750mqtt:
    image: hvalev/bh1750mqtt-homeassistant
    container_name: bh1750mqtt
    devices:
      - /dev/i2c-1:/dev/i2c-1
    environment:
      - topic=zigbee2mqtt
      - device_id=bh1750
      - broker=192.168.X.X

/dev/i2c-1:/dev/i2c-1 is required to access the Inter-Integrated Circuit bus and communicate with your BH1750 sensor. If it doesn't work, you can try to run the container in privileged mode privileged:true.

Parameters

The container offers the following configurable environment variables:

ParameterPossible valuesDescriptionDefault
topicMQTT topic to submit to.zigbee2mqtt
device_idUnique identifier for the device. If you have multiple, you could use something like bedroom_bh1750.bh1750
brokerMQTT broker ip address.192.168.1.10
usernameMQTT username.None
passwordMQTT password.None
busVariable passed to the i2c bus. Rev 1 Pi uses 0, Rev 2 Pi uses 1.1
addrPin address.0x23
sensSensor sensitivity. Possible values are 31-254.254
unitMeasurement unit.lx
modeMeasurement mode. Supported methods are measure_low_res, measure_high_res and measure_high_res2 coded as 0, 1 and 2. Recommended is to set at 1.1
pollSampling rate in seconds. Depending on the measurement mode (see mode variable) different sampling rates are possible (Specs Datasheet). Recommended value is at least 2 seconds.2
mqtt_chatteressential|ha|fullControls how much information is relayed over to the MQTT broker. Possible non-mutually exclusive values are: essential - enables basic MQTT communications required to connect and transmit data to the zigbee broker; ha enables home assistant discovery protocol; full enables sending information about container internals over to the MQTT broker.essential|ha
logginglog2stdout|log2fileLogging strategy. Possible non-mutually exclusive values are: log2stdout - forwards logs to stdout, inspectable through docker logs dht22mqtt and log2file which logs temperature and humidity readings to files timestamped at containers' start.none

If you end up using log2file, make sure to add this volume in your docker run or docker-compose commands - ~/yourfolderpath:/log to be able to access the logs from your host os.

If you want to run this container to simply record values to files with no MQTT integration, you need to explicitly set mqtt_chatter to a blank string. In that case, you can also omit all MQTT related parameters from your docker run or compose configurations.

If you're using this container for multiple sensors on the same or different devices which, however, connect to the same mqtt network, you need to explicitly pick a unique device_id for each. Otherwise, identically named devices will boot each other off the network each time they transmit a reading.

I have noticed that using measure_high_res2 for sensor measurement mode sometimes produces 0 lux measurements. Some sort of filtering may be required if you opt for it.

Connecting your sensor

There are multiple online resources on how to hook up your sensor. Be mindful that the pins your sensor is connected to influences the addr pin parameter above.

Acknowledgements

The bh1750.py class has been shamelessly copied from the following gist.

Tag summary

Content type

Image

Digest

Size

19.4 MB

Last updated

almost 5 years ago

docker pull hvalev/bh1750mqtt-homeassistant