Author Topic: mcThings Battery Monitor via MQTT  (Read 525 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
mcThings Battery Monitor via MQTT
« on: November 01, 2016, 05:03:16 pm »
This sounds like a simple project, but has some interesting features. Took me about 1 hour to hook up, and another hour hacking code (and another hour to download to the module - kidding! not really).

Background:

I have a Z-Wave multi-sensor (Aeon labs MS6) used to control a light in a stairwell using the motion detection feature. Originally this was battery powered, but the batteries only last a month or two (not the years they are supposed to). As the sensor is hard to get to, I converted the sensor to Mains Power (the sensors can run off 5V DC) to avoid the battery changing issue.

However, there is no power conveniently by the light, other than the (switched) power going to the bulb itself (it's actually an LED bulb, but that doesn't matter). As a solution, I wired a small 5V supply into the bulb socket (a 2A USB charger), then connected this to an adafruit PowerBoost 1000c. This takes 5V in, and charges a LiPo battery. When power is lost (the light switches off), the LiPo supply's power to the 5V out, ensuring uninterrupted 5V power out for the motion sensor.

See here https://learn.adafruit.com/adafruit-powerboost-1000c-load-share-usb-charge-boost/overview

This works well, as long as the light is on long enough for the LiPo to charge more than the sensor draws over time.

I found that after a week or two, the LiPo would become discharged (I'm using a 4,400 mAh LiPo). Turning the light on for a few hours would recharge it, but this was a nuisance. I tried an automated solution using best guesses as to charge/discharge rates, sensing when the light was on etc, but this doesn't work well. I needed real time monitoring of the LiPo battery state, in a small footprint, that doesn't draw too much power (ie discharge the LiPo even faster), and can report periodically, without wires.

Solution:
mcThings 110 module. This can monitor the battery voltage, read the status of the "Low Battery" pin, measure the temperature of the LiPo, and report every 30 seconds via MQTT over Low Power radio. Impact on battery life should be minimal.

Challenges:

The nominal LiPo voltage is 3.7V, but this can go as high as 4.2V when charging. This is higher than the 3.6V maximum for an mcThings module. The "LBO" pin (low battery) is normally connected to the battery (via an LED), and is pulled low when the battery voltage drops below the preset limit (3.2V), so this is also above the 3.6V limit.

The solution was to wire a small diode (500mA rectifier diode) in line with the power input, and a reverse bias (blocking) diode from the module to the LBO pin on the PowerBoost 1000c.

With the modules green LED on (to provide a small continuous load), the in line diode drops the LiPo voltage to 3.6V when charging, so just within our limit.

The module is wired PowerBoost 1000c VBAT via a diode to module pin 12, GND to pin 4 and LBO via reverse bias diode to module pin 8

The module is then cable tied to the LiPo battery (so that the temperature sensor reads close to the temperature of the battery), and everything is hidden in the ceiling (see the pictures - I didn't take any of the wiring - but if I take it down, I'll try to add some).

The code is on my github, under "projects" "BatteryMonitor" here: https://github.com/NickWaterton/mcScript/tree/master/projects/BatteryMonitor

The MQTT library code contains a lot of "stuff" to ensure the module keeps publishing, and also puts the data in the module beacons (which you can decode using beacon_decode.py from my site), so that you get data even if the module stops publishing.

The "diode to drop the voltage" is a bit of a hack, and if I'm not happy with it, I may replace it with a small voltage regulator, but then I'd have to put in a voltage divider to another pin to monitor the battery voltage, so more work, and this seems to work fine for what it is.

The MQTT data gets fed to my Openhab set up (which is what I use for most things) , with some rules to turn on the light when the battery gets low, and some monitoring to make sure we are receiving data, and the temperature is within range etc.

I may update this when I have more data, as this just went in, and may need some fine tuning  ;D.

OK, modified the code slightly, and added some pictures as I had to take the module out of the ceiling to update it.
« Last Edit: November 05, 2016, 09:16:19 am by Nick_W »

Share on Facebook Share on Twitter

Like Like x 1 View List

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: mcThings Battery Monitor via MQTT
« Reply #1 on: November 02, 2016, 12:43:10 pm »
Awesome Nick! Great job and a cool way to use the modules!
We are looking forward to your next project!

Keep up the good work my friend!
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: mcThings Battery Monitor via MQTT
« Reply #2 on: November 04, 2016, 02:58:42 pm »
Pics of wiring
« Last Edit: November 04, 2016, 03:01:14 pm by Nick_W »