• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

[MMM-MQTTbridge] A module to publish and receive MQTT messages

Scheduled Pinned Locked Moved Utilities
16 Posts 3 Posters 1.8k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    wishmaster270 Module Developer
    last edited by wishmaster270 Mar 24, 2025, 10:11 AM Nov 20, 2022, 1:42 PM

    MMM-MQTTbridge

    https://github.com/Tom-Hirschberger/MMM-MQTTbridge

    MMM-MQTTbridge allows you to integrate your MagicMirror into your smart home system via MQTT protocol and manage MagicMirror via MQTT messages by converting them into MM Notifications and vise verse - listen to your MM’s Notifications and convert them into MQTT mesages.

    So, this module for MagicMirror does the following:

    Listens to MQTT messages from your MQTT broker and, if mqtt-message arrives, module sends MM Notifications based on the pre-configured mqtt-to-notification Dictionary rules.
    Listens to the MM Notifications within your MagicMirror environment. If Notification arrives, module sends MQTT message based on the preconfigured notification-to-mqtt Dictionary rules.

    mqttbridge_logo.png

    Download:

    MMM-MQTTbridge


    Version 2.2.4:

    • updated jsonpath-plus and mqtt dependency

    Version 2.2.3:

    • bumped version of jsonpath-plus library to 10.1.0

    Version 2.2.2:

    • added a postinstall script which creates a copy of the imported JSONPath library cause MagicMirror only imports files with ending js and not cjs to fix JSONPath

    Version 2.2.1:

    • bumped jsonpath-plus library to version 10.0.1
    • bumped mqtt library to version 5.10.1
    • only print each event (received notification or received mqtt message) on console if debug is enabled, now

    Version 2.2.0:

    • fixed incl condition
    • introducing two new conditions time to suppress messages / notifications if they happen to quickly after each other and tdiff to send messages / notifications only if they changed or there is enough time gap between the last one
    • it is possible to configure notifications / messages which should be send after the module connected and subscribed successfully now

    Version 2.1.0:

    • it is possible the parse the input of MQTT messages as JSON now
    • the JSON content of MQTT messages now can be filtered with JSONPath-Plus
    • the payload of MQTT messages or notifications now can be formatted with a format string before further processing happens
    • it is possible to configure complex conditions (equal, lower than, lower equal, greater, greater equal, includes, matches) for message and notification processing now

    Version 2.0.0:

    :information_source: This is the first release after the ownership of the module changed to Tom-Hirschberger
    :warning: There are breaking changes in the notiDictionary.js and mqttDictionary.js with this release. Make sure to save the two dict files before updating. The files will be ignored with future releases and there is no need to be careful with them after version 2.0.0! Please read the two sections in the Readme about the dictionaries.

    The following things changed:

    • The way of how to configure how to ignore the payload of notifications and MQTT messages changed
    • The way of how to configure how to send the payload of notifications as MQTT messages and the payload of MQTT messages as payload of notifications changed
    • It is now possible to configure a “last will” message and define if you like a clean MQTT session (see http://www.steves-internet-guide.com/mqtt-clean-sessions-example/ for details) or any other of MQTT.js supported connection option
    • It is now possible to configure a QoS value, the retain flag and any other of MQTT.js supported option for published MQTT messages (either in general or individual for single messages)
    • It is now possible to configure a QoS value and any other of MQTT.js supported option for subscribed MQTT messages (either in general or individual for single topics)
    • The paths of the dictionary files can be configured now and the dictionary files in the “dict” directory will be ignored during updates.
    • If one of the dictionary files is missing or has syntax errors a warning is printed but the module starts with empty configuration (and does not crash the whole mirror anymore)
    • The speed of the notification and message filter has been increased
    1 Reply Last reply Reply Quote 2
    • S Serge referenced this topic on Nov 27, 2022, 2:02 PM
    • C Offline
      Cr4z33
      last edited by Jul 22, 2024, 8:22 AM

      @wishmaster270 I would like to intercept the MQTT event of when my Dahua video doorbell is pressed and send the stream to MMM-RTSPStream, but I don’t really know how to get the two modules to “talk” to each other… 😅

      So looking at DahuaVTO2MQTT registry this comes out when the doorbell button is pressed:

      MQTT message published, Topic: DahuaVTO/VideoTalkLog/Event, Payload: {"Action":"Pulse","Data":{"EndState":"Missed","LocalNumber":"9901","LocaleTime":"2024-07-22 10:09:27","RealUTC":1721635767,"TalkTime":0,"UTC":1721639367}}
      

      Now looking at MMM-RTSPStream readme this is the section where it explains how to control it from other modules (aka MMM-MQTTbridge), but as I said above it didn’t make sense to me.

      Can you please help me (at least on your module’s side)?

      W 1 Reply Last reply Jul 22, 2024, 7:33 PM Reply Quote 0
      • W Offline
        wishmaster270 Module Developer @Cr4z33
        last edited by Jul 22, 2024, 7:33 PM

        @Cr4z33 Hi, you will first need the URL of the RTSP stream of your camera.
        In the next step you will need to subscribe to the topic in the file mqttDictionary.js

        var mqttHook = [
            {
              mqttTopic: "DahuaVTO/VideoTalkLog/Event",
              mqttPayload: [
                {
                   jsonpath: "Action", 
                   conditions: [
                               {
                                 type: "eq",
                                 value: "Pulse"
                               },
                             ],
                  mqttNotiCmd: ["doorbell"]
                },
              ],
            },
          ];
        var mqttNotiCommands = [
            {
              commandId: "doorbell",
              notiID: "RTSP-PLAY",
              notiPayload: "YOUR-STREAM-URL" 
            },
          ]; 
        

        But you will need to find a way to stop the stream in any way.

        C 1 Reply Last reply Jul 23, 2024, 9:05 AM Reply Quote 1
        • C Offline
          Cr4z33 @wishmaster270
          last edited by Jul 23, 2024, 9:05 AM

          @wishmaster270 thank you mate!

          Yeah I will add a timeout command as I don’t think it will take much to search for it. 🙂

          C 1 Reply Last reply Jul 23, 2024, 9:29 AM Reply Quote 0
          • C Offline
            Cr4z33 @Cr4z33
            last edited by Jul 23, 2024, 9:29 AM

            @wishmaster270 sorry to bother you again.

            Right now my mqtt Dictionary.js looks like this

            var mqttHook = [
              {
                mqttTopic: "zigbee2mqtt/BTicino F20T60A",
                mqttPayload: [
                  {
                    payloadValue: "",
                    mqttNotiCmd: ["POWERMETER"],
                    mqttPayload: ""
                  },
                ],
              },
            ];
            
            var mqttNotiCommands = [
              {
                commandId: "POWERMETER",
                notiID: "POWERMETER_VALUES",
              },
            ];
            
            module.exports = { mqttHook,  mqttNotiCommands};
            

            so how should I add the new piece of code please?

            W 1 Reply Last reply Jul 23, 2024, 3:01 PM Reply Quote 0
            • W Offline
              wishmaster270 Module Developer @Cr4z33
              last edited by Jul 23, 2024, 3:01 PM

              @Cr4z33 The two datatstructures are arrays containing objects. So you can simply append the two objects…

              var mqttHook = [
                {
                  mqttTopic: "zigbee2mqtt/BTicino F20T60A",
                  mqttPayload: [
                    {
                      payloadValue: "",
                      mqttNotiCmd: ["POWERMETER"],
                      mqttPayload: ""
                    },
                  ],
                },
                {
                    mqttTopic: "DahuaVTO/VideoTalkLog/Event",
                    mqttPayload: [
                      {
                         jsonpath: "Action", 
                         conditions: [
                                     {
                                       type: "eq",
                                       value: "Pulse"
                                     },
                                   ],
                        mqttNotiCmd: ["doorbell"]
                      },
                    ],
                  },
              ];
              
              var mqttNotiCommands = [
                {
                  commandId: "POWERMETER",
                  notiID: "POWERMETER_VALUES",
                },
                {
                    commandId: "doorbell",
                    notiID: "RTSP-PLAY",
                    notiPayload: "YOUR-STREAM-URL" 
                  },
              ];
              
              module.exports = { mqttHook,  mqttNotiCommands};
              
              
              C 1 Reply Last reply Jul 23, 2024, 3:16 PM Reply Quote 1
              • C Offline
                Cr4z33 @wishmaster270
                last edited by Cr4z33 Jul 23, 2024, 3:19 PM Jul 23, 2024, 3:16 PM

                @wishmaster270 thank you again!

                However nothing happens in the MagicMirror frontend (although I can see the MQTT event if running MM by npm start

                [23.07.2024 17:15.55.132] [LOG]   [MQTT bridge] MQTT message received. Topic: DahuaVTO/VideoTalkLog/Event, message: {"Action":"Pulse","Data":{"EndState":"Missed","LocalNumber":"9901","LocaleTime":"2024-07-23 17:15:55","RealUTC":1721747755,"TalkTime":0,"UTC":1721751355}}
                

                I suspect that I am entering the wrong data at

                "YOUR-STREAM-URL"
                

                What shall I enter? Just the IP address or something like ie.

                rtsp://username:password@IPADDRESS/cam/realmonitor?channel=1&subtype=1#backchannel=0
                
                S W 2 Replies Last reply Jul 23, 2024, 3:35 PM Reply Quote 0
                • S Offline
                  sdetweil @Cr4z33
                  last edited by Jul 23, 2024, 3:35 PM

                  @Cr4z33 said in [MMM-MQTTbridge] A module to publish and receive MQTT messages:

                  although I can see the MQTT event if running MM by npm start

                  if using pm2 to autolaunch MM, then

                  pm2 logs --lines=xxxx
                  

                  will show you the last xxxx of the output

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  C 1 Reply Last reply Jul 24, 2024, 9:55 AM Reply Quote 1
                  • W Offline
                    wishmaster270 Module Developer @Cr4z33
                    last edited by Jul 23, 2024, 5:24 PM

                    @Cr4z33 Hi,

                    think I found the problem.
                    You need to send streamX as value where X is the number of the stream in the configuration of MMM-RTSPStream.
                    You will need to configure the camera information in the MMM-RTSPStream module and only will be able to start the stream by notification

                    C 1 Reply Last reply Sep 23, 2024, 10:47 AM Reply Quote 1
                    • C Offline
                      Cr4z33 @sdetweil
                      last edited by Cr4z33 Jul 24, 2024, 9:56 AM Jul 24, 2024, 9:55 AM

                      @sdetweil said in [MMM-MQTTbridge] A module to publish and receive MQTT messages:

                      @Cr4z33 said in [MMM-MQTTbridge] A module to publish and receive MQTT messages:

                      although I can see the MQTT event if running MM by npm start

                      if using pm2 to autolaunch MM, then

                      pm2 logs --lines=xxxx
                      

                      will show you the last xxxx of the output

                      @wishmaster270 said in [MMM-MQTTbridge] A module to publish and receive MQTT messages:

                      @Cr4z33 Hi,

                      think I found the problem.
                      You need to send streamX as value where X is the number of the stream in the configuration of MMM-RTSPStream.
                      You will need to configure the camera information in the MMM-RTSPStream module and only will be able to start the stream by notification

                      Thank you both will do as soon as I am back at home again!

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        5/16
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy