MQTT issues with sensors

I don’t think you can have a space in your state_topic, use an underscore ‘_’

So does this mean I will need to rename all my sensors and remove all spaces?

Not necessarily but HA will change the spaces for _ so in your state topic make it Hallway_Sensor

Would help to know which line is 55. I’m not sure the problem is the space in the state topic since thats not what the error is complaining about. Seems instead like a yaml formatting error. Did you place that dashed paragraph underneath the sensor: block, like so? Could just be an indentation problem. Should look like this:

sensor:
  - platform: mqtt
    state_topic: "smartthings/Hallway Sensor/temperature"
    name: "Hallway Temperature"
    unit_of_measurement: "°C"

I’ve added the unit of measurement parameter, without it you won’t get a nice graph showing the temperature trend but instead the number will just be treated as different states of the sensor. Try that and let me know if it works.

Excellent that’s got the sensor appearing - thanks! Unfortunately the attribute is now ‘unknown’ so doesn’t seem to pulling down the data…

Does that topic have a retained message? If not, then the sensor will need to publish data at least once after home assistant subscribes in order for HA to receive the value.

Use mosqitto_pub to publish to the topic to get something into HA or wait for the sensor to update when smartthings sends it

In another ssh window you can try subscribing to the topic to see if smartthings is sending anything

Yeah all seems to be working but HA does not update. I can publish

{
  "topic":"smartthings/Hallway Sensor/temperature",
  "payload":"18"
}

And it appears in mosquitto_pub but HA remains at ‘unknown’.

Errr yep that’s because you are using a space try _

:slight_smile:

OK can get HA to manually populate the atttribute. Will see if MQTT can publish any data as the other sensors I have are all ‘unknown’ and my switch is assumed to be ‘off’ so no data either.

Man this is frustrating!

From the research I’ve been doing a space is valid, but you need to know exactly what the topic is that smartthings is publishing to because /Hallway Sensor/ is not the same as /hallway sensor/

Mmm this is my mosquitto log

0|smartthi | info: Incoming message from SmartThings: smartthings/Xmas tree/switch = on
0|smartthi | info: Incoming message from MQTT: smartthings/Xmas tree/switch = on
0|smartthi | info: Skipping duplicate message from: smartthings/Xmas tree/switch = on
0|smartthi | info: Incoming message from MQTT: smartthings/Hallway Sensor/temperature = 18
0|smartthi | info: Skipping duplicate message from: smartthings/Hallway Sensor/temperature = 18

So it’s definitely seeing the data, just HA never populates with anything from MQTT unless I manually populate from HA direct.

Can you rename the sensor in smartthings to Hallway_Sensor just to see if it is the space that’s causing a problem?

No difference. Everything is logging as OK just HA never updates auotmatically :frowning:

Can you paste all of the sensor file please?

OK I think it’s now working. I am getting temperature reported in HA. Thanks for your help.

How do you go the other way? I want to send data from HA to ST, its not clear how you can do that.

I have an mqtt sign, so to publish data to it I use an automation…

 - alias: MQTT Sign Startup
   initial_state: 'on'
   trigger:
     - platform: mqtt
       topic: stat/MQTTSign/STARTUP  
   action:
     - service: mqtt.publish
       data_template:
         topic: "cmnd/MQTTSign/PLANT"
         payload: 'No plant needs attention'

So when the sign publishes that it’s started up (it has to get the time first) I publish all my data to it, this is just a small example I publish lots to it.

The sign subscribes to the topic /cmnd/MQTTSign/PLANT plus a load of others to get my data and display it :slight_smile:

OK that’s cool, but if the device is only ‘seen’ in HA (there is no plugin for ST) is there a way to publish that to MQTT and then somehow added into ST?

I don’t have ST so have no idea, best to ask in the ST forum, or maybe someone around here can help :slight_smile:

Edit:

and I think there maybe a HA MQTT bridge to ST, have a search on this forum.

This might help