MQTT: Working Mosquitto / CloudMQTT Bridge

HI @vageesh79,
did you install owntracks in HA too?
After subscribing to all MQTT-topics via “topic # in” and restarting HA, my devices showed up.

I have owntracks in configured in device_tracker.yaml file.

- platform: owntracks
  max_gps_accuracy: 75
  waypoints: yes

and my cloudmqtt.conf look like this -

connection cloudmqtt
address m11.cloudmqtt.com:1111
remote_username xxx
remote_password xxx
clientid xxx
try_private false
start_type automatic
topic # in

and i am getting requests from owntrack from android with this command -

mosquitto_sub -h m11.cloudmqtt.com -p xxx -u xxx -P xxx -t ‘#’ -v

On HA i have configured sensor for battery as -

- platform: mqtt
  state_topic: 'owntracks/xxxh/Nx'
  name: Battery N4
  unit_of_measurement: "%"
  value_template: '{{ value_json.batt }}' 

but no value. I can see the value if run from ssh.

I have local broker also and is working fine… so i bridged cloudmqtt.conf. Am i missing something

I finally got this working after following this post and some others. There are a few things that need to be done for it to work end-to-end.

  1. In /etc/mosquitto/mosquitto.conf file add

include_dir /etc/mosquitto/conf.d

  1. in /etc/mosquitto/conf.d directory create a file as per the OP

connection cloudmqtt
address <host:port>
remote_username <>
remote_password <>
clientid <>
try_private false
start_type automatic
topic # in

  1. Your device_tracker config should look like his

device_tracker:

  • platform: mqtt
    devices:
    paulus_oneplus: /location/paulus
    annetherese_n4: /location/annetherese

from: MQTT device tracker - Home Assistant

What I also did was to create a bridge on cloudmqtt to my local mosquitto install.

First I created a new user in mosquitto by doing

sudo mosquitto_passwd /etc/mosquitto/pwfile username

Go to the Cloudmqtt console and create a bridge to your local mosquitto.

url: mqtt://USER:PASSWORD@host:port
Direction: out
Local Prefix: owntracks/#
Remote Prefix: owntracks/#

Obviously I had to portforward in the router to the local mosquitto port.

Hope this helps

Mukund

1 Like

You can create bridge on your local MQTT Server and you do bot need port forwarding for it. Connection initiator will be local MQTT server not CloudMQTT

1 Like

Didn’t work for me, so I did the other way. I’ll try disabling the bridge from cloudmqtt and see if the connections stay.

If you don’t configure bridge on local MQTT connection wil be lost.
Here is my config for brdging mosquitto with cloudmqtt

connection couldmqtt
  address <your cloudmqtt account>
  topic # in 1
  try_private true
  notifications false
  start_type automatic
  remote_clientid <your client id>
  remote_username <your user name>
  remote_password <your password>
  keepalive_interval 300
  cleansession true
  bridge_protocol_version mqttv311
  local_clientid hass
  bridge_cafile /etc/ssl/certs/ca-certificates.crt
  bridge_insecure false
3 Likes

@sffjunkie
Confirmed working with below.

1 Like

I wonder where is the certificate coming from. Is this something that can be downloaded from the cloudmqtt website? It’s from your own environment (meaning your own cert)?

I gave this a couple of tries but I can make it work.

The cert is not created or added by you.

I think it’s installed as part of HA…

Just looked at mine and it is dated 2/2/2017

Can you please share your /etc/mosquitto/mosquitto.conf file?

Cant get it to work. Keep getting the following

Connecting bridge cloudmqtt (instance.cloudmqtt.com:port)
1493539560: Connecting bridge cloudmqtt (instance.cloudmqtt.com:port)
1493539560: Bridge mosquitto-cloudmqtt-bridge sending CONNECT
1493539561: Socket error on client cloudmqtt, disconnecting.

ok, confirmed working with SSL port.

This is list of root CA’s. It’s a part of OS. It’s required to verify CouldMQTT cert which presented during connection establishment.

Now something else is wrong with my config.
Since getting this working I’ve pointed my device_tracker config to mqtt. Now the status doesn’t seem to be getting updated.

Instead i get the raw JSON as the state of the devices.

my MQTT settings are as below. Can you please tell me what i’m doing wrong?

mqtt:
broker: 127.0.0.1
port: 1883
client_id: home-assistant-1
username: pi
password: !env_var password_mqtt
discovery: true
protocol: 3.1
keepalive: 60

this is now fixed. All i had to do was change the device tracker to cloudmqtt platform.

Do you mean setting the platform to owntracks because I’m getting errors when using cloudmqtt as platform.

Yes, sorry. That’s what i meant.

platform: owntracks

Cloudmqtt in a broker. It receives a store messages from your owntracks app.

Thanks!
Although my ha location does not seem to update when using the local mosquitto mqtt(I’ve set up the bridge to cloudmqtt) server. I’m not getting any errors but it just doesn’t update.
My in my configuration.yaml I have:

mqtt:
  broker: 127.0.0.1
  port: 1883
  client_id: home-assistant-1
  username: mosquitto user name
  password: mosquitto password
  discovery: true
  keepalive: 60

And also:

device_tracker:
  - platform: owntracks
    max_gps_accuracy: 75

Then I have to following text in the cloudmqtt.conf file under /etc/mosquitto/conf.d:

connection couldmqtt
  address my cloudmqtt serveradress:my cloudmqtt SSL port
  topic # in
  try_private true
  notifications false
  start_type automatic
  remote_clientid ha
  remote_username cloudmqtt username
  remote_password cloudmqtt password
  keepalive_interval 300
  cleansession true
  bridge_protocol_version mqttv311
  local_clientid hass
  bridge_cafile /etc/ssl/certs/ca-certificates.crt
  bridge_insecure false

Does anyone know what I’m doing wrong?

How is your owntracks configured?