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

Battery "fetch-device-info" with docker-compose #50

Closed
matt8707 opened this issue Oct 18, 2021 · 6 comments
Closed

Battery "fetch-device-info" with docker-compose #50

matt8707 opened this issue Oct 18, 2021 · 6 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@matt8707
Copy link

Continuing #41 (comment)

I'm unsure how to pass the --fetch-device-info command-line option in docker-compose

I've tried variations of command: --fetch-device-info and passing it along a mqtt payload

@fphammerle
Copy link
Owner

would that work?

command: >-
  switchbot-mqtt --mqtt-host "$MQTT_HOST" --mqtt-port "$MQTT_PORT"
  --mqtt-username "$MQTT_USERNAME" --mqtt-password "$MQTT_PASSWORD"
  --fetch-device-info

I should add support for setting that flag via an environment variable

@fphammerle fphammerle added the enhancement New feature or request label Oct 18, 2021
@matt8707
Copy link
Author

That passes and an environment variable would be neat.

docker logs switchbot-mqtt
"In docker-based setups, you could use sudo docker run --cap-drop ALL --cap-add NET_ADMIN --user 0 … (seriously insecure)."

Just to make sure, I have to run it insecure if I want battery-percentage?

Working compose file:

version: '3'
services:
  switchbot-mqtt:
    image: fphammerle/switchbot-mqtt:2.0.0-armv7
    container_name: switchbot-mqtt
    restart: always
    network_mode: host
    userns_mode: host
    cap_add:
      - NET_ADMIN
    cap_drop:
      - ALL
    user: '0'
    command: >
      switchbot-mqtt
        --mqtt-host "$MQTT_HOST"
        --mqtt-port "$MQTT_PORT"
        --fetch-device-info

Also why is battery-percentage published to "cover" for switches?

@fphammerle
Copy link
Owner

Just to make sure, I have to run it insecure if I want battery-percentage?

Unfortunately, yes. On Linux the NET_ADMIN capability is required to retrieve battery percentage via bluetooth low-energy.

Also why is battery-percentage published to "cover" for switches?

Thanks! That should not be the case. I'll fix that in an upcoming release.

@fphammerle
Copy link
Owner

Could you retry with v2.1.0?

The new release fixes the battery topic for button automators (old kept for compatibility).

Additionally, you can now enable --fetch-device-info by setting env var FETCH_DEVICE_INFO to some non-empty value.
No need to change command anymore.

@matt8707
Copy link
Author

That was fast! Yes, that works 👍🏻

screen

  switchbot-mqtt:
    image: fphammerle/switchbot-mqtt:2.1.0-armv7
    container_name: switchbot-mqtt
    restart: always
    network_mode: host
    userns_mode: host
    cap_add:
      - NET_ADMIN
    cap_drop:
      - ALL
    user: '0'
    environment:
      - MQTT_HOST=${MQTT_HOST}
      - MQTT_PORT=${MQTT_PORT}
      - FETCH_DEVICE_INFO=yes

@fphammerle
Copy link
Owner

Great! Thanks for testing! :)

I'll remove that misleading cover/switchbot/*/battery-percentage topic in the next major release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants