MQTT Help needed getting started

I’m new to HA, so please explain in detail if you can :slight_smile:

I’m running on an RPi3, as I don’t need anything fancy.

It was easy to setup my Switchbot temperature sensors and put them on a graph. Now I want to get MQTT data onto a similar graph.

I’ve installed the MQTT addon, and used the test buttons on it to subscribe to a topic, and to publish data on that topic. ( The topic name is SummerHouse )

This ‘SummerHouse’ topic will eventually receive data from a remote Arduino or similar, and will contain just a number in the range 0 to 100, sent once per minute.

I want to plot these numbers in a statistics graph.

How do I get topic data into a graph ?.

You have two options,

  1. Publish discovery data as well as sensor data from your Arduino. This will automatically set up the sensor.

or

  1. Only publish the sensor data and create the mqtt sensor manually in YAML.

Both methods are outlined here with examples at the bottom of the page:

Hi,

The key is to tell HA what the units are for the sensor, otherwise long term statistics may not plot a graph (as it doesn’t know what the value represents - even just a “number”).

I’d use the search on this forum as there are many posts about developing using MQTT including…

If this helps, :heart: this post!

Maybe I need to explain my immediate requirement a little better.

The MQTT integration has test buttons for ‘Listen’ and ‘Publish’. If I set a topic name in both, and some number as the payload, then each time I press ‘Publish’ a message appears in the ‘Listen’ area showing the time of the message, the topic, and the payload value.

I’ve put some YAML in which I thought should create a sensor to access this topic, which would then let me use the payload in a graph.

mqtt:
sensor:
- name: “SHv1”
state_topic: “home/SummerHouse”

I can then find ‘sensor.shv1’ in the entity list, but it doesn’t appear as a source for a graph, and the ‘History’ display just shows ‘Unknown’.

It looks like I need more YAML to give HA instructions how to interpret this sensor.
Where do I find the relevant stuff ?

Eventually the topic will receive values from a microcontroller, maybe Arduino, which I will deal with later. First, I want to get the HA end working.

As I posted above, you need to set the units and potentially the device class of the sensor to get long term statistics to log and graph them.

In the link I posted above.

1 Like

I think I’ve found the source of the problem, just now need to find out how to fix it.

This YAML … [ EDIT: added code fences ]

mqtt:
  sensor:
    - name: "SHv1"
      state_topic: "home/SummerHouse"
      state_class: "measurement"

… does create a sensor, with the Entity_ID ‘sensor.shv1’, and this sensor now appears as available for graphing.

But the graph shows empty, no data points. I think the answer is on this page …

… somewhere !

Can I also suggest adding “code fences” (three back ticks before and after code) as the result is a lot more readable…

mqtt:
  sensor:
  - name: “SHv1”
    state_topic: “home/SummerHouse”
    state_class: “measurement”

Sorry, I didn’t wait long enough.

The update interval on the graph is 5 minutes, so nothing shows until the interval ends.

Now I’ve got the HA end of this working, next step is to build the microcontroller for the remote end.

1 Like

I’ve started getting the microcontroller working !.

Its sending MQTT to HA over WiFi once a minute reliably, updating the sensor, and plotting a graph.

Now I don’t need a notification every time HA receives a message, it just clogs the logs.

How do I turn off notifications from MQTT ?