raspbian mosquitto mqtt setup and tasmota

this was working as of 2020-05-23

apt update
apt install -y mosquitto mosquitto-clients
sudo systemctl enable mosquitto.service

Test the system to ensure it’s working. Start terminal windows…

term 1 – subscriber to the topic “test”

mosquitto_sub -t "test"

term 2 – publish something to the topic “test”

mosquitto_pub -m "message from mosquitto_pub client" -t "test"

Create a user/password

sudo mosquitto_passwd -c /etc/mosquitto/passwd username
Password: password

edit the file as root, /etc/mosquitto/conf.d/default.conf:

allow_anonymous false
password_file /etc/mosquitto/passwd

Restart

sudo systemctl restart mosquitto

test pub/sub in two terminals.

term-1 $> mosquitto_sub -t "test" -u "username" -P "password"
term-2 $> mosquitto_pub -t "test" -u "username" -P "password" -m "message from mosquitto_pub client"

That’s the setup of MQTT

Tasmota portion:

Tasmota is another beast… it wasn’t readily appearant to me when I was looking at the docs.

Tasmota 8.3.1

Enable MQTT support in tasmota:

  1. Configuration -> Configure Other -> click MQTT Enable
  2. Configuration -> Configuration MQTT
  3. Host: the ip of the mqtt server
  4. Port: should be 1833, unless you overrode it in the config.
  5. Client leave as is.
  6. User: the user you created for MQTT
  7. Password: same password as you created earlier.
  8. Topic: this should be unique for this device
  9. Full Topic: %prefix%/%topic%/

Now, it wasn’t immediate appearant to me, what the mqtt topics where:

To turn on/off my device,

topic: "cmnd/aquriumlight/POWER"
payload: "on" / "off"

Groups are possible, the default group is “tasmotas”. The example below would turn on/off all devices listening to tasmotas.

topic: "cmnd/tasmotas/POWER"
payload: "on" / "off"

The device can be part of multiple groups:

issue the command in the console:

grouptopic
23:17:18 MQT: stat/aquariumlight/RESULT = {"GroupTopic1":"tasmotas","GroupTopic2":"","GroupTopic3":"","GroupTopic4":""}

GroupTopic1 is tasmotas, and topics 2-4 are empty.

to change that, in the console:

GroupTopic2 LivingRoom

sending a message to topic: “cmd/LivingRoom/Power” “off” would shut down all devices in LivingRoom.

to upgrade all devices (dangerous)

cmnd/tasmotas/upgrade

After you got the first tasmota devices setup, subsequent devices will be easy with mqtt.

MQTT Explorer

Using MQTT Explorer, it’s a GUI that will allow you easily send and view messages on the queue/topics. I recommend you check them out.

Connect to your mqtt server with the appropriate credentials.

Try out a few things:

EXMAPLE: Set your timezone on all devices to eastern daylight savings time. (GMT-4)
TOPIC: cmnd/tasmotas/timezone
PAYLOAD: -4

EXAMPLE: Set your timezone, and location on all devices to pacific, and location is Googleplex. (GMT-7)
TOPIC: cmnd/tasmotas/Backlog
PAYLOAD: timezone -7; latitude 37.422; longitude -122.084



Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *