Skip to main content

This project is a multi-system and multi-OS adaptation of mac2mqtt. It allows you to execute any command on your system, providing endless possibilities for automation and control.

Project description

Computer2Mqtt

This project is a multi-system and multi-OS adaptation of mac2mqtt. It allows you to execute any command on your system, providing endless possibilities for automation and control.

Requirements

This assumes you have direnv and uv installed

Simply run direnv allow to setup the environment, you can read the contents of .envrc to see what it does behind the scenes.

Setup

  1. Clone this repository to your local machine.
  2. Run direnv allow in the project directory. This will set up the Python environment using pyenv.
  3. Create a computer2mqtt.yaml by copying computer2mqtt-example.yaml configuration file in the project root. There are 2 important sections first the mqtt config, and second the commands you want to run. In the example below these are commands for macs to turn on/off the display. This should be changed to commands for your target system. Possibility is endless.
mqtt:
  ip: 192.168.1.100
  port: 1883
  user: username
  password: password


commands:
  # Example mac command to wake/sleep display
  displaysleep: "pmset displaysleepnow"
  displaywake: "caffeinate -u -t 1"
  1. Run c2m and note down the Sanitized hostname: Mac-mini, Mac-mini in this case.
  2. Set up Home Assistant Scripts to trigger commands. Here is an example from my scripts.yaml file in Home Assistant
macmini_displaysleep:
  alias: Mac Mini Display Sleep
  icon: mdi:laptop
  sequence:
    - service: mqtt.publish
      data:
        topic: "mac2mqtt/{device_name}/command/displaysleep"
        payload: "displaysleep"

macmini_displaywake:
  alias: Mac Mini Display Wake
  icon: mdi:laptop
  sequence:
    - service: mqtt.publish
      data:
        topic: "mac2mqtt/{device_name}/command/displaywake"
        payload: "displaywake"

Replace {device_name} with the name of your device from the previous step!

Running in the background

To run the script in the background, you can use the screen command. screen is a full-screen window manager that multiplexes a physical terminal between several processes.

  1. Start a new screen session with name of your choice with the command screen -S {mysession}.
  2. Run the script with the command c2m.
  3. Detach from the screen session with the command Ctrl-a d.
  4. You can reattach to the session at any time with the command screen -r {mysession}. This will keep the script running in the background, even if you close the terminal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

computer2mqtt-0.1.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

computer2mqtt-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file computer2mqtt-0.1.0.tar.gz.

File metadata

  • Download URL: computer2mqtt-0.1.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for computer2mqtt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94bac2109c7506ff8cdf11c88e4602aa05605abf3ad3d2cadef7c534fca702a4
MD5 99dbfd96c5a6a5f31bfbe268d495a63e
BLAKE2b-256 816ac8aa61498a53deecc9bce5bc483c40859980c28f16b49cb7228971741deb

See more details on using hashes here.

File details

Details for the file computer2mqtt-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for computer2mqtt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75a17eea06f92ff438b88af519fdd30fdd41b1f2fe183879ea7d575ff60b4126
MD5 e42d301bd15f0d7b3cdf7f4952ba42d6
BLAKE2b-256 e97effeb1dff67bf43a0b5c1fa95fb5b8691f16a7de1fe7ece3795cf80c3b5f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page