{"id":5986,"date":"2024-04-24T10:02:00","date_gmt":"2024-04-24T08:02:00","guid":{"rendered":"https:\/\/shakti.tattva.se\/?p=5986"},"modified":"2025-08-30T07:45:37","modified_gmt":"2025-08-30T05:45:37","slug":"using-a-meross-wi-fi-switch-with-openhab","status":"publish","type":"post","link":"https:\/\/shakti.tattva.se\/index.php\/using-a-meross-wi-fi-switch-with-openhab\/","title":{"rendered":"Using a Meross Wi-Fi switch with OpenHab"},"content":{"rendered":"<div class=\"post-body-wrapper\">\n<div class=\"post-body\">\n<p>The aim of this article to set up and configure a Meross Wi-Fi switch (I\u2019m using an MSS310) with OpenHab2 to work in offline mode \u2014 with MQTT and no dependency on the Meross online services.<\/p>\n<p>I gathered most, almost all, of the information required from this thread on github <a href=\"https:\/\/github.com\/albertogeniola\/MerossIot\/issues\/1\">Offline-ONLY support<\/a>.<\/p>\n<p>For this article, you need to be comfortable with the command line, and have git and node.js installed; you should already have an OpenHab2 setup.<\/p>\n<h2 id=\"configure-an-mqtt-server\">Configure a MQTT server<\/h2>\n<p>Install <a href=\"https:\/\/archlinux.org\/packages\/extra\/x86_64\/mosquitto\/\">mosquitto<\/a><\/p>\n<p>The Meross switch requires a secure MQTT server.<\/p>\n<pre>ssldir=\"\/usr\/share\/licenses\/mosquitto\/\"\r\n\r\n# ca\r\nopenssl genrsa -out $ssldir\/ca.key 2048\r\nopenssl req -new -x509 -days 1826 -key $ssldir\/ca.key -out $ssldir\/ca.crt -subj \"\/CN=MQTT CA\"\r\n\r\n# broker\r\nopenssl genrsa -out $ssldir\/broker.key 2048\r\nopenssl req -new -out $ssldir\/broker.csr -key $ssldir\/broker.key -subj \"\/CN=broker\"\r\nopenssl x509 -req -in $ssldir\/broker.csr -CA $ssldir\/ca.crt -CAkey $ssldir\/ca.key -CAcreateserial -out $ssldir\/broker.crt -days 360\r\n\r\n\r\n<\/pre>\n<h2>Edit mosquitto configuration<\/h2>\n<p>In \/etc\/mosquitto\/mosquitto.conf:<\/p>\n<pre>listener 1883\r\nallow_anonymous true\r\nlistener 8883\r\nport 1883\r\nallow_anonymous true\r\nrequire_certificate false\r\n# replace with your CA Root \r\ncafile \/usr\/share\/licenses\/mosquitto\/ca.crt\r\n# replace with your server certificate and key paths \r\ncertfile \/usr\/share\/licenses\/mosquitto\/broker.crt\r\nkeyfile \/usr\/share\/licenses\/mosquitto\/broker.key<\/pre>\n<h6>Create cert_regen.sh bash script, which will create a new certificate once a week:<\/h6>\n<pre>#!\/usr\/bin\/env bash\r\nssldir=\"\/usr\/share\/licenses\/mosquitto\/\"\r\n\r\n# ca\r\nopenssl genrsa -out $ssldir\/ca.key 2048\r\nopenssl req -new -x509 -days 1826 -key $ssldir\/ca.key -out $ssldir\/ca.crt -subj \"\/CN=MQTT CA\"\r\n\r\n# broker\r\nopenssl genrsa -out $ssldir\/broker.key 2048\r\nopenssl req -new -out $ssldir\/broker.csr -key $ssldir\/broker.key -subj \"\/CN=broker\"\r\nopenssl x509 -req -in $ssldir\/broker.csr -CA $ssldir\/ca.crt -CAkey $ssldir\/ca.key -CAcreateserial -out $ssldir\/broker.crt -days 360<\/pre>\n<h6>Create a cronjob for it<\/h6>\n<pre>00 22 * * 7 \/....\/cert_regen.sh<\/pre>\n<h2 id=\"configure-the-meross-switch-for-your-wi-fi-and-mqtt-server\">Configure the Meross switch for your Wi-Fi and MQTT server<\/h2>\n<h3 id=\"get-the-meross-tools-from-your-command-line\">Get the meross tools, from your command line<\/h3>\n<pre><code>git clone https:\/\/github.com\/bytespider\/Meross\r\ncd Meross\/bin\/src\r\nnpm i\r\n<\/code><\/pre>\n<h6 id=\"plugin-your-wi-fi-switch\">Plugin the Meross smartplug.<\/h6>\n<p>If it\u2019s not your first time using the switch, press and hold the power button for 5 seconds. Connect to its Wi-Fi access point (Meross_XXX)<\/p>\n<h6 id=\"configure-the-switch-for-your-wi-fi-and-mqtt-server\">Configure the switch for your Wi-Fi and MQTT Server<\/h6>\n<p>from Meross\/bin\/src directory<\/p>\n<pre><code>.\/meross setup --gateway 10.10.10.1 --wifi-ssid &lt;your-ssid&gt; --wifi-pass &lt;your-pass&gt; --mqtt &lt;mqtt-host-ip&gt;:8883\r\n<\/code><\/pre>\n<p>At this stage, you may hear some clicks from the switch. You can also verify that it has connected using the mosquito logs:<\/p>\n<p><code>1595295630: New client connected from 192.168.30.7<\/code><\/p>\n<p>You should also see some messages from the new switch:<\/p>\n<p><code>\/appliance\/<\/code><strong>1712281825467829030134298f151c4a<\/strong><code>\/publish<\/code><\/p>\n<p>{&#8220;header&#8221;:{&#8220;messageId&#8221;:&#8221;7c2834f83f9cc5b1c7ae1049280a9f3f&#8221;,&#8221;namespace&#8221;:&#8221;Appliance.Control.ToggleX&#8221;,&#8221;method&#8221;:&#8221;PUSH&#8221;,&#8221;payloadVersion&#8221;:1,&#8221;from&#8221;:&#8221;\/appliance\/1712281825467829030134298f151c4a\/publish&#8221;,&#8221;timestamp&#8221;:1557534775,&#8221;timestampMs&#8221;:955,&#8221;sign&#8221;:&#8221;f07e2a7ab622997508d359cb89c74038&#8243;},&#8221;payload&#8221;:{&#8220;togglex&#8221;:{&#8220;channel&#8221;:1,&#8221;onoff&#8221;:1,&#8221;lmTime&#8221;:1557534775}}}<\/p>\n<p><strong>Note the appliance ID in bold above.<\/strong><\/p>\n<p>On my Mac, I also used <a href=\"https:\/\/apps.apple.com\/us\/app\/mqtt-explorer\/id1455214828?mt=12\">MQTT Explorer<\/a> to view the messages and to determine the appliance id.<\/p>\n<h2 id=\"add-the-switch-to-openhab\">Add the switch to Openhab<\/h2>\n<h3 id=\"add-a-new-thing\">Add a new thing.<\/h3>\n<ul>\n<li>Using the Paper UI as a new thing.\n<ul>\n<li>Inbox \/ \u201c+\u201d on the top of the screen.<\/li>\n<li>Select MQTT Binding.<\/li>\n<li>Manually Add Thing<\/li>\n<li>Select Generic MQTT Thing<\/li>\n<li>Give your thing a name, and select your MQTT bridge (configured from step 1).<\/li>\n<\/ul>\n<\/li>\n<li>Add a Channel\n<ul>\n<li>On\/Off Switch<\/li>\n<li>The settings are as follows:\n<ul>\n<li>MQTT State Topic: <code>\/appliance\/&lt;appliance_id&gt;\/publish<\/code><\/li>\n<li>MQTT Command Topic: <code>\/appliance\/&lt;appliance_id&gt;\/subscribe<\/code><\/li>\n<li>Custom On\/Open Value: <code>1<\/code><\/li>\n<li>Custom Off\/Closed Value: <code>0<\/code><\/li>\n<li>Incoming Value Transformations: <code>JSONPATH:$.payload.togglex..onoff<\/code><\/li>\n<li>Outgoing Value Transformation: <code>JS:meross.js<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Finally, download the following file, <a href=\"https:\/\/theriom.com\/assets\/meross.js\">meross.js<\/a> and save it to your transform directory, for me this is <code>\/etc\/openhab2\/transform\/<\/code>.<\/p>\n<p>The meross.js file creates the JSON structure required to control the switch.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The aim of this article to set up and configure a Meross Wi-Fi switch (I\u2019m using an MSS310) with OpenHab2 to work in offline mode \u2014 with MQTT and no dependency on the Meross online services. I gathered most, almost all, of the information required from this thread on github Offline-ONLY support. For this article,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_kad_post_transparent":"default","_kad_post_title":"default","_kad_post_layout":"default","_kad_post_sidebar_id":"","_kad_post_content_style":"default","_kad_post_vertical_padding":"default","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[445],"tags":[],"class_list":["post-5986","post","type-post","status-publish","format-standard","hentry","category-openhab"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/posts\/5986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/comments?post=5986"}],"version-history":[{"count":7,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/posts\/5986\/revisions"}],"predecessor-version":[{"id":8987,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/posts\/5986\/revisions\/8987"}],"wp:attachment":[{"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/media?parent=5986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/categories?post=5986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shakti.tattva.se\/index.php\/wp-json\/wp\/v2\/tags?post=5986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}