Sign inSign up

tediore/audioflow2mqtt

By tediore

•Updated 3 months ago

https://github.com/Tediore/audioflow2mqtt

Image
0

2.5K

tediore/audioflow2mqtt repository overview

⁠Audioflow to MQTT Gateway

audioflow2mqtt enables local control of your Audioflow speaker switch(es) via MQTT. It supports Home Assistant MQTT discovery for easy integration. It can also automatically discover the Audioflow devices on your network via UDP discovery, or you can specify the IP address of the Audioflow devices if you don't want to use UDP discovery.


⁠Configuration

audioflow2mqtt can be configured using environment variables or by using a configuration file named config.yaml. Example config.yaml with all possible configuration options:

mqtt_host: 10.0.0.2
mqtt_port: 1883
mqtt_user: user
mqtt_password: password
mqtt_qos: 1
base_topic: audioflow2mqtt
home_assistant: True
device_ips:
- 10.0.1.100
discovery_port: 54321
log_level: debug

Configuration options (please note that the variables are lowercase if using config.yaml):

VariableDefaultRequiredDescription
MQTT_HOSTNoneTrueIP address or hostname of the MQTT broker to connect to.
MQTT_PORT1883TrueThe port the MQTT broker is bound to.
MQTT_USERNoneFalseThe user to send to the MQTT broker.
MQTT_PASSWORDNoneFalseThe password to send to the MQTT broker.
MQTT_QOS1FalseThe MQTT QoS level.
BASE_TOPICaudioflow2mqttTrueThe topic prefix to use for all payloads.
HOME_ASSISTANTTrueFalseSet to True to enable Home Assistant MQTT discovery or False to disable.
DEVICE_IPSNoneDepends*IP address(es) of your Audioflow device(s). Must be a comma-separated string (if multiple).
* Required if you don't plan to use UDP discovery.
DISCOVERY_PORT54321FalseThe port to open on the host to send/receive UDP discovery packets.
LOG_LEVELinfoFalseSet minimum log level. Valid options are debug, info, warning, and error

⁠How to run

Docker via docker-compose with config.yaml

  1. Create your docker-compose.yaml (or add to existing). Example docker-compose.yaml:
version: '3'
services:
  audioflow2mqtt:
    container_name: audioflow2mqtt
    image: tediore/audioflow2mqtt:stable
    volumes:
    - /path/to/config.yaml:/config.yaml
    restart: unless-stopped
    network_mode: host # only required if device_ips is not set in config.yaml
  1. docker-compose up -d audioflow2mqtt

Docker via docker run with config.yaml

Example docker run command:

docker run --name audioflow2mqtt \
-v /path/to/config.yaml:/config.yaml \
--network host \ # only required if device_ips is not set in config.yaml
tediore/audioflow2mqtt:stable

Docker via docker-compose without config.yaml

  1. Create your docker-compose.yaml (or add to existing). Example docker-compose.yaml with all environmental variables:
version: '3'
services:
  audioflow2mqtt:
    container_name: audioflow2mqtt
    image: tediore/audioflow2mqtt:stable
    environment:
    - MQTT_HOST=10.0.0.2
    - MQTT_PORT=1883
    - MQTT_USER=user
    - MQTT_PASSWORD=password
    - MQTT_QOS=1
    - BASE_TOPIC=audioflow2mqtt
    - HOME_ASSISTANT=True
    - DEVICE_IPS=10.0.1.100,10.0.1.101
    - DISCOVERY_PORT=54321
    - LOG_LEVEL=debug
    restart: unless-stopped
    network_mode: host # only required if DEVICE_IPS is not set
  1. docker-compose up -d audioflow2mqtt

Docker via docker run without config.yaml

Example docker run command with all environment variables:

docker run --name audioflow2mqtt \
-e MQTT_HOST=10.0.0.2 \
-e MQTT_PORT=1883 \
-e MQTT_USER=user \
-e MQTT_PASSWORD=password \
-e MQTT_QOS=1 \
-e BASE_TOPIC=audioflow2mqtt \
-e HOME_ASSISTANT=True \
-e DEVICE_IPS=10.0.1.100,10.0.1.101 \
-e LOG_LEVEL=debug \
--network host \ # only required if DEVICE_IPS is not set
tediore/audioflow2mqtt:stable

Bare metal (not recommended)

  1. Set the necessary environment variables or create config.yaml
  2. git clone https://github.com/Tediore/audioflow2mqtt
  3. cd audioflow2mqtt
  4. python3 audioflow2mqtt.py

⁠Home Assistant

audioflow2mqtt supports Home Assistant MQTT discovery which creates a Device for the Audioflow switch and entities for each zone as well as sensors for SSID, RSSI (signal strength), and Wi-Fi channel.


⁠MQTT topic structure and examples

The command topic syntax is BASE_TOPIC/serial_number/command/zone_number where BASE_TOPIC is the base topic you define, serial_number is the device serial number (found on the sticker on the bottom of the device), command is one of the below commands, and zone_number is the zone you want to control (zone A on the switch is zone number 1, zone B is zone number 2, and so on).

Valid commands are set_zone_state and set_zone_enable. The examples below assume the base topic is the default (audioflow2mqtt) and the serial number is 0123456789.

Turn zone B (zone number 2) on or off, or toggle between states

Topic: audioflow2mqtt/0123456789/set_zone_state/2

Valid payloads: on, off, toggle

Turn all zones on or off

Topic: audioflow2mqtt/0123456789/set_zone_state (note the lack of a zone number at the end of the topic)

Valid payloads: on, off

Enable or disable zone A (zone number 1) This might not really be something you would need, but I figured I'd add it anyway

Topic: audioflow2mqtt/0123456789/set_zone_enable/1

Valid payloads: 1 for enabled, 0 for disabled


When the zone state or enabled/disabled status is changed, audioflow2mqtt publishes the result to the following topics:

Zone state: audioflow2mqtt/0123456789/zone_state/ZONE

Zone enabled/disabled: audioflow2mqtt/0123456789/zone_enabled/ZONE


Network info is published to the following topics:

SSID: audioflow2mqtt/0123456789/network_info/ssid

Wi-fi channel: audioflow2mqtt/0123456789/network_info/channel

RSSI: audioflow2mqtt/0123456789/network_info/rssi


⁠Important notes

When running separate instances for multiple devices, you will need to set a different base topic for each instance. Also, while audioflow2mqtt does support UDP discovery of Audioflow devices, creating a DHCP reservation for your Audioflow device(s) and setting DEVICE_IPS is recommended. UDP discovery will only work if the Audioflow device is on the same subnet as the machine audioflow2mqtt is running on.


Buy Me A Coffee

⁠TODO

  1. Handle Audioflow device disconnects/reconnects
  2. Add support for re-discovery of Audioflow switch if its IP address changes
  3. Add support for multiple Audioflow switches? Not sure how many people would have more than one.
  4. You tell me!

Tag summary

Content type

Image

Digest

sha256:c04fe4852…

Size

354.2 MB

Last updated

3 months ago

docker pull tediore/audioflow2mqtt