Fluks-o-Emoncms

Hi,

Recently i helped a friend route his beloved fluksometer to emoncms, at the end he was completely blown away with this great piece of software. Not only he has much better visualization tools, he gained a ticket to complete integration with everything.

I didn’t know flukso, i find the project very interesting it’s a router with OpenWRT with a arduino inside and a complete online and local visualization app. The great thing about this piece of hardware is its MQTT implementation that publishes huge amount of data. the measurements are reported at 1-second rate with lots of options, more than i could understand.

Here’s the implementation details:

Flukso comes with it’s own MQTT server, unauthenticated on port 1883 available at both wan or lan interfaces. The topics to subscribe are:

/sensor/+/counter/#
/sensor/+/gauge/#

The function:


////////////////////////////////////////////////////APR
// Slow down rate to every 10s
///////////////////////////////////////////////////////
var Value = msg.payload.split(",");
if(Value[0].substr(Value[0].length - 1) != '0' ) 
{
    return null; 
}
///////////////////////////////////////////////////////

/*
 *  The following structure defines reasonable names
 *  and type of measuring for each sensor ID
 *    - pplus, pminus, q1, q2, q3 and q4:
 *       same sensor ID @ counter & gauge MQTT topics
 *       
 *    - vrms, irms, pf, vthd and ithd:
 *       unique sensor ID @ gauge MQTT topic
 *
 * Find your own sensor id's and build the tables below
 * accordingly:
 *    - 1st argument: *node* at emoncms
 *    - 2nd argument: *key*  at emoncms 
 *
 */

var myGauge = {};
var Counter = {};

 // PORT1 (CT)
myGauge['00000000000000000000000000010001'] = 'port1,pplus';
Counter['00000000000000000000000000010001'] = 'port1,pplusWh';
myGauge['00000000000000000000000000010002'] = 'port1,pminus';
Counter['00000000000000000000000000010002'] = 'port1,pminusWh';
myGauge['00000000000000000000000000010003'] = 'port1,q1';
Counter['00000000000000000000000000010003'] = 'port1,q1VARh';
myGauge['00000000000000000000000000010004'] = 'port1,q2';
Counter['00000000000000000000000000010004'] = 'port1,q2VARh';
myGauge['00000000000000000000000000010005'] = 'port1,q3';
Counter['00000000000000000000000000010005'] = 'port1,q3VARh';
myGauge['00000000000000000000000000010006'] = 'port1,q4';
Counter['00000000000000000000000000010007'] = 'port1,q4VARh';
myGauge['00000000000000000000000000010008'] = 'port1,vrms';
myGauge['00000000000000000000000000010009'] = 'port1,irms';
myGauge['00000000000000000000000000010010'] = 'port1,pf';
myGauge['00000000000000000000000000010011'] = 'port1,vthd';
myGauge['00000000000000000000000000010012'] = 'port1,ithd';

// PORT4 (SO)
Counter['00000000000000000000000000040001'] = 'port4,pplus';

/*
 *    ** Main Program **
 *
 *    Value[0]    - timestamp with some leading garbage
 *    Value[1]    - actual measured value
 *    SensorID[2] - original Sensor ID
 *    SensorID[3] - gauge or counter mqtt topics
 *    Info[0]     - name of the sensor (port1,  port2,  ...)
 *    Info[1]     - type of measurement (pplus, pminus, ...)
 */

var SensorID = msg.topic.split("/");
var Info;

if(SensorID[3] == 'gauge' && myGauge[SensorID[2]] ) 
{
    Info = myGauge[SensorID[2]].split(",");
}
else if(SensorID[3] == 'counter' && Counter[SensorID[2]] ) 
{
    Info = Counter[SensorID[2]].split(",");
}
else 
{
    node.status({fill:"red",shape:"dot",text:"invalid"}); 
    return null; 
}

node.status({fill:"green",shape:"dot",text:"success"});
msg.nodegroup = Info[0];
msg.payload   = "{\"" + Info[1] + "\":" + Value[1] + "}";
return [msg];

Each incoming message that matches with the associative array that defines node and key produces a valid datapoint that is posted to Emoncms and turns on a green dot status indication. Incoming messages that are not defined generate a red dot at the function status. If this is the case the status indicator will blink at the presence of unconfigured sensor IDs.

The hardware used was a RPI3 with the latest emoncms SD image. Thanks to all contributors for making this easily available.

3 Likes

Sorry for the necromancy… I am blown away by this… So emoncms could work with flukso.

Now I need to understand how to implement this… :smiley:

1 Like

Nice you just need to find the sensorID’s that are reported through flukso’s MQTT and populate the array
myGauge and Counter. Let me know if you need any help.

1 Like

Thanks for your reply @cab123 I am going to install emoncms today and give it a try. Where is the above file located under the emoncms structure?

Thanks 100000000000!

Hello @cab123, I got emconcms going. I created an account and now I am in the system. I have nothing configured but the server is up and running and I can log in. :slight_smile:

I have the sensor ID’s I just dont know were to populate this array. Do I do it on the web ui? Do I have to add an app?

Thanks for all your help You just shine a new light down a tunnel that was very dark!

Edit: After some research I found NodeRed which seems to be what u are using to build your flow. I am working on that now. Though any tips are still appreciated! New to this but I am a season Linux person.

Hey no tips or else i take away all the fun for you! :grin:

You’re doing great, if you get stuck i’ll be here to help

1 Like

@cab123, HAHAHAHA! Thanks. I got it! This is amazing, I have two flukso’s so now I am trying to figure out how add the second without conflicting with the other.

All setup!

Thanks a million!

@cab123 I do have a question… What is the information been gather by Port4, pplus? The output does not make sense to me so I ma not sure what is the value coming down…

Also what is q4VARh? Is been sent down as well and not sure what it is just like port 4 :slight_smile:

If i remember Port4 pplus is a example of a pulse counter input. The q4VARh i have no idea, maybe search in the flukso git pages or ask the creator.

I’m really happy you managed to set up everything!

edit:

Stop now if you want to live a good life LOL

1 Like

ROFL!!!
Thanks for the advice… I want the good life!
LOL

@cab123,

I just enable the water pulse port on my flukso.
Do I have to do something special to log the water?

The mqtt does look different… Here is an example:

1553388184: /sensor/00000000000000000000000000010001/gauge ~> [1553388184,90270,"L/day"]
1553388184: /sensor/00000000000000000000000000010001/counter ~> [1553388184,645.43,"L"]

I think it is the same as the energy topics, can you please post one to compare? I don’t have a flukso.

If you add a entry on the myGauge and Counter arrays the new values should in emoncms just fine, have you tried?

myGauge['00000000000000000000000000010001'] = 'port1,waterFlow';
Counter['00000000000000000000000000010001'] = 'port1,waterL';

@cab123,

Here is what my electrical sensors look like:

1553437053: /sensor/00000000000000000000000000010001/counter ~> [1553437053,781844,"Wh"]
3437065: /sensor/00000000000000000000000000010001/gauge ~> [1553437065,637,"W"]
1553437064: /sensor/00000000000000000000000000010002/gauge ~> [1553437064,18,"W"]
1553437064: /sensor/00000000000000000000000000010001/gauge ~> [1553437064,643,"W"]
1553437064: /sensor/00000000000000000000000000010001/counter ~> [1553437064,781846,"Wh"]

I added the water sensor just like you did to the electrical sensors and indeed is reporting fine, I just wanted to confirm that there is not a different way to tell emoncms that this one is a water sensor

Now I see you posted port1,waterFlow, Would this help identify in emoncms is a water probe?

This is how it reports in emoncms…

Thanks for all your help @cab123!

Your electrical sensors have the same scheme, the value of the topic includes a timestamp, the value and the units that the value represent.

To emoncms all measures are energy-centric you just need to map the correct units, so in your water case i think Liters represents the same as Energy (kWh) and Liters/Day… being a gauge maybe divide the values by 86400 and get Liters/Second that represents a more meaningfull “power” figure.

No, the mappings simple categorize that particular reading belonging to node “port1” with key being “waterFlow”

1 Like

Thanks for your reply @cab123, Where would I add this value?

In the process list you can calibrate the inputs

1 Like

Thanks!
I added the calibration x with value of 86400. I will post here what it looks like.
Thanks again, If you have pay pal. pm me for a beer donation.

If you want to convert days to seconds you should divide (multiply by the result of 1/86400).

But i’m not sure what is the best flow units that yield the most meaning. Is it per day, minute, second?

1 Like

Both minutes and day :slight_smile: