Use the FLM's MQTT broker for further extending your home measurements

With the built-in MQTT broker the FLM provides an easy to use and easy to adapt capability to publish own sensor data beyond the FLM built in energy measurement.
With an Arduino-based MQTT publisher it is possible to add, for example, temperature gauges using the well-known Dallas/Maxim DS18x20 one-wire temperature sensors. Having access to digital as well as analog inputs on the Arduino (or derivate) this is not restricted to temperature but you may connect to any kind of sensor - accelerometers, compasses (did my house move?), humidity, water level (oh, flood again), mains frequency, you name it.
And with a convenient panel they are shown instantly without any configuration (as denoted in another thread)
Be inspired by https://github.com/gebhardm/energyhacks/tree/master/AVRNetIOduino and use your own creativity as long as the Kube is not publically available (or too expensive?).
Please note: Arduino is not only wired-ethernet, but provides also Wifi and BT, so connectivity is unlimited...
Please also note: MQTT is not only for displaying/supplying read-only messages, but may be used also for controlling; so the same means may be used for home automation purposes as well - security measures yet to be implemented!
Have fun.
Markus

jgysenbergs's picture

And so, there is an Arduino on its way. Excellent for long winter evenings coming soon!

ksofluk's picture

I have deployed several MySensor sensors (see http://www.mysensors.org/build/) which are logging to the FLM built-in MQTT broker through a MySensors ESP8266 MQTT gateway. The data is visualized locally using the excellent flmlocal scripts.

Question: FLM does not seem to store the data from these additional sensors. Is there a way to store the data from these additional sensors in tmpo format on the FLM?

gebhardm's picture

The FLM does not log any non-registered sensor in its TMPO storage (be aware that there are some space restrictions also, as the FLM has not too much flash memory) - see https://github.com/flukso/flm02/blob/develop/openwrt/package/flukso/luas...
From this line I would argue that if the configuration is tweaked to reflect also external sensors then also your mySensors would be logged (at own risk, of course). The actual configuration is updated from the /www/scripts/controllers/sensor.js script through some system command which results in an update of /etc/config/flukso (in my FLM02A case up to 13 different sensors)
With the (still upcoming) Kube there "must" be a solution to this, so an alternative is looking for the Kube registration process. Code is still the best documentation ;-)

ksofluk's picture

Gebhardm - thanks a lot for the prompt response.

So it looks like I could try to adopt one of those free sensor IDs that are listed in /etc/config/flukso, and map the MQTT messages accordingly.

But not very confident playing with Lua scripts on Flukso - so I'll just store the data on another MQTT server, until I have more time to play with this :)

Thanks again!

gebhardm's picture

Hmm, I am not sure what really happens when tweaking the config-file. While the tmpo-daemon does not care where an actual sensor read from the config file is located, a look into https://github.com/flukso/flm02/blob/develop/openwrt/package/flukso/luas... reveals that all flukso-config registered sensors are synchronized with the sensor board; the external sensors of course shouldn't... I assume (!) the list port parameter controls some kind of "enabling" on the sensor board side (as all "non-listed" are set to an "unused" 0xff ) - so, if tweaking the config file, better have a finger on the factory reset button and do everything at your own risk - study the code beforehand - lua is not very different from javascript or any other language newer than ALGOL ;-)

vv4yn0's picture

Hi Gebhardm,
I installed your mods and all has been running superbly until my modem died.
I have replaced the modem, connected my flukso with ethernet and toggled the wifi to ethernet so i could log in and set up the new wifi details but the wifi config screen only shows the old wifi details with no option to change them - I can't remember what that screen was like before the mod so unsure what to do - any ideas?
Wayne

gebhardm's picture

Hello vv4yn0,
the wifi screen is not altered by the mod. If you could still reach it then "it should work as expected". You are talking about the v2 FLM, do you? I just checked on mine: If I log on (first step), then I can select the SSID and enter a password in the wifi screen (second step). If all "breaks" then you could either reset the network defaults --> https://github.com/flukso/flm02/wiki#pushbutton or go back to factory default as a "last option" (but then the mod has to be reinstalled again)
HTH, Markus

vv4yn0's picture

Thanks for the pointers Markus. - I did first reset network defaults and then reset to defaults and the wifi settings still did not scan the available wifi - it was just an empty list. I then used winscp to reflash the firmware and the ssid list now works - I am still stuck though, I cant access the box when toggled into wifi mode (when both ethernet and wifi is connected) - I can access ok in ethernet mode. I have tried to SSH in and set the access on wifi with

uci set firewall.@zone[1].input=ACCEPT
uci commit

I get the expected response but nothing changes.
I will keep fiddling - something has to work eventiually!
Thanks for the help :)

gebhardm's picture

Make sure to always clear the browser cache - javascript is horrible in this sense...

vandeputtemichel's picture

Hello,
i try to put the MQTT message from my Flukso FLM to DOMOTICZ

Directly - Not yet possible ? who try to subscribe? result ?
Hardware posibliity :MySensors Gateway with MQTT interface or MQTT Client Gateway with LAN interface
the connection work But NOTHING happen

Or - via Moquitto bridge - But i need to make a simply routing in the mosquitto.conf
subscribe and publish ?

With - MQTTBox in Chrome subscribe / received the data from my FLM OK
mqtt://:1883 then

vandeputtemichel's picture

With - MQTTBox in Chrome subscribe / received the data from my FLM OK
mqtt://:1883 then look the result
[1489963643,914,"W"]
qos : 0, retain : false, cmd : publish, dup : false, topic : /sensor/xxxxxxxxxxxxxxxxxx/gauge, messageId : , length : 68, Raw payload : 9149525657575451545251445749524434873493
Thank's

vandeputtemichel's picture

YES I DO with mosquitto and python: from Flukso to Domoticz
1-in Domoticz create a hardware like : MySensors Gateway with MQTT interface
with your moquitto ip and port
2-in Mosquitto simple conf with same ip and port
3-with python library in the path
where paho library is download ( pip install paho-mqtt )
4- this my prototype python program with debug print

import paho.mqtt.subscribe as subscribe
import paho.mqtt.client as mqtt
import re
mqttc = mqtt.Client()

def on_message_print(client, userdata, message):
#print("%s %s" %(message.topic, message.payload))
#print("%s" %(message.topic))
#print("%s" %(message.payload))
t = ("%s" %(message.payload))
#print(t)
m = re.search(',(.+?),', t)
r = flukso_extract(t)
#print("W:",r)
x = mosquitto_pub(r)

def flukso_extract(text):
#print(text)
m = re.search(',(.+?),', text)
#print(m)
f = ""
if m:
f = m.group(1)
#print("found",f)
return(f)

def mosquitto_pub(msg_data):
mqttc.publish("domoticz/in/MyMQTT/5/1/1/0/17",msg_data)
#print("publish registration node 5 child 1 data 1")
print("publish flukso_3ao:",msg_data)

print("start Mosquitto on ip nnn.nnn.nnn.nnn")
mqttc.connect("nnn.nnn.nnn.nnn", 1883,60)
print("publish registration node 5 child 1 type 17 Watt")
mqttc.publish("domoticz/in/MyMQTT/5/1/0/0/17", "Flukso_3a0")
print("start listening flukso")
subscribe.callback(on_message_print, "/sensor/xxxxxxxxxxxxxxxxxxx/gauge/#", hostname="FFF.FFF.FFF.FFF" , port=1883 , keepalive=60 )
print("stop")

IN domoticz
2018-03-31 15:58:12.326 (RFX333) Temp + Humidity (T_TUYAU)
2018-03-31 15:58:17.232 (RFX333) Temp + Humidity (T_Surgelateur)
2018-03-31 15:58:19.670 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/0/0/17, Message: Flukso_3a0
2018-03-31 15:58:19.779 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message:
2018-03-31 15:58:19.889 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message: 791
2018-03-31 15:58:19.998 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message: 783
2018-03-31 15:58:20.123 (Mosquitto) Usage (flukso)
2018-03-31 15:58:20.545 (Mosquitto) Usage (flukso)
2018-03-31 15:58:20.779 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message: 797
2018-03-31 15:58:20.842 (Mosquitto) Usage (flukso)
2018-03-31 15:58:21.186 (Mosquitto) Usage (flukso)
2018-03-31 15:58:21.779 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message: 802
2018-03-31 15:58:22.092 (Mosquitto) Usage (flukso)
2018-03-31 15:58:22.217 (RFX333) Temp + Humidity (T_SDB)
2018-03-31 15:58:22.779 MySensorsMQTT: Topic: domoticz/in/MyMQTT/5/1/1/0/17, Message: 802

1144 Mosquitto 0000005 1 flukso Usage Electric 799 Watt -

gebhardm's picture

Just for the records: The output format of the FLM is json, so just import json and use this instead of neat regular expressions: python json. Then you may even use the transmitted timestamp and the unit. All you need to do is receive, transform and republish a MQTT message... (I learned that node-red is the answer to all questions ;-))

gebhardm's picture

And the super-duper-simple way is tweaking the flukso daemon's MQTT publication itself; see the corresponding codeline to publish the gauge values; here you may just add a second topic publication afterwards mqtt:publish(yourTopic, yourPayload, MOSQ_QOS, MOSQ_RETAIN); this is the fascination of open source... (be fair and also use github to publish your own code!) - use ssh and beloved vi ;-) (the fluksod.lua file is in /usr/sbin - and know what you are doing; but at last a factory reset is just a button push away - hi hi)