Getting data from emoncms into OpenHab2


(Clive Just) #1

I am new to Openhab2 and my first task it to collate the data from a number of emonpis each capturing 3 phase electricity consumption into a central Openhab2 system running under Windows/Linux

Not sure if I need to do this - I have enabled both OpenEnergyMonitor Binding and MQTT Binding in Add-on but don’t know what the next steps are so any advice would be most welcome.

I have hunted around but can’t find anything that seems relevant!

Thanks


(Rich Koshak) #2

I recommend reviewing the Beginner’s Tutorial which will introduce you to the major concepts of how OH works and give you a guide for how to proceed.

Then install and review the Demo to see a working configuration.

Then review the readmes for the bindings that talk to your specific devices which will give you the specifics for how to discover and/or configure your Things and Items.


(Clive Just) #3

Thanks Rich

Are you just suggesting that, as indeed it is a good thing to do, or do you know the answer to my question and are sure it is answered in the documentation?

Actually I have done that and once setup a working OpenHAB and connected devices pulling in data via SSH from my own remote devices - so I claim no expertise at all but neither have I just installed it and then said HELP!

Yes I do have the technical ability to wade through and work it out for myself but time is short and any advice directing me to the answers would be most welcome.

Cheers


(Rich Koshak) #4

I direct you to the beginner’s guide and other docs because your question lacks the specificity to answer and the nature of the question implies you do not have the basic knowledge of how OH works. All in all this question comes across as a “do it for me” type posting. I’m sure that wasn’t your intent.

We can’t possibly have the answer without specifics.

What are your Things and Items?
What are your Rules?
Have you read and tried to follow the binding’s readmes and do you have specific questions about something unclear in the docs?

Your question implies you don’t know what Things and Items and Rules are and that you have not found anything specifically unclear in the docs.

OH is a large and complex platform and if you do not have a basic grasp of how the various parts and concepts of them work together it is exceptionally difficult to provide any answer beyond “read the docs.” If you go through the Beginner’s Tutorial you will be provided this basic information and the next steps should become evident. If not come back with specific questions and we will try to answer them.


(Jimbob) #5

Hi,
Not at home right now, so can’t respond in full or look at my code…

I’ve got EmonHub running on the same RPi as Openhab, along with Mosquitto for MQTT - I’ve then setup the relevant items in openhab to capture the readings.

I did mean that I would have needed to do calculations to get daily usage etc, but I’m only interested in the instaneous values…

Cheers
James


(Clive Just) #6

Thanks James

My original post was exceedingly badly worded - too late at night when I posted it - and Rich was quite gentle on me really!

Despite that I do understand some of the basics of OpenHAB2 but was just a bit unclear how much I can depend on OpenHAB1 stuff still being relevant when I read posts etc. and a bit frustrated as the stuff I found never quite answered my questions.

We have at least three RPis running emoncms and want to collate data on one OpenHAB2 server

Anyway the question really is it seems there are several bindings I could use to get data from emoncms to OH2 - eg MQTT, OpenEnergyMonitor, EXEC and probably HTTP - but what is the best (easiest but reliable) or otherwise what are the pros/cons of each.

I suspect MQTT may be the “right” way to go but I really want to keep it as simple as possible, I dont want to code anything complex - though happy to script - and certainly want to avoid getting into things like Eclipse

I am currently using EXEC and CURL to get the JSON data - probably viewed as a quick and dirty solution!

Apart from that there are two other things I am investigating:

whether I can get Volts Amps and Watts in one call and store as one “record” in OpenHAB.
I want to add Persistence using MySQL - I did try this on an earlier installation of OH2 and found I could record everything with the same frequency but failed to record Mains every 5 seconds and Temperatures every 5 minutes.

Any suggestions most welcome. Cheers


(Rich Koshak) #7

When I’m in doubt I usually look at the OH 2 docs to see if there are any differences. If not I try it out and see how it goes. While there are some new concepts introduced in OH 2, the vast majority of OH 1 stuff works just fine unchanged in OH 2.

Now THAT is a question I can answer. :slight_smile:

OK, I’ve no experience with OpenEnergyMonitor so cannot address that. As a general rule though a more specific binding will be easier and more feature complete than a more generic binding. So I would look at OpenEnergyMonitor first.

MQTT would be a really good second choice. It provides a bit more flexibility and control over things but it does require running a separate broker which you may not want to do in this deployment. I personally really like MQTT and found that once I had it set up I find more and more things to do with it.

I would probably put either the HTTP binding or the HTTP actions at about the same level as MQTT. The reason I would put this after MQTT is that by its very nature it becomes a polling/pull of the data rather than a subscribe/push.

Exec would be my last choice but mainly because a lot of people have a hard time getting it to work. You already have it working so you can either follow the old adage “If it ain’t broke, don’t fix it” rather than Red Green’s (an old Canadian tv show) motto of “if it ain’t broke, you aren’t trying hard enough.”

So persistence is strictly Item based. If you want to store three values separately you must use three Items which will result in three entries into whatever database you use for persistence (I like InfluxDB). You can correlate them by time as each entry is a tuple (state and datetime). You cannot define your own table space in MySQL and expect OH to populate it.

Also, each Item will be saved to the database as a separate transaction (assuming the underlying database supports transactions). So there is no way to force all the values to be saved in a single transaction.

The only thing I can think of would be to merge the three values into a String Item and persist that, but then you lose the numerical aspects of the measurements and will need to pull them out and parse them back into numbers in order to chart, calculate, or otherwise process them individually.

Presumably, you want to analyze and display this data in charts so I will recommend the InfluxDB+Grafana to get much more flexible graphing possibilities. I do believe that Grafana recently added support for MySQL so if you want to use that it might work.


(Jimbob) #8

Hi there,

Sorry it’s taken me a while to get back on this thread…

I’ve got an RFM12b on the same RPi 3 that also runs openHAB, I’m running Mosquito for MQTT, and run emonhub exporting data to the emoncms.org instance - I don’t run a local copy of emoncms.

emonhub.conf (relevent bits):

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        mqtt_host = 127.0.0.1
        mqtt_port = 1883
        mqtt_user = ''
        mqtt_passwd = ''

    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,

        # emonhub/rx/10/values format
        # Use with emoncms Nodes module
        node_format_enable = 1
        node_format_basetopic = emonhub/

        # emon/emontx/power1 format - use with Emoncms MQTT input
        # http://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/MQTT.md
        nodevar_format_enable = 1
        nodevar_format_basetopic = emon/

Openhab.cfg:

################################# MQTT Transport ######################################
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with a id you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:mosquitto.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqtt:mosquitto.clientId=OpenHab

mqtt.items:

Number PowerImport "Import [%d W]" (gMqtt,gPower) {mqtt="<[mosquitto:emon/emontx1/power1:state:default]"}
Number PowerSolar "Solar [%d W]" (gMqtt,gPower) {mqtt="<[mosquitto:emon/emontx1/power2:state:default]"}
Number PowerMains "Mains [%.1f V]" (gMqtt,gPower) {mqtt="<[mosquitto:emon/emontx1/power4:state:JS(divide.js)]"}

As @rlkoshak suggests, I used influxdb+grafana to store/graph the data, with the following persistence strategy:

gMqtt*		:	strategy = everyChange, restoreOnStartup

Hope that helps
James