BME680 + Sonoff Basic + Tasmota = air quality sensor

Hello

I discovered an easy way to get the data of an BME680 air quality sensor to the openHAB system. The nice thing about this sensor is that it has a gas sensor which can give you an indication how good the air quality is. The higher the resistance of the sensor, the better the quality.

Here I want to share the solution how it can be done:

Prerequisites:

  • Sonoff Basic flashed with tasmota(sensors). I testet R1 and R2. R1 might be the better choice because the sensor went offline after some time when I tried it with R2.
  • BME680 Sensor
  • minimal soldering skills
  • running MQTT broker
  • OpenHAB MQTT binding and JSONPATH transformation

Prepare your Sonoff Basic
#1 flash the device with tasmota-sensors Firmware
You can use the tasmota webinstaller.
#2 connect your BME680 with the Sonoff Basic device
See here: BME680 wiring


Configure your Sonoff Device
#1 module parameters

When everything is working, it should look like this.
grafik

#2 mqtt settings (you have to costomize the host and userdata to your needs)

OpenHAB configuration
#1 create MQTT Thing

Bridge mqtt:broker:mosquitto "Mosquitto" [ host="localhost", port=1883, secure=false, username="youruser", password="yourpassword" ]
    // Sonoffs
    mqtt:topic:tasmota_5545AD_Test "Sonoff Basic" (mqtt:broker:mosquitto) {
    Channels:
        Type switch : power     "Power"                [ stateTopic="stat/tasmota_5545AD/POWER", commandTopic="cmnd/tasmota_5545AD/POWER" ]
        Type number : rssi      "WiFi Signal Strength" [ stateTopic="tele/tasmota_5545AD/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type number : temperature "Temperature"        [ stateTopic="tele/tasmota_5545AD/SENSOR", transformationPattern="JSONPATH:$.BME680.Temperature"]
        Type number : humidity    "Humidity"           [ stateTopic="tele/tasmota_5545AD/SENSOR", transformationPattern="JSONPATH:$.BME680.Humidity"]
        Type number : pressure    "Pressure"           [ stateTopic="tele/tasmota_5545AD/SENSOR", transformationPattern="JSONPATH:$.BME680.Pressure"]
        Type number : gas         "Gas"                [ stateTopic="tele/tasmota_5545AD/SENSOR", transformationPattern="JSONPATH:$.BME680.Gas"]
    }

#2 create items

Group                        gSonoff_Sensor                "Sonoff"                                                   ["Sensor"]

Switch                       GF_Sonoff_Sensor_Power          "Power"                              (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:power"}
Number:ElectricResistance    GF_Sonoff_Sensor_RSSI           "WiFi Signal Strength [%d %%]"       (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:rssi"}
Number:Temperature           GF_Sonoff_Sensor_Temperature    "Temperature [%.1f]"                 (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:temperature"}
Number:Dimensionless         GF_Sonoff_Sensor_Humidity       "Luftfeuchte [%.1f %]"               (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:humidity"}
Number:Pressure              GF_Sonoff_Sensor_Pressure       "Luftdruck [%d hPa]"                 (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:pressure"}
Number                       GF_Sonoff_Sensor_Gas            "Gas [%.1f]"                         (gSonoff_Sensor)                  {channel="mqtt:topic:tasmota_5545AD_Test:gas"}

#3 widget template:

widget code

uid: bme680
tags:

  • community
  • bme680
    props:
    parameters:
    • description: The name of the sensor
      label: Title
      name: title
      required: false
      type: TEXT
    • context: item
      description: The Sonoff equipment group (prefix of the point item names)
      label: Item
      name: gitem
      required: false
      type: TEXT
      parameterGroups: []
      timestamp: Sep 18, 2022, 12:41:22 PM
      component: f7-card
      config: {}
      slots:
      default:
    • component: f7-block
      config:
      style:
      align-items: start
      border-radius: var(–f7-card-expandable-border-radius)
      box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
      background-color: ‘= (Number.parseFloat(items[props.gitem + “_Gas”].state) < 100) ? “rgba(139,0,0,0.5)”:(Number.parseFloat(items[props.gitem + “_Gas”].state) < 150) ? “rgba(255,69,0,0.5)”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 200) ? “rgba(255,165,0,0.5)”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 250) ? “rgba(238,238,0,0.5)”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 350) ? “rgba(173,255,0,0.5)”: “rgba(0,255,0,0.5)”’
      display: flex
      flex-direction: column
      min-height: 150px
      slots:
      default:
      - component: Label
      config:
      style:
      color: black
      font-weight: bold
      margin: 5px
      text-shadow: 0px 0px 3px white
      text-transform: uppercase
      text: =props.title
      - component: oh-link
      config:
      action: analyzer
      actionAnalyzerItems: =[props.gitem + ‘_Gas’]
      color: black
      iconF7: chart_bar_circle
      iconSize: 24
      style:
      font-size: 24px
      text-shadow: 0px 0px 3px white
      text: ‘= (Number.parseFloat(items[props.gitem + “_Gas”].state) < 100) ? “very bad”:(Number.parseFloat(items[props.gitem + “_Gas”].state) < 150) ? “bad”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 200) ? “ok”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 250) ? “good”: (Number.parseFloat(items[props.gitem + “_Gas”].state) < 350) ? “very good”: “excellent”’
      - component: oh-link
      config:
      action: analyzer
      actionAnalyzerItems: =[props.gitem + ‘_Temperature’]
      color: black
      iconF7: thermometer
      style:
      text-shadow: 0px 0px 3px white
      text: =items[props.gitem + ‘_Temperature’].state
      - component: oh-link
      config:
      action: analyzer
      actionAnalyzerItems: =[props.gitem + ‘_Humidity’]
      color: black
      iconF7: drop
      style:
      margin-left: 2px
      text-shadow: 0px 0px 3px white
      text: =items[props.gitem + ‘_Humidity’].state
      - component: oh-link
      config:
      action: analyzer
      actionAnalyzerItems: =[props.gitem + ‘_Pressure’]
      color: black
      iconF7: speedometer
      style:
      margin-left: 2px
      text-shadow: 0px 0px 3px white
      text: =items[props.gitem + ‘_Pressure’].state

grafik

Thanks to the open source community :clap: :grinning: Feedback welcome.
BR

2 Likes

Ahhh yes yes. But you should instead take a look at the espurna firmware. Trust me on this one :wink: flash it and take a look, get back to us afterwards:)
The espurna firmware uses the oficial Bosch software blob with better control of the internal sensor devices and better data output.

Edit:
Here - ESPurna ESP8266 Automation Firmware Gets Support for BME680 Sensor's Precise Indoor Air Quality Measurements - CNX Software

Edit 2: with the Bosch software you don’t even need that logic for the air quality! It’s sent from the sensor itself :wink:

This is interesting. I will give this definitvely a try!

1 Like