Getting started with MQTT

Hi all,

I’m trying to get the hang of MQTT but whatever information I come across always seems to be missing something so I’m hoping you guys can enlighten me.

I’m trying to use this:

https://github.com/thejeffreystone/alpha_vantage_to_mqtt

to publish Stock Prices to CloudMQTT and then add the sensors in Home Assistant.

The actual instructions to configure the publishing script seem fine, and I think I did everything right and I can see a connection to CloudMQTT.

I then added CloudMQTT to integrations in my Home Assistant and it shows as connected.

Then, I added the sensor in my configuration.yaml

sensor:

  • platform: mqtt
    name: “Aviva PLC”
    state_topic: “stock/AV.L/price”

This just gives me a sensor with value ‘unknown’

What am I doing wrong? I think I’d prefer to run an MQTT broker locally (I have mosquitto running alongside one of my Home Assistant instances), but I can’t seem to configure it ie. setting up of username/password/port.

Any help would be appreciated.

Edit: When viewing the CloudMQTT logs, I can see:

2019-05-30 10:56:07: Saving in-memory database to /var/lib/mosquitto/12829/db

So if I’m seeing it right, the script I have running is publishing results to MQTT, but I can’t seem to get at them.

Try to use an MQTT client connected to CloudMQTT and see what are the messages and if they are the same as the topic you have declared in the sensor

Hi, thanks for the tip. I’ve connected a client to the MQTT service, but I’m not seeing any messages, which leads me to believe they’re not being published.

Does anyone have any experience with this script:

https://github.com/thejeffreystone/alpha_vantage_to_mqtt

because I suppose this is where it’s going wrong. It’s odd though, because I set the update interval to 30 minutes and I’m getting a log entry every 30 minutes to confirm data being written.

Any other ideas?

I’m sorry, but I don’t have experience with CloudMQTT neither with the script.

Have checked if there is any other custom components that tracks stocks?

I’ve actually got a stocks tracker working, but then it runs directly in Home Assistant, which is a bit flakey.

I sortof thought I’d make the foray into MQTT because I need to understand it sooner or later for more complicated tasks.

I’ve found enough to give me a very broad understanding of MQTT and what it can do, but the finer details seem to be either missing or not explained properly. Can you perhaps point me in the direction of useful guides for understanding MQTT better and setting it up?

maybe you can try to use Node Red and manage tasks starting from the HA entity. then you can add more complexity…

Try this tutorial
https://www.hivemq.com/blog/how-to-get-started-with-mqtt/

2 Likes