• 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

Scheduled Pinned Locked Moved Unsolved System
44 Posts 14 Posters 12.3k Views 15 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.
  • S Offline
    Serge @fribse
    last edited by Serge Feb 26, 2020, 6:02 PM Feb 25, 2020, 10:20 PM

    You have (1) mismatch in config and (2) wrong use of MMMRemoteControl syntax.

    1. First.
      You config.js contains a line:

    useMqttBridgeFormatOnly: false,

    use the syntax exactly as it is written in the module’s readme. So please correct your config.js to useMqttBridgeFromatOnly.
    !!! I know about this misprint but it will be corrected in next release. As of now use as it is mentioned in readme.

    1. Second.

    notiPayload: ‘MONITOROFF’

    Notifications REMOTE_ACTION:MONITOROFF should be issued by the MQTTbridge module with your current mqttDictionary.js.

    However, I have checked the MMM-Remote control module, section “examples” and have found that MMMRemoteControl requires different from your Notification’s payload. It requires format: REMOTE_ACTION:{action: 'MONITOROFF'}

    So correct your mqttDictionary according to that format from MMM-Remote Control repo. As I understood, for monitor turn-off it should look like:

      commandId: "MONITOROFF",
      notiID: "REMOTE_ACTION",
      notiPayload: "{action: 'MONITOROFF'}"
    

    Check the terminal log, MQTTbridge log in there (1) module start/stop (2) connection to mqtt server (3) conversion mqtt->noti.

    1 Reply Last reply Reply Quote 0
    • S Offline
      Serge @fribse
      last edited by Serge Feb 25, 2020, 10:48 PM Feb 25, 2020, 10:21 PM

      @fribse said in MMM-MQTTbridge:

      where can I see if it even receives the message?

      see the log in terminal
      module produces something like this:

      [00:46:52.653] [LOG]    [MQTT bridge] MQTT message received. Topic: cmnd/home/smartmirror/volume/set, message: VOLUME_SET:0
      [00:46:52.873] [LOG]    [MQTT bridge] MQTT -> NOTI issued: VOLUME_SET, payload: 0
      
      1 Reply Last reply Reply Quote 0
      • F Offline
        fribse
        last edited by fribse Mar 1, 2020, 2:04 PM Mar 1, 2020, 2:02 PM

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • F Offline
          fribse
          last edited by fribse Mar 1, 2020, 3:21 PM Mar 1, 2020, 3:11 PM

          Ok, I fixed the config.
          The typo is back :-)

          I see a few results right of the bat:

          [15:55:10.009] [LOG]    [MQTT bridge] MQTT brocker error: Error: client disconnecting
          [15:55:10.015] [LOG]    [MQTT bridge] NOTI->MQTT. Topic: home/bathroom/mirror/set, payload: {"state":"OFF"}
          [15:55:20.026] [LOG]    [MQTT bridge] MQTT brocker error: Error: client disconnecting
          [15:55:20.028] [LOG]    [MQTT bridge] NOTI->MQTT. Topic: home/bathroom/mirror/set, payload: {"state":"ON"}
          

          It also pops up on the screen that the MQTT broker is not replying, which is weird, as it’s in use for a lot of systems. Not sure what is going on?

          The dict looks like this:

          var mqttHook = [
              {
                mqttPayload: "TURN_OFF_SCREEN",
                mqttNotiCmd: ["MONITOROFF"]
              },
              {
                mqttPayload: "TURN_ON_SCREEN",
                mqttNotiCmd: ["MONITORON"]
              },
              {
                mqttPayload: "UNDIM_SCREEN",
                mqttNotiCmd: ["UNDIM"]
              },
              {
                mqttPayload: "DIM_SCREEN",
                mqttNotiCmd: ["DIM"]
              },
           ];
          var mqttNotiCommands = [
              {
                commandId: "MONITOROFF",
                notiID: "REMOTE_ACTION",
                notiPayload: "{action: 'MONITOROFF'}"
              },
              {
                commandId: "MONITORON",
                notiID: "REMOTE_ACTION",
                notiPayload: "{action: 'MONITORON'}"
              },
              {
                commandId: "UNDIM",
                notiID: "REMOTE_ACTION",
                notiPayload: "{action; 'BRIGHTNESS 100'}"
              },
              {
                commandId: "DIM",
                notiID: "REMOTE_ACTION",
                notiPayload: "{action: 'BRIGHTNESS 75'}"
              },
            ];
          
            module.exports = { mqttHook,  mqttNotiCommands};
          

          When I publish the MONITOROFF to it, it seems to pick it up and then bummer:

          [16:04:30.547] [LOG]    [MQTT bridge] MQTT message received. Topic: cmnd/home/bathroom/mirror, message: TURN_OFF_SCREEN
          [16:04:30.639] [LOG]    [MQTT bridge] MQTT -> NOTI issued: REMOTE_ACTION, payload: {action: 'MONITOROFF'}
          [16:04:30.646] [LOG]    Whoops! There was an uncaught exception...
          [16:04:30.665] [LOG]    MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
          [16:04:30.667] [LOG]    If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
          [16:04:30.710] [LOG]    Whoops! There was an uncaught exception...
          [16:04:30.713] [LOG]    MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
          [16:04:30.714] [LOG]    If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
          

          So for me it looks like the MQTT part works, it’s the sending to ‘Remote commander’ that is not working, or am I wrong?
          I’ve also tried creating a ‘RESTART’ command, same result.

          S 1 Reply Last reply Mar 1, 2020, 9:43 PM Reply Quote 0
          • S Offline
            Serge @fribse
            last edited by Serge Mar 1, 2020, 10:01 PM Mar 1, 2020, 9:43 PM

            @fribse said in MMM-MQTTbridge:

            [16:04:30.547] [LOG] [MQTT bridge] MQTT message received. Topic: cmnd/home/bathroom/mirror, message: TURN_OFF_SCREEN

            the log record above means that MMM-MQTTbridge received mqtt message at the topic cmnd/home/bathroom/mirror with payload TURN_OFF_SCREEN.

            The next log record

            [16:04:30.639] [LOG] [MQTT bridge] MQTT -> NOTI issued: REMOTE_ACTION, payload: {action: ‘MONITOROFF’}

            says that MQTTbridge issued MagicMirror’s notification REMOTE_ACTION with payload {action: 'MONITOROFF'} which is exactly what you need. So this part works well.

            However, the further messages in log

            [16:04:30.646] [LOG] Whoops! There was an uncaught exception…
            [16:04:30.665] [LOG] MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
            [16:04:30.667] [LOG] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues

            says that something went wrong with the MM core. That could be the reason for not executing the command by another module.

            To find out the reason, you need to localize the error. Try to disable all modules and then add modules one-by-one and find which one cause that error.
            hint: to disable modules, use disabled: true within each module config.

            Change also listenNoti: to false, in MQTTbridge config if you do not need to convert Noti to Mqtt messages. So the module will not check all incoming MM’s notifications.

            Here is the full log within my setup, I just sent a simple message to issue noti TEST with payload message:

            pi@raspberrypi:~/MagicMirror $ npm start dev
            
            > magicmirror@2.10.1 start /home/pi/MagicMirror
            > ./run-start.sh "dev"
            
            [23:48:05.361] [LOG]    Starting MagicMirror: v2.10.1
            [23:48:05.395] [LOG]    Loading config ...
            [23:48:05.435] [LOG]    Loading module helpers ...
            [23:48:05.444] [LOG]    No helper found for module: clock.
            [23:48:07.792] [LOG]    Initializing new module helper ...
            [23:48:07.794] [LOG]    Module helper loaded: calendar
            [23:48:07.800] [LOG]    No helper found for module: currentweather.
            [23:48:07.802] [LOG]    No helper found for module: weatherforecast.
            [23:48:07.890] [LOG]    Initializing new module helper ...
            [23:48:07.891] [LOG]    Module helper loaded: newsfeed
            [23:48:08.506] [LOG]    Initializing new module helper ...
            [23:48:08.507] [LOG]    Module helper loaded: MMM-MQTTbridge
            [23:48:08.691] [LOG]    All module helpers loaded.
            [23:48:08.693] [LOG]    Starting server on port 8181 ... 
            [23:48:08.705] [INFO]   You're using a full whitelist configuration to allow for all IPs
            [23:48:08.735] [LOG]    Server started ...
            [23:48:08.740] [LOG]    Connecting socket for: calendar
            [23:48:08.744] [LOG]    Starting node helper for: calendar
            [23:48:08.747] [LOG]    Connecting socket for: newsfeed
            [23:48:08.749] [LOG]    Starting module: newsfeed
            [23:48:08.752] [LOG]    Connecting socket for: MMM-MQTTbridge
            [23:48:08.754] [LOG]    [MQTT bridge] Module started
            [23:48:08.800] [LOG]    Sockets connected & modules started ...
            [23:48:09.890] [LOG]    Launching application.
            [23:48:26.071] [LOG]    [MQTT bridge] Subscribed to the topic: home/smartmirror/bathroom/light/set
            [23:51:43.274] [LOG]    [MQTT bridge] MQTT message received. Topic: home/smartmirror/bathroom/light/set, message: TEST:message
            [23:51:43.420] [LOG]    [MQTT bridge] MQTT -> NOTI issued: TEST, payload: message
            
            1 Reply Last reply Reply Quote 0
            • F Offline
              fribse
              last edited by fribse Mar 2, 2020, 11:04 AM Mar 2, 2020, 10:47 AM

              Hmm, not really sure what changed. I’ve tried setting the notilisten to false, and then I don’t see the error, but after reactivating it, I still dont’ see it.
              I can see that the log reports state 0x6 when the monitor is on, and 0x2 when it’s off.
              I can send commands to the Remote_Control module via http api, but nothing happens when I try it via the mqttbridge.
              I guess I have to ask @Jopyth about that?

              I also tried changing the quotation markings in the dict file, to match the Remote_Control parameters in the examples, but no change :-(

              var mqttNotiCommands = [
                  {
                    commandId: "MONITOROFF",
                    notiID: 'REMOTE_ACTION',
                    notiPayload: '{action: "MONITOROFF"}'
                  },
                  {
                    commandId: "MONITORON",
                    notiID: 'REMOTE_ACTION',
                    notiPayload: '{action: "MONITORON"}'
                  },
                  {
                    commandId: "UNDIM",
                    notiID: 'REMOTE_ACTION',
                    notiPayload: '{action; "BRIGHTNESS", value: "100"}'
                  },
                  {
                    commandId: "DIM",
                    notiID: "REMOTE_ACTION",
                    notiPayload: '{action: "BRIGHTNESS", value: "75"}'
                  },
                  {
                    commandId: "RESTART",
                    notiID: "REMOTE_ACTION",
                    notiPayload: '{action: "RESTART"}'
                  },
                ];
              
              1 Reply Last reply Reply Quote 0
              • ? Offline
                A Former User
                last edited by Mar 3, 2020, 7:45 AM

                @fribse said in MMM-MQTTbridge:
                notiPayload: '{action; "BRIGHTNESS", value: "100"}'

                attention the syntax is not correct

                try wih:

                notiPayload: '{action: "BRIGHTNESS", value: "100"}'

                F 1 Reply Last reply Mar 3, 2020, 9:52 AM Reply Quote 0
                • F Offline
                  fribse @Guest
                  last edited by Mar 3, 2020, 9:52 AM

                  @Bugsounet Thanks, it doesn’t change the behaviour though :-)

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    fribse
                    last edited by fribse Mar 8, 2020, 10:55 AM Mar 8, 2020, 9:14 AM

                    Darned, I just found the problem.

                    I had this in the mqttdictionary:

                    var mqttHook = [
                        {
                          mqttPayload: "TURN_OFF_SCREEN",
                          mqttNotiCmd: ["MONITOROFF"]
                        },
                    

                    But I was sending a MQTT message with ‘MONITOROFF’, if I send ‘TURN_OFF_SCREEN’ it works perfectly :-)

                    Thankyou @Serge and @Bugsounet for this GREAT module, just the missing piece.
                    Now I have to figure out about the noti->mqtt thing, I can see that the monitor status is reported in the log, but I can’t see what ‘notification’ is sent…

                    P.S. the logfile looks a bit weird:

                    0|mm  | [MQTT bridge] MQTT message received. Topic: cmnd/bathroom/mirror, message: MONITORON
                    0|mm  | [MQTT bridge] MQTT -> NOTI issued: REMOTE_ACTION, payload: **[object Object]**
                    

                    But it works…

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      Serge
                      last edited by Serge Mar 8, 2020, 12:11 PM Mar 8, 2020, 12:06 PM

                      @fribse , finally it works for you. So the reason was the incorrect config initially as I understood.

                      P.S. the logfile looks a bit weird:

                      log means that the payload of the noti is an “object” and not other type of data.

                      Now I have to figure out about the noti->mqtt thing,

                      Exactly the same as for mqtt->noti: create an noti->mqtt dictionary and that is, literally, all.

                      I can see that the monitor status is reported in the log, but I can’t see what ‘notification’ is sent

                      here author https://github.com/Jopyth/MMM-Remote-Control#system-control wrote that Noti USER_PRESENCE: true or USER_PRESENCE: false is issued by the MMM-Remote-Control.
                      So configure your noti dictionary with these lines and you will get mqtt as soon as the USER_PRESENCE: true\false arrive. Pay attention, that the same noti could by issued by other modules, e.g.

                      Also, you can control other modules via mqtt-noti command. Starting from hiding/showing and ending with direct control. Examples:
                      Within your smarthome ecosystem based on MQTT/HomeAssistant (HA) - a great modules are

                      • MMM-NewPIR - use your PIR sensor, integrated into MM as an instance within HA ecosystem and add it states to the scenes automation.
                      • MMM-Youtube, - send mqtt->noti to this module and control via HA scenes e.g. turn-on news on Youtube in the morning etc.
                      • MMM-Volume, set and turn-on/off the volume (e.g. during the day/night time)
                      • Google Assistant etc.

                      Also, just a hint: add to ignoreNotiSender a default “clock” module. I will add this by default to the next release. The reason: “clock” module sends notification every second. So adding “clock” to ignored list will prevent MQTTbridge from checking “clock’s” notification in dictionary every second (just to save rpi cpu usage).

                      F 1 Reply Last reply Mar 8, 2020, 12:35 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 1 / 5
                      1 / 5
                      • First post
                        9/44
                        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