Community
OpenEnergyMonitor

Community

Alternative means of measuring room temperature Part 2

Continuing the discussion from Alternative means of measuring room temperature:

So the TL;DR is to use Xiaomi Mijia sensors, Home Assistant (HA) and ESPHome on a Wemos D32 to cheaply and simply get Temperature & Humidity into EmonCMS (and HA).

The long version;

As I said in part one, as much as I like the EmonTH, for me, they are simply too expensive for general deployment around the house, so I have been after a cheaper alternative for a while.

I found a solution, but now I have improved on that massively.

Firstly it still consists of these Xiaomi Mijia Bluetooth Hygrothermograph devices (available for around the £10 mark). I have now had these a year and the AAA battery in each has about 20% left - pretty good!

What I have just done though is massively simplified setting up the reading of the data.

Firstly I bought a Wemos D32 from AliExpress for around £7 from the official store - arrived in 10 days.

I’m quite a fan of HomeAssistant especially the Hass.io variety mainly because of the various add-ons that are available. I have also been a fan of Tasmota, but recently I have moved to ESPHome. The key reason for this change is that I have found it far simpler to set up and it has some built-in components I want, one of which is a component for these temperature sensors. I also have some CO2 sensors in the post that I hope will integrate just as easily onto some Wemos D1 Minis I bought at the same time.

The Hass.io add-on means you can write the config file there, click to build the code, If the D32 is connected to the same computer, you can upload directly or (like me as HA is on a VM), download the binary and flash the D32.

Once done, any configuration update is edited in the HA add-on, complied and flashed from there - just so easy!

The biggest hurdle is overcoming the rather cryptic documentation and getting the config right. I’m still working on that but I’ll post it once done.
.
Of course, I then publish the data through MQTT and pull it into EmonCMS.

As promised the config:

esphome:
  name: esp32_ble
  platform: ESP32
  board: lolin_d32

wifi:
  ssid: "xxxx"
  password: "xxx"

mqtt:
  broker: x.x.x.x
  username: xxxx
  password: xxxxx
  discovery: false
  log_topic: 'esp32_ble/debug'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

esp32_ble_tracker:
  scan_interval: 300s

sensor:
  - platform: xiaomi_mijia
    mac_address: AA:AA:AA:AA:AA:AA
    temperature:
      name: "Xiaomi MiJia Temperature"
      # Adding a 'state_topic` is all that is needed to get it to publish by MQTT
      state_topic: emon/ble/temp
      # Add a filter as these sensors have quite a jitter
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 2
    humidity:
      name: "Xiaomi MiJia Humidity"
    battery_level:
      name: "Xiaomi MiJia Battery Level"
1 Like

I’ve dabbled with these Xaomi temp sensors along with the Xaomi hub connected up to Hassio.

I’ve not yet attached them to anything emonCMS… but just for a cheap way of monitoring separate room temps they work fine. I couldn’t find a cheaper way to get small sensors around the house and get them recording to a central source like a Raspberry Pi (running hassio).

You need the gateway

Or alternativley any decent zigbee stick (although i’ve not gone down this route yet)

Good article here for those fancying a dabble.

Hope this helps.

1 Like

I really wanted a sensor with a display and wanted to avoid, at all costs, getting sucked into a hub that the manufacturers can change the firmware on whenever they feel like it (so destroying your integrations with HA) and also did not want it by default connected to the internet in a way I cannot control.

I’ve have also got a zigbee stick setup with Zigbee2MQTT on a PiZero that works well for an Ikea light I have.

Yeah, I should probably go down the zigbee stick route. But I currently don’t have any other controllable devices and I just wanted to get the temp monitoring sorted.

1 Like

@borpin thanks for the post. Could you clarify the use of the Wemos and it’s configuration? I assume it’s the interface between HASSIO <“wi-fi”> Wemos <“Bluetooth”> Xiamomi ?

Thanks
Trevor

The ESPHome on the D32 (as it has built-in bluetooth) communicates with the Xiamomi sensors by Bluetooth and passes the data on to HA (via WiFi) with no further configuration.

What are you using for the MQTT broker? Mosquitto?

Yes. I have it installed on a separate DietPi VM (Virtual Machine) instance. It serves all my internal systems.

Hi Brian,

What is the display on your system? I couldn’t see a display in the hardware you described.

I’m looking to replace a cheap inside/outside thermometer with something that:

  • is mains-powered
  • can log its data to emoncms
  • doesn’t depend on ‘cloud’ access or services :slight_smile:
  • does include an indoor display
  • is expandable to include more sensors

Your system looks close but is battery-powered and I don’t see a display? I’m also more comfortable with processors running linux and attached sensors than flashing and understanding other hardware.

I’m looking at a system with a couple of Pi zero W processors and Si7021 sensors and a small display but would welcome any thoughts anybody has.

And yes, it would be ideal if the OEM shop could offer something at a lower price. The emonTH looks quite old-fashioned now.

This link but is definitely for indoors.

Have you thought about a Weather Station? I’ve got a WH1080 that Maplin used to sell for about £80 that I link to EmonCMS via PYWWS (posts MQTT message).

Looks like they are now difficult to come by but I’m sure other Weather Stations would work.

I posted the initial post a year ago and the batteries still have at least 20% remaining.

I know where you are coming from there BUT I’ve just started playing with this combo (WEMOS, ESPHome, HomeAssistant) and it is so, so simple. Kids play.

I’ve just setup a new BME680 that came in the post less than an hour ago.

This is the code I needed (I have set up some templates that the substitutions pass settings to);

substitutions:
  device_name: bme680_1
  display_name: "BME680 1"
  name: bme680_1
  platform: ESP8266
  board: d1_mini
  cc_devicename: "BME680_1"
  static_ip: 192.168.7.82
  log_level: DEBUG

<<: !include common/esphome.yaml
<<: !include common/wifi.yaml

i2c:
  sda: D2
  scl: D1
  scan: True
  id: bus_a
  
sensor:
  - platform: bme680
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    address: 0x76
    update_interval: 60s
    

And that is it. Now talking to HomeAssistant via the native API. Need to set up the MQTT to EmonCMS as well but I will template that so it Just gets included every time I create a new sensor.

The only tricky bit used to be the first flash (every one after that is done OTA), but this little gem (esphome-flasher) solves that.

It really is worth the plunge.

I hadn’t but thanks for the idea. £80 is more than my proposed configuration though and I don’t see many that have a computer interface. Have you any suggestions?

I know batteries can have quite a long life -my fire alarms have ten year batteries (since they’re required to have batteries as well as mains), as does my watch - but having gaps every year or so is an annoyance.

Well right, but you’ve cables and a breadboard there I don’t have, and you’ve previously said you struggled with poor documentation. I’d rather have something that I understand if I can’t have something that’s plug-and-play.

Hum, I feel like this could be accomplished without a middle man. It would probably just need an ESPHome component that posts to the EmonCMS API.

Or the EmonCMS system accessing the ESPHome API directly.

The MiM is just the same as an EmonPi does itself in a standard configuration - Emonhub posts to MQTT rather than directly via the API interfacer it is just the MQTT broker in this case in on the same machine.

I use MQTT for lots of other things and often data goes into the broker from a system, gets processed (usually to export a single figure) then passed back to the broker on a different topic emoncms can then pick up.

'Fraid not, as I said mine was a Maplin WH1080 that has a USB port.

Yes I have gradually acquired bits - it is just what is needed to test it out. The bits are all now soldered together and returning data - just got to work out what it means :grinning:.

The reason for going down this road is that I have not found something that just works and does what I want.

Horses for courses, I suppose. I’ve just ordered the bits for my proposed solution, so I’ll see how reality matches up with my expectations. :grin:

Yes - YMMV always applies.

Yeah, EmonCMS pulling from the ESPHome api would probably be easier.

Look forward to seeing it :grin:. I would not know where to start.