Metadata-Version: 2.1
Name: mqtt-presence-checker
Version: 0.1.18
Summary: Check if you (or your phone) is at home and notify your smarthome via mqtt!
Author: RincewindWizzard
Author-email: git@magierdinge.de
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Provides-Extra: docs
Requires-Dist: asyncio-mqtt (>=0.13.0,<0.14.0)
Requires-Dist: docstring-parser (>=0.15,<0.16)
Requires-Dist: dotwiz (>=0.4.0,<0.5.0)
Requires-Dist: jsonargparse (>=4.15.1,<5.0.0)
Requires-Dist: loguru (>=0.6.0,<0.7.0)
Requires-Dist: pingparsing (>=1.4.0,<2.0.0)
Requires-Dist: pytest (>=7.1.3,<8.0.0)
Requires-Dist: python-daemon (>=2.3.1,<3.0.0)
Requires-Dist: sphinx (>=5.3.0,<6.0.0); extra == "docs"
Requires-Dist: sphinx-rtd-theme (>=1.0.0,<2.0.0); extra == "docs"
Requires-Dist: sphinxcontrib-napoleon (>=0.7,<0.8); extra == "docs"
Requires-Dist: toml (>=0.10.2,<0.11.0)
Description-Content-Type: text/markdown

# mqtt-presence-checker

Check if you (or your phone) is at home and notify your smarthome via mqtt.
You can configure this daemon via a toml file in _/etc/mqtt-presence-checker/mqtt-presence-checker.conf_.

/etc/mqtt-presence-checker/mqtt-presence-checker.conf:

    [main]
    cooldown = 10
    log = "/var/log/mqtt-presence-checker.log"

    [mqtt]
    host = "mqtt.example.org"
    username = "<username>"
    password = "<password>"
    topic = "presence-checker/presence"
    
    [mqtt.sensor.door-sensor]
    topic = "zigbee2mqtt/door_sensor"
    predicate = "lambda x: not x['contact']"

    [ping]
    hosts = [
        'alice.example.org',
        'bob.example.org'
    ]

This is rather rudimentary and might crash or behave strange. Feel free
to [fork me on github](https://github.com/RincewindWizzard/mqtt-presence-checker) and send a PR if you find any bug!

## Install with docker

Run with docker:

    docker run \
        --cap-add net_raw \
        --cap-add net_admin \
        --name mqtt-presence-checker  \
        --restart unless-stopped \
        -v /etc/mqtt-presence-checker/:/etc/mqtt-presence-checker/ \
        --label io.containers.autoupdate=registry \
        -d docker.io/rincewindwizzard/mqtt-presence-checker:latest

You can also configure systemd to create the containers using

    $ podman generate systemd --restart-policy=always --new -n -t 1 mqtt-presence-checker > /etc/systemd/system/container-mqtt-presence-checker.service
    $ systemctl enable container-mqtt-presence-checker.service

Which results in the following systemd unit:

    # container-mqtt-presence-checker.service
    # autogenerated by Podman 3.4.4
    # Sat Oct 29 17:08:56 UTC 2022
    
    [Unit]
    Description=Podman container-mqtt-presence-checker.service
    Documentation=man:podman-generate-systemd(1)
    Wants=network-online.target
    After=network-online.target
    RequiresMountsFor=%t/containers
    
    [Service]
    Environment=PODMAN_SYSTEMD_UNIT=%n
    Restart=always
    TimeoutStopSec=61
    ExecStartPre=/bin/rm -f %t/%n.ctr-id
    ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --rm --sdnotify=conmon --replace --cap-add net_raw --cap-add net_admin --name mqtt-presence-checker -v /etc/mqtt-presence-checker/:/etc/mqtt-presence-checker/ --label io.containers.autoupdate=registry -d docker.io/rincewindwizzard/mqtt-presence-checker:latest
    ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
    ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
    Type=notify
    NotifyAccess=all
    
    [Install]
    WantedBy=default.target

Now everytime

    $ podman auto-update

is called, the latest container image is redeployed.

