mqtt2cmd

command module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

MQTT to command-line applications gateway

Release Software license Build status

Create virtual MQTT switches from command-line applications. Expose apps running locally on your laptop or desktop to your home automation server, like Home Assistant.

Installation

MacOS

# Add tap to your Homebrew
brew tap haimgel/tools

# Install it
brew install mqtt2cmd

# Configure (see below for details)
mkdir -p ~/Library/Application\ Support/mqtt2cmd
vi ~/Library/Application\ Support/mqtt2cmd/config.yaml

# Run it in the background, autostart upon boot
brew services start mqtt2cmd

# View the logs
tail -f ~/Library/Application\ Support/mqtt2cmd/mqtt2cmd.log

Configuration

This application expects a configuration file named config.yaml, located in:

  • $HOME/Library/Application Support/mqtt2cmd on MacOS
  • $XDG_CONFIG_HOME/mqtt2cmd or $HOME/.config/mqtt2cmd on Linux

Sample configuration (controls Slack status across multiple Slack workspaces using slack-status)

# Application ID is the prefix for all MQTT topics this app subscribes and publishes to. Defaults to mqtt2cmd
app-id: 'laptop'
mqtt:
  broker: "tcp://your-mqtt-server-address:1883"
switches:
  - name: lunch
    # How often to run the `get_state` command and update the state: useful if the state changes by means
    # other than this application
    refresh: "10m"
    # A command to turn the switch on
    turn_on: "/opt/homebrew/bin/slack-status set lunch"
    # A command to turn the switch off
    turn_off: "/opt/homebrew/bin/slack-status clear"
    # A command to query the state of the switch: exit status = 0 is "ON", exit status = 1 is "OFF"
    get_state: "/opt/homebrew/bin/slack-status -u myteam get lunch"

Using the configuration above, mqtt2cmd will:

  1. Subscribe to MQTT topic laptop/switches/lunch/set
  2. Publish the current state to laptop/switches/lunch
  3. Publish overall application availability to laptop/available
  4. Publish switch availability to laptop/switches/lunch/available (will be marked offline if the commands could not be executed successfully).

Sample Home Assistant configuration

Assuming mqtt2cmd is configured as above, the following Home Assistant configuration will allow to control the virtual "switch" and expose its status and availability.

mqtt:
  switch:
    - name: "Slack 'Lunch' status"
      icon: 'mdi:hamburger'
      state_topic: 'laptop/switches/lunch'
      command_topic: 'laptop/switches/lunch/set'
      availability:
        - topic: 'laptop/available'
        - topic: 'laptop/switches/lunch/available'
      availability_mode: 'all'

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL