Skip to main content

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 computer2mqtt 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 computer2mqtt.
  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.

Metadata

Release files for computer2mqtt 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for computer2mqtt 0.1.2
File Size Uploaded Provenance
computer2mqtt-0.1.2.tar.gz 29.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for computer2mqtt 0.1.2
File Interpreter ABI Platform
computer2mqtt-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 33.5 kB

Release files / computer2mqtt-0.1.2.tar.gz

Download URL computer2mqtt-0.1.2.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
af1f664761a047564379d28cb62bf4b100718043b79b7f222a1f18acb5257f40
BLAKE2b-256 checksum
How to use checksums
5b158ac8f6a89e9a8182858dbb571b1d819522859c96f1762138fa0f0376b003
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / computer2mqtt-0.1.2-py3-none-any.whl

Download URL computer2mqtt-0.1.2-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39f06e1cb3bcad69554284e477fb15154e9e61f045ea0acdb1ee0ac3497a00a0
BLAKE2b-256 checksum
How to use checksums
97da980eb610a797965b4977271d02eca96b19687894c7c1e54996e30e4b7999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for computer2mqtt 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page