btmon patch for MQTT Publication

Post any 3rd party software here.
guessed
Posts: 25
Joined: Thu Feb 10, 2011 1:17 pm
Location: California

btmon patch for MQTT Publication

Post by guessed » Wed Sep 16, 2015 1:06 am

Hi,
I have a patch that adds MQTT to the list of sinks that btmon.py can publish to. I've been running it for a few days now to publish my GEM & ECM-1240 data to openHAB.

I PM'd @mwall, as I wanted to have it vetted prior to publishing it out. Does anyone know a better way to get ahold of Matthew?

It looks like the Contact Information link on his page doesn't list him anymore.
ben
Site Admin
Posts: 4254
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon patch for MQTT Publication

Post by ben » Wed Sep 16, 2015 3:27 pm

That's pretty interesting, do you have any screenshots of what the integration looks like?
Ben
Brultech Research Inc.
E: ben(at)brultech.com
guessed
Posts: 25
Joined: Thu Feb 10, 2011 1:17 pm
Location: California

Re: btmon patch for MQTT Publication

Post by guessed » Thu Sep 17, 2015 12:43 am

No screenshots (yet) since I'm pushing the data to openHAB to allow for Home Automation events, more than display/graphs (although it can do both).

Arch wise it's just:

Code: Select all

GEM (RN-XV) ---> btmon.py (RPi B) --->  MQTT Broker/mosquitto (ODroid C1) <---> openHAB + HA Bindings (ODroid C1)
ECM-1240 (USB-Serial)---^                      ^                 ^             (Lights|TStats|Alarm|AV)
                                              /                   \
                                             v                      v
                                         OwnTracks                MQTTWarn
I pump all the same data that btmon emits (W, Wh, dWh, Temp, Pulse), and allow btmon to have optional aliases for each Channel into their counterpart MQTT Topic. btmon also publishes the data to SEG & PVOutput.
eg.

Code: Select all

[mqtt]
mqtt_out = true
mqtt_topic_base=/home/energy
mqtt_upload_period = 90
mqtt_host = odroid
mqtt_clientid = my_power
mqtt_user = bythepower
mqtt_passwd = ofgreyskull
mqtt_map = 010EIEI0_volts,volts,010EIEI0_ch1_w,bath_w,...010EIEI0_ch14_w,solar_w,010EIEI0_ch14_wh,
solar_wh,010EIEI0_ch14_dwh,solar_dwh,010EIEI0_ch,01000175_t1,garage_temperature,...
and you end up with a set of discrete MQTT topics like:

Code: Select all

/house/energy/volts
/house/energy/bath_w
/house/energy/solar_w
/house/energy/solar_wh
/house/energy/solar_dwh
/house/energy/garage_temperature
...
Then anything that can subscribe to the MQTT Broker will see the same data including: and they'll all be updated as bymon would normally do for any of it's sinks - all the subscribers get to see the same data publication events.

In openHAB you bind them to Items, and then write rules against them, put them into charts and/or simple displays. The raw Item update stream might look like:

Code: Select all

2015-09-16 16:56:12 - HouseVoltsAlt state updated to 127.2
2015-09-16 16:57:23 - HouseVolts state updated to 123.7
2015-09-16 16:57:23 - HousePowerGarage state updated to 41.297
2015-09-16 16:57:23 - HousePowerSolar state updated to 709.495
2015-09-16 16:57:23 - HousePowerGarageLights state updated to 20.967
2015-09-16 16:57:23 - HouseEnergyGarage state updated to 966622.902
2015-09-16 16:57:23 - HouseEnergySolar state updated to 6929898.28
2015-09-16 16:57:23 - HouseEnergyGarageLights state updated to 328703.711
2015-09-16 16:57:23 - HouseTemperatureGarage state updated to 75.0
2015-09-16 16:57:23 - HouseDEnergyGarage state updated to 1.044
2015-09-16 16:57:23 - HouseDEnergySolar state updated to 17.934
2015-09-16 16:57:23 - HouseDEnergyGarageLights state updated to 0.53
2015-09-16 16:57:43 - HouseVoltsAlt state updated to 125.8
2015-09-16 16:58:55 - HouseVolts state updated to 123.8
but the rule is just a script that looks at the Item values, sourced from the GEM-via-MQTT, and does stuff.

eg. shutdown stuff is today's Solar-gen is too low, or start Dish/Clothes washers if you have excess.
guessed
Posts: 25
Joined: Thu Feb 10, 2011 1:17 pm
Location: California

Re: btmon patch for MQTT Publication

Post by guessed » Thu Sep 17, 2015 12:53 am

This is the corresponding discussion thread on the openHAB forum: I was going to write a native openHAB binding, but the MQTT route seemed more flexible.

It'd be really interesting if the GEM's emitted MQTT as a native format. :P
guessed
Posts: 25
Joined: Thu Feb 10, 2011 1:17 pm
Location: California

Re: btmon patch for MQTT Publication

Post by guessed » Fri Sep 18, 2015 10:20 am

ben,
I've done a little reading and, from a pure-ui standpoint, I'd probably do something like this: and then substitute the openHAB Datasource components for bits working directly against my MQTT (having everyone then publish their bits to MQTT, since there's already a MQTT Gist to do that type of thing.

The Dashing library seems fairly flexible for a UI that needs both Display + Control components.

That said, I'd likely simplify the Energy data down to Solar (today, this month), Net Consumption (today, this month) and a label of which channel is currently consuming the most... I need room to fit a bunch of other controls on the page ;)
ben
Site Admin
Posts: 4254
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon patch for MQTT Publication

Post by ben » Mon Sep 21, 2015 10:19 am

guessed wrote:ben,
I've done a little reading and, from a pure-ui standpoint, I'd probably do something like this: and then substitute the openHAB Datasource components for bits working directly against my MQTT (having everyone then publish their bits to MQTT, since there's already a MQTT Gist to do that type of thing.

The Dashing library seems fairly flexible for a UI that needs both Display + Control components.

That said, I'd likely simplify the Energy data down to Solar (today, this month), Net Consumption (today, this month) and a label of which channel is currently consuming the most... I need room to fit a bunch of other controls on the page ;)
That's pretty neat, last time I played around with OpenHAB I was messing with GreenT.

I let Paul know about MQTT, not sure when he'll have time to look into it.
Ben
Brultech Research Inc.
E: ben(at)brultech.com
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

Re: btmon patch for MQTT Publication

Post by vespaman » Fri Feb 12, 2016 11:02 am

I'm heading into guessed's route now, so I just wanted you guys not to forget to the MQTT wish. It all would be much cleaner.
gosmond
Posts: 14
Joined: Thu Oct 27, 2016 9:00 pm

Re: btmon patch for MQTT Publication

Post by gosmond » Mon Dec 05, 2016 12:20 am

Another OpenHAB user here, adding +1 to request for native MQTT formatted data from the GEM.
Any status or ETA on this?
mwall
Posts: 140
Joined: Wed Dec 07, 2011 6:25 pm

Re: btmon patch for MQTT Publication

Post by mwall » Mon Dec 05, 2016 12:28 pm

gosmond wrote:Another OpenHAB user here, adding +1 to request for native MQTT formatted data from the GEM.
Any status or ETA on this?
btmon has had mqtt support for some time now.

ben and paul would have to say for certain, but mqtt in the gem firmware could be complicated. the protocols are easy, but there are many permutations, such as retain, last-will-and-testament, quality-of-service, not to mention the variety of possible data formats. it would be easy to upload a json-formatted packet with all of the data. but if your broker or downstream consumer cannot handle that, then you'll have to inject some processing along the way anyway.

try the btmon mqtt implementation. then give ben and paul some feedback about exactly *how* you want mqtt implemented.

m
ben
Site Admin
Posts: 4254
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon patch for MQTT Publication

Post by ben » Tue Dec 06, 2016 12:15 pm

We looked through MQTT but it unfortunately doesn't look like something the GEM can support by itself.

You're best off using a solution with btmon.py as mwall mentioned above. You should be able to run it on the same server running OpenHAB.
Ben
Brultech Research Inc.
E: ben(at)brultech.com
Post Reply