Is there any way to connect Paho (or other) mqtt client to the mosquitto broker in home assistant from web server in the same local network?

Hi guys, I’m trying to connect a websocket and mqtt (JavaScript Paho mqtt client) to my Home Assistant in order to get the status of Sonoff switches, or send commands to them and show the info in my private custom built site. Is there any way to do that? I tried almost everything but I always get error like: WebSocket connection to ‘ws://192.168.1.107:8085/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED. I tried websocket ports like 9001, 9002, 8085, 8123 …Same error anytime …

EDIT:
In order to explain my pain better:
I have a web server, on a separate machine in my home network, with IP 192.168.1.111. There is a web site on it where I’ve built web interface for wireless IR Remote controls (one for each of my room) to control my TV’s, Air Conditioners and Audio Systems. I want to show the status of the light switches (Sonoff relays) connected to hass (installed on Raspberry Pi with IP 192.168.1.107). Also, if there is a possibility, to integrate html+css switch to send mqtt commands to switch them on\off. I decided to use Paho mqtt javascript in the pages for each room to make the connection and send the topics. As you can see this is where the problems started. :smiley:

The embedded MQTT broker is using 8080 as WebSocket port. Keep in mind that this broker only supports 3.1.1.

I’m still getting:
WebSocket connection to ‘ws://192.168.1.107:8080/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Do I have to do any configurations in home assistant in order to connect to it?

If the mqtt component is activated then the embedded broker will be present.

I’m using Mosquitto for mqtt if that matters … :
This is my mosquitto.conf
listener 1883
listener 1884
protocol mqtt3.1.1 // I also tried with “mqtt3.1” and “mqtt”
listener 8080
protocol websockets

The connection between your client and mosquitto is completely unaffected by HA.

From the mosquitto.conf man page

Websockets support is currently disabled by default at compile time.

So are you sure you have websockets enabled?

Really, your problem is between your client and mosquitto, so you would probably be better off asking your question on the mosquitto mailing list, rather than on the HA forum.

May depend on the used operating system. For the Fedora/CentOS package I enabled WebSocket support. Not sure how Debian/Ubuntu is doing it.

At least for my debian stretch installation, web socket support is working with mosquitto using the default package from apt.

I’m using the hassbian package …
So if I got you right, I have to disable Mosquitto and try using the internal mqtt component?

Excuse me for my dumb questions, but I’m very new in this IoT thing. I’m very excited of it and it is interesting for me. I’m playing around with it from a month and I think home assistant is great, but I don’t know many things of it. Even simple things like socket connection is starting to drive me crazy … :smiley: But I won’t give up. That’s why I’m asking for help from you guys. :slight_smile:

I think it would be nice if it is possible the Mosquito component for Home Assistant to be updated to more recent version like 1.4 or 1.5.