MQTT integration with Hass.io

Hey everyone so i have my :particle: set up and streaming data to the console swimmingly, I’d like to integrate into my Hassio dashboard preferably using Mqtt but I’m open to any ideas for incorporation

Let me ping someone that might be able to help, @rickkas7 or @ParticleD are you able to assist?

Oh wow that is great thanks so much for the assistance :hamburger:

@KyleG’s very kind pings to @rickkas7 and @ParticleD don’t always result in any help, so I thought I’d jump in and see if I can help.

I’ve recently integrated Home Assistant and Particle and if I can help you, I will.

The only problem I’m having is the Core I’m running my MQTT server keeps flaking out. I don’t know if it’s the Core, my code, or my router - I’ve just bought a new router so we’re about to rule out one option.

Anyway - what did you want to know?

awesome thanks for the response, so im using the core mqtt broker built into Hassio, I am also running the Dallas temp sketch on my photon to send temp data to the particle console id like to add MQTT lib to my particle sketch so the data from the sensor will appear in Hassio

So if you add the @hirotakaster MQTT library to your sketch, using the library function of the online IDE (presume you’re compiling in the cloud?), you can then connect to your broker easily like so:

byte server[] = {192,168,0,110};
MQTT client(server, 1883, callback);

then you’d do publish like

client.publish("Fiservedpi/temp",YOURVARIABLE)

subscribe like

client.subscribe("Fiservedpi/temp");

void callback(char * topic, byte * payload, unsigned int length) {
        char p[length + 1];
        memcpy(p, payload, length);
        p[length] = NULL;

        if (!strcmp(p, "messageone"))
                Particle.publish("front-door-unlocked", PRIVATE);
			 
        else if (!strcmp(p, "messagetwo"))
                Particle.publish("front-door-locked", PRIVATE);
}

Only problem is stability.

Home Assistant config:

# Example configuration.yaml entry
sensor:
  - platform: mqtt
    state_topic: "Fiservedpi/temp"
2 Likes

Wonderful!! Thank you so much for the assistance really appreciate it

to manually add this library to my sketch do i just hit the + button in web ide and paste the code?

Yeah, you will need to do a bit of fine tuning to get the code working with your exact topics and setup…but the above is a massive point in the right direction.

This MQTT sketch is the best I’ve found.

1 Like

ok thanks a bunch

so heres what ive got so far

#include "DS18.h"
#include "MQTT.h"

byte server[] = {192,168,86,44};
MQTT client(server, 1883, callback);



void callback(char * topic, byte * payload, unsigned int length) {
        char p[length + 1];
        memcpy(p, payload, length);
        p[length] = NULL;

        if (!strcmp(p, "messageone"))
                Particle.publish("temperature", PRIVATE); 

Now my MQTT broker uses login where would i put that info

-u -P

would it be something like
mosquitto sub -t -uxxxxxxxxxxx -Pxxxxxxxxxxx/#