Meross Devices with local MQTT Broker - Cloudless

Hi everyone,

in the last few days I was struggeling a bit to get my Meross power strip (MSS425F) to work with openhab3, so I thought to write a quick tutorial how I got it to work. This solution runs locally without the need to connect to the meross Cloud.

First of all a big thanks to:

  • bytespider for his great work on the Meross solution, which allows to connect to a local mqtt broker. And his documentation for the mqtt config, link in the second post.
  • Colin Fitzpatrick for providing a tutorial over at theriom.com

For my solution, Iā€™m running a docker image of eclipse-mosquitto where my certificates are mounted and configured. The Meross power strip is then configured to use this broker for the communication. Openhab again can communicate as well with it and can send commands.

Configuring MQTT - Docker-Compose

For MQTT Iā€™m using a simple docker service, which I run via compose. This will automatically deploy an MQTT broker and load the config from ā€œ./mqtt/configā€

---
version: '3.5'
services:
  mqtt:
    image: eclipse-mosquitto:latest
    container_name: mqtt
    hostname: mqtt
    restart: unless-stopped
    volumes:
      - "./mqtt/config:/mosquitto/config"
      - "./mqtt/data:/mosquitto/data"
      - "./mqtt/log:/mosquitto/log"
      - "./mqtt/ssl:/ssl"
    ports:
      - "1883:1883"
      - "8883:8883"

Since this broker runs only locally and has no contact to the internet, I kept the config as simple as possible.

listener 8883
port 1883
allow_anonymous true
require_certificate false
# replace with your CA Root
cafile /ssl/ca.crt
# replace with your server certificate and key paths
certfile /ssl/broker.crt
keyfile /ssl/broker.key

Iā€™ve also created a simple bash script, which will create a new certificate once a week, so I do not have to care to much about the certificate and probably forget about it in the 360 days lifetime of it.

#!/usr/bin/env bash
cd /opt/containers
docker stop mqtt
ssldir=./mqtt/ssl

# ca
openssl genrsa   -out $ssldir/ca.key   2048
openssl req   -new   -x509   -days 1826   -key $ssldir/ca.key   -out $ssldir/ca.crt   -subj "/CN=MQTT CA"

# broker
openssl genrsa   -out $ssldir/broker.key   2048
openssl req   -new   -out $ssldir/broker.csr   -key $ssldir/broker.key   -subj "/CN=broker"
openssl x509   -req   -in $ssldir/broker.csr   -CA $ssldir/ca.crt   -CAkey $ssldir/ca.key   -CAcreateserial   -out $ssldir/broker.crt   -days 360

docker start mqtt

And created a cronjob for it

00 22 * * 7 /opt/containers/mqtt/cert_regen.sh

Now we can take the broker up.

docker-compose up -d

We can test and see if the broker is running on one shell run

docker exec -ti mqtt mosquitto_sub -h localhost -t '#' -t '/#' -v

and in another shell

mosquitto_pub -h localhost -t "test" -m "message"

If you see the message on the first shell everything is fine :slight_smile:

Install dependencies

For the following procedure you need a computer with wifi and a working npm >= 12 installation. There are plenty of tutorials online.

Next we will clone/download the meross_lan repo and switch into it and in the bin folder. In here we will just install the needed npm packages via commandline with ā€œnpm iā€ (keep the commandline open)

Thats all dependencies we need here.

Reset your Meross Device

For my power strip, of what I read itā€™s the same for most Meross devices, I needed to press the power for 5 sec. and the reset was done.

Bind Meross to MQTT Broker

First we connect our computer to the now availible SSID from the Meross Device, in my case it was just Meross_.
Now we head back to our commandline in the folder Meross/bin, maybe you need to make the file runable via ā€œchmod +x ./meross-setupā€

sudo ./meross-setup --gateway 10.10.10.1 --wifi-ssid '<mywifiname>' --wifi-pass '<mywifipw>' --mqtt mqtts://<broker-ip>:8883

After running the command, my power strip clicked a few times and got online.
Little gotcha I had here, was as my mqtt broker was not configured correctly the first time. If this is the case, the power strip tried to connect, was pingable a few times on the network and resetted itself again to factory defaults. So if this is the case something is wrong with the mqtt connection.

Connection to Openhab

  • Create a Thing for your Broker
    • Keep it simple, I only used IP-adress, username and password
  • Create a Thing for Meross
    • Select the previous created broker as bridge
    • Add Channel(s), example below
      • here you will need the appliance ID, which you can get from your broker with the mosquitto_sub command from above.
    • The last thing we need to add is the transformation. You can download this file near the bottom of Colin Fritzpatricks article Ā“meross.jsĀ“ In his article you can also find the how to for the channel config.
      • Place this in your openhab folder under Ā“openhab/conf/transform/Ā“

Note: If you have a power strip, like I have you need to make some minor changes to the transformation file. For each power outlet you have on the strip, you need a transformation file. I renamed the files to setMeross[description].js and inside the files you need to set the channel, line 17, to match the outlet you want to control.

pi@internal:~ $ ls -la /opt/containers/openhab/conf/transform/
-rw-r--r--  1 pi pi 9242 Oct  8 11:20 setMerossAll.js
-rw-r--r--  1 pi pi 9242 Oct  8 11:20 setMerossComputer.js
-rw-r--r--  1 pi pi 9242 Oct  8 11:20 setMerossLaptop.js
-rw-r--r--  1 pi pi 9242 Oct  8 11:20 setMerossPeripherals.js
-rw-r--r--  1 pi pi 9242 Oct  8 11:21 setMerossState.js
-rw-r--r--  1 pi pi 9242 Oct  8 11:21 setMerossUSB.js
UID: mqtt:topic:f1927b217c:73636c37a8
label: MQTT Meross
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:f1927b217c
channels:
  - id: office_socket
    channelTypeUID: mqtt:switch
    label: office
    description: ""
    configuration:
      commandTopic: /appliance/<appliance_ID>/subscribe
      transformationPatternOut: JS:setMerossAll.js
      stateTopic: /appliance/<appliance_ID>/publish
      transformationPattern: JSONPATH:$.payload.togglex..[?(@.channel == 0)].onoff
      off: "0"
      on: "1"
1 Like

Links:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.