Tom-Hirschberger / MMM-MQTTbridge

Module allows users to use your MagicMirror as an MQTT device within their MQTT smart home
MIT License
24 stars 5 forks source link

Problem with sending notifications #1

Closed fribse closed 4 years ago

fribse commented 4 years ago

Hi @sergge1 I think it is a better place to solve this, instead of the magic mirror forum.

Ok, I tried putting some 'notifications' in the 'schedule' mode about turning the screen on and off (just to test), and that worked perfectly. So the notification module is working.

    {
      module: 'MMM-ModuleScheduler',
      config: {
        notification_schedule: [
          // TURN THE MONITOR/SCREEN ON AT 07:30 EVERY DAY
          {notification: 'REMOTE_ACTION', schedule: '57 8 * * *', payload: {action: "MONITORON"}},
          // TURN THE MONITOR/SCREEN OFF AT 22:30 EVERY DAY
          {notification: 'REMOTE_ACTION', schedule: '55 8 * * *', payload: {action: "MONITOROFF"}},
          // RESTART THE MAGICMIRROR PROCESS AT 2am EVERY SUNDAY
          {notification: 'REMOTE_ACTION', schedule: '0 2 * * SUN', payload: {action: "RESTART"}},
        ],
      },
    },

I have rewritten the entire config, just to make sure that there are no misspellings.

I've also modified the MQTT subscription string to be shorter, just to be on the safe side. From the config.js:

    {
      module: 'MMM-MQTTbridge',
      disabled: false,
      config: {
        mqttServer: "mqtt://username:password@homeassistant:1883",
        mqttConfig:
        {
          listenMqtt: true,
          useMqttBridgeFromatOnly: false,
          interval: 300000,
          topicSubscr: ["cmnd/bathroom/mirror"],
        },
        notiConfig:
        {
          listenNoti: false,
          useMqttBridgeFromatOnly: false,
          ignoreNotiId: ["CLOCK_MINUTE", "NEWS_FEED"],
          ignoreNotiSender: ["system", "NEWS_FEED"],
        },
        // set "NOTIFICATIONS -> MQTT" dictionary at /dict/notiDictionary.js
        // set "MQTT -> NOTIFICATIONS" dictionary at /dict/mqttDictionary.js
      },
    },

Now, I can see the commands in the log:

0|mm  | [09:14:20.135] [LOG]
0|mm  | [09:14:30.592] [LOG]
0|mm  | [MQTT bridge] MQTT message received. Topic: cmnd/bathroom/mirror, message: MONITOROFF
0|mm  | [09:14:30.596] [LOG]
0|mm  | [MQTT bridge] MQTT message received. Topic: cmnd/bathroom/mirror, message: MONITOROFF
0|mm  | [09:14:31.108] [LOG]
0|mm  | state 0x6 [DVI DMT (57) RGB full 16:10], 1680x1050 @ 60.00Hz, progressive

But nothing happens. This is the mqttdictionary.js

/**  mqtt-to-notification                     **/
/**  dictionaty                               **/
/**  for MMM-MQTTbridge module                **/
/**  modify comands                           **/
/**         @sergge1                          **/

var mqttHook = [
    {
      mqttPayload: "TURN_OFF_SCREEN",
      mqttNotiCmd: ["MONITOROFF"]
    },
    {
      mqttPayload: "TURN_ON_SCREEN",
      mqttNotiCmd: ["MONITORON"]
    },
    {
      mqttPayload: "UNDIM_SCREEN",
      mqttNotiCmd: ["UNDIM"]
    },
    {
      mqttPayload: "DIM_SCREEN",
      mqttNotiCmd: ["DIM"]
    },
    {
      mqttPayload: "RESTART",
      mqttNotiCmd: ["RESTART"]
    },
    {
      mqttPayload: "MONITORSTATUS",
      mqttNotiCmd: ["MONITORSTATUS"]
    },
 ];
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: '50'}
    },
    {
      commandId: "RESTART",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: "RESTART"}
    },
    {
      commandId: "MONITORSTATUS",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: "MONITORSTATUS"}
    },
  ];

  module.exports = { mqttHook,  mqttNotiCommands};

I tried making the notiID and notiPayload as alike as the scheduler with ' and " to make sure that wasn't the problem.

So what I can see. The notification module works. The MQTT module receives the command.

So for me it looks like one of two things: a) The mqttdictionary.js doesn't translate it properly or b) The notification sending uses the wrong format

fribse commented 4 years ago

OH my god, I just found out what I was doing wrong!

I am sending MONITOROFF to MQTT, and not TURN_OFF_SCREEN

It's working perfectly!