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

Enhancement request: QOS setting in the NOTI->MQTT #2

Closed fribse closed 1 year ago

fribse commented 4 years ago

Hi guys

I still beleive this is the absolute BEST integration out there for MQTT, the others provided are way too narrow, this is done 'the right way'. One thing that I'm missing seems to be a way to set QOS for the MQTT messages. The QOS can be 0, 1 or 2, and describes how much a guarantee there is for the message to be delivered.

sergge1 commented 4 years ago

@fribse

I still beleive this is the absolute BEST integration out there for MQTT, the others provided are way too narrow, this is done 'the right way'. One thing that I'm missing seems to be a way to set QOS for the MQTT messages. The QOS can be 0, 1 or 2, and describes how much a guarantee there is for the message to be delivered.

This should be set for each message In Dictionary or as one setting in config? I suppose one setting in config would be better.

fribse commented 4 years ago

Well, it is usually settable per message type, as it's different what kind of priority the messages get. But I don't think it matters that much.

sergge1 commented 4 years ago

@fribse could you share your notiDict and mqttDict that you are using while integrating it to HA with mmm-remotecontrol? I would add it as an example here

fribse commented 4 years ago

Yes of course. I'm not really clear in my head (suffering from Covid-19), so please bear with me, if I'm doing it wrong. But a lot of work went into this, and you are a gem for helping me out with the syntax corrections, so of course I will help out with some working example.

First of the config.js part:

    {
      module: 'MMM-Remote-Control',
      config: {
        showModuleApiMenu: true,
      }
    },
    {
      module: 'MMM-MQTTbridge',
      disabled: false,
      config: {
        mqttServer: 'mqtt://mqttuser:mqttpassword@mqtthost:1883',
        mqttConfig:
        {
          listenMqtt: true,
          interval: 2000,
        },
        notiConfig:
        {
          listenNoti: true,
          ignoreNotiId: ['CLOCK_MINUTE', 'NEWS_FEED'],
          ignoreNotiSender: ['clock','newsfeed','currentweather','calendar']
        }
      }
    }

Then the mqttDictionary.js

var mqttHook = [
    {
      mqttTopic: "cmnd/bathroom/mirror",
      mqttPayload: [
        {
          payloadValue: "MONITOROFF",
          mqttNotiCmd: ["MONITOROFF"]
        },
        {
          payloadValue: "MONITORON",
          mqttNotiCmd: ["MONITORON"]
        },
        {
          payloadValue: "UNDIM",
          mqttNotiCmd: ["UNDIM"]
        },
        {
          payloadValue: "DIM",
          mqttNotiCmd: ["DIM"]
        },
      ],
    },
  ];

var mqttNotiCommands = [
    {
      commandId: "MONITOROFF",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: 'MONITOROFF'}
    },
    {
      commandId: "MONITORON",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: 'MONITORON'}
    },
    {
      commandId: "DIM",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: 'BRIGHTNESS', value: '50'}
    },
    {
      commandId: "UNDIM",
      notiID: 'REMOTE_ACTION',
      notiPayload: {action: 'BRIGHTNESS', value: '255'}
    },
  ];

module.exports = { mqttHook,  mqttNotiCommands};

Then there is the notiDictionary.js

var notiHook = [
  {
    notiId: "USER_PRESENCE",
    notiPayload: [
      {
        payloadValue: '1',
        notiMqttCmd: ["SCREENON"]
      },
      {
        payloadValue: '0',
        notiMqttCmd: ["SCREENOFF"]
      }
    ]
  }
];
var notiMqttCommands = [
  {
    commandId: "SCREENOFF",
    mqttTopic: "state/bathroom/mirror/monitor",
    mqttMsgPayload: "OFF"
  },
  {
    commandId: "SCREENON",
    mqttTopic: "state/bathroom/mirror/monitor",
    mqttMsgPayload: "ON"
  }
];

module.exports = { notiHook, notiMqttCommands };

In Home Assistant I've built a sensor and a switch. The binary sensor reflects the state of the mirror, and the switch turns the monitor on/off

binary_sensor:
  - platform: mqtt
    name: "MagicMirror Bathroom"
    state_topic: 'state/bathroom/mirror/monitor'
    device_class: window

The switch uses two images to show the state of it.

switches:
  - platform: template
    switches:
      magicmirror_bathroom:
        friendly_name: "Magicmirror"
        value_template: "{{ is_state('binary_sensor.magicmirror_bathroom', 'on') }}"
        turn_on:
          service: mqtt.publish
          data:
            topic: "cmnd/bathroom/mirror"
            payload: "MONITORON"
        turn_off:
          service: mqtt.publish
          data:
            topic: "cmnd/bathroom/mirror"
            payload: "MONITOROFF"
        entity_picture_template: >-
          {% if is_state('binary_sensor.magicmirror_bathroom', 'on') %}
            /local/images/mirror_on.png
          {% else %}
            /local/images/mirror_off.png
          {% endif %}

The images are placed in \config\www\images

mirror_off mirror_on

Tom-Hirschberger commented 1 year ago

Hi, i took over the ownership of the module and started with a new version today. The new version will support:

Tom-Hirschberger commented 1 year ago

As of version 2.0.0 of the module QoS, retain flags (and many more things) are supported now. Please see the release notes for details.