This adds MQTT features to Ubiquiti Networks mPower devices. This is version 2, which aims to comply with homie MQTT convention. The implementation of the convention is not complete yet.
Use at your own risk!
A linux system is required to install the MQTT client into your mPower. First add your public key to the mPower device.
ssh-copy-id -o KexAlgorithms=+diffie-hellman-group1-sha1 -o Ciphers=+aes256-cbc -o HostKeyAlgorithms=+ssh-dss -i ~/.ssh/id_rsa ubnt@<mpowerhost>
If that works fine, execute the following commands on your linux machine:
wget -q https://raw.githubusercontent.com/magcode/mpower-tools/refs/heads/master/mqtt/client/install-client.sh
chmod 777 install-client.sh
./install-client.sh <mpowerhost>
Now SSH into your mPower, change mqtt.cfg
, mpower-pub.cfg
, led.cfg
and "save"
ssh <mpowerhost>
save
reboot
/var/etc/persistent/mqtt/client/mqrun.sh
The script also starts automatically approx 3 minutes after booting the device (using rc.poststart).
/var/etc/persistent/mqtt/client/mqstop.sh
Edit the file /var/etc/persistent/mqtt/client/mqtt.cfg
and configure your server, topic and refresh time. Setting topic, refresh, mqttusername and mqttpassword is not mandatory. Defaults are
topic=homie/[name of the mpower]
and refresh=60
seconds
mqtthost=192.168.0.1
#refresh=60
#topic=my/topic
#mqttusername=myMqttUserName
#mqttpassword=myMqttPassword
You can suppress certain attributes (such as voltage) by editing the file mpower-pub.cfg
. Set value to 0
if you dont need the data.
#enable (1) or disable (0) properties here
relay=1
power=1
energy=1
lock=1
voltage=0
You can configure the LED using the file led.cfg
.
# set the led state using this configuration, none of the settings mandatory!
# afterboot ... led state after starting
# relay_off ... led state when all relays are OFF
# relay_on ... led state if at least one relay is ON
# 0=OFF, 1=BLUE, 2=YELLOW, 3=PURPLE
afterboot=3
# relay_on=1
# relay_off=0
The mPower device will publish messages every 60 seconds to different topics. Example:
homie/mpower-1/port1/relay=0
homie/mpower-1/port2/relay=1
homie/mpower-1/port3/relay=0
homie/mpower-1/port1/power=0.0
homie/mpower-1/port2/power=7.2
homie/mpower-1/port3/power=0.0
homie/mpower-1/port1/energy=0
homie/mpower-1/port2/energy=4
homie/mpower-1/port3/energy=8
homie/mpower-1/port1/voltage=0.0
homie/mpower-1/port2/voltage=234.9
homie/mpower-1/port3/voltage=0.0
Additionally - currently only at the start of the script - the device will also report:
homie/mpower-1/$homie=2.1.0
homie/mpower-1/$name=mpower-1
homie/mpower-1/$fw/version=MF.v2.1.11-mq-0.2
homie/mpower-1/$fw/name=mPower=MQTT
homie/mpower-1/$localip=192.168.1.26
homie/mpower-1/$nodes=port1,port2,port3
homie/mpower-1/$stats/uptime=2589629.67
homie/mpower-1/port1/relay/$settable=true
homie/mpower-1/port2/relay/$settable=true
homie/mpower-1/port3/relay/$settable=true
homie/mpower-1/port1/lock/$settable=true
homie/mpower-1/port2/lock/$settable=true
homie/mpower-1/port3/lock/$settable=true
You can control the sockets by sending 0
or 1
to the topic <topic chosen above>/port<number of socket>/relay/set
You can lock the sockets by sending 0
or 1
to the topic <topic chosen above>/port<number of socket>/lock/set
The tool logs into standard messages log.
tail -f /var/log/messages
This is an example how to define an openHAB thing:
Thing mqtt:topic:switchTV "Switch TV" (mqtt:broker:mosquitto) {
Channels:
Type switch : switch "Switch" [ stateTopic="homie/mympower/port4/relay", on="1", off="0", commandTopic="homie/mympower/port4/relay/set"]
Type number : consumption "Consumption" [ stateTopic="homie/mympower/port4/energy"]
Type number : power "Power" [ stateTopic="homie/mympower/port4/power"]
}
and the according items:
Switch switchWZTV "Switch TV" { channel="mqtt:topic:switchTV:switch"}
Number switchWZTVEnergy "Switch TV Energy [%d Wh]" { channel="mqtt:topic:switchTV:consumption"}
Number switchWZTVPower "Switch TV Power [%.1f W]" { channel="mqtt:topic:switchTV:power"}