Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt items and discovery #829

Merged
merged 6 commits into from
Feb 12, 2021
Merged

Mqtt items and discovery #829

merged 6 commits into from
Feb 12, 2021

Conversation

DaveNeudoerffer
Copy link
Contributor

Here it is -- mqtt items and discovery.

I have just submitted a pull request that adds mqtt item support as well as mqtt discovery as defined by
Home Assistant.  Full documentation is found in mqtt_items.pm, but I summarize here.

mqtt_items.pm:

  • An mqtt item is a misterhouse object representing the mqtt device,
      managing all messages associated with that device.  
  • There are mqtt_RemoteItems for mqtt devices.  The item will receive state messages
      from the device and publish command topics to the device.  This  
      supports Tasmota, IOT4, and likely ESPurna devices
  • Also supported are mqtt_LocalItems which are linked to an existing
      misterhouse item and will publish state messages and receive command messages
      for that existing item
  • MQTT LWT messages are also supported for online/offline status as
      well as other topics such as the brightness topic for dimmable devices.  I have not yet added support for colour lights, but if someone can  point me at a good MH implementation of a light with colour, I will take a look.
  • MQTT types supported: switch, light, binary_sensor, sensor
  • .mht support for MQTT_REMOTEITEM, MQTT_LOCALITEM and MQTT_INSTMQTT
  • MQTT_REMOTEITEMS support Tasmota, IOT4, and likely ESPurna devices
  • MQTT_LOCALITEM supports almost any existing mh device that can be mapped to an MQTT type
  • MQTT_INSTMQTT supports devices published by the insteon-mqtt project
  • These are statically defined MQTT objects, and do not need discovery, but
      defining the objects statically can be tedious.  See discovery below.

mqtt_discovery.pm:

  • Discovery allows for the processing of discovery messages as published by
      mqtt devices.  Most mqtt devices have some support for discovery as
      defined by Home Assistant.  Usually it needs to be turned on on
      the device (eg. Tasmota -- setOption19 1).  
      Misterhouse items are created (mqtt_RemoteItem) for
      the discovered devices.  These items can be written to a .mht file
      so the next time misterhouse is run, they will appear as first class
      misterhouse items.    
  • This module will also publish discovery information for mqtt_LocalItems,
      allowing misterhouse items to be discovered by Home Assistant, or by another
      instance of misterhouse or anything else that can consume discovery messages.
  • I have tried this with TASMOTA and IOT4 devices, but it should work
      much more broadly.
  • .mht support for MQTT_DISCOVERY class to process discovery messages and
      MQTT_DISCOVERED_ITEM item type for discovered items written to a .mht
      file by mqtt_Discovery::write_discovered_items().
     
    mqtt.pm:
  • These new modules use the existing broker support in mqtt.pm.  
  • I have tried very hard not to break anything in the existing mqtt.pm,
      including the existing mqtt_item class, but there have been some
      bug fixes and small enhancements made to support the new functionality:
        - multiple mqtt broker support has been fixed.  The code was there,
          but it shared a receive buffer across brokers which didn't work very well :-)
        - enhanced debugging support with debug levels 1-3
        - the ability for an object to listen to a list of topics or topic patterns.
          (thanx Gilles for the topic pattern support!)
        - I had to remove Gilles' short circuit when an object was found matching
          a message topic because there are cases where multiple objects receive the
          same topic
        - optionally unloaded the set function, with the addition of a new object
          method $obj->receive_mqtt_message().  This makes the item code more understandable.
        - added methods for managing retained topics
         
    Enjoy.  Open to any and all feedback or suggestions.

@hplato
Copy link
Collaborator

hplato commented Feb 12, 2021

Thanks Dave!

@hplato hplato merged commit df14d29 into hollie:master Feb 12, 2021
@hplato hplato mentioned this pull request Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants