Finding mqtt topic

Apologies, its over a year since I set up HA and getting old the memory is more volotile than it used to be.
How do I find the mqtt topic I have a IOT4H01RELAY
its set up to use the default mqtt port , the HA and mosquitto server are on the same machine running ubuntu18.04,. not using hass.io
the relay address on my network is 192.168.1.109 and the mqtt and HA server are on 192.168.1.82.
If I can find the exact topic name , I should be able to blunder my way through configuration.yaml.
I just need to get the switch up on the HA app at the moment

thanks
Richard

The config of the IOT4H01RELAY should have that, but if not… install an MQTT client of your choice (MQTT Spy or other), and then subscribe to #

Then you’ll see every message received by the broker scroll by.

Thanks I found on the config of the switch
But my sddition to the sonfiguration.yaml is accepted , when I test the config, turning the switch on/off from HA is not working, I can turn the switch on/off on its config page.
Reading what being sent to mqtt at the switch with telnet , I get this with toggling the switch
<[WEBSOCKET] Requested action: relay
[RELAY] #0 scheduled ON in 0 ms
[RELAY] #0 set to ON
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/relay/0 => 1 (PID 1)
[RELAY] Saving mask: 1
[WEBSOCKET] Requested action: relay
[RELAY] #0 scheduled OFF in 0 ms
[RELAY] #0 set to OFF
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/relay/0 => 0 (PID 1)
[RELAY] Saving mask: 0
[MAIN] Time: 2019/04/02 19:50:32
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/app => IOT4 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/version => 1.9.7 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/host => IOT4SH01RELAY_D341D (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/ip => 192.168.1.109 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/mac => 18:FE:34:D3:41:DE (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/rssi => -73 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/uptime => 600 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/freeheap => 24744 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/relay/0 => 0 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/vcc => 3183 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/status => 1 (PID 1)
/>
I see nothing when I toogle from HA
the section in configuration.yaml is
<switch:

  • platform: tplink
    host: 192.168.1.83
    name: LR Lamp
  • platform: mqtt
    host: 192.168.1.109
    name: IOT4-Switch
    state_topic: “/iot4/IOT4SH01RELAY_D34ID”
    command_topic: “/iot4/IOT4SH01RELAY_D34ID/set”
    availabilty_topic: “/iot4/IOT4SH01RELAY_D34ID/available”
    payload_on: “ON”
    payload_off: “OFF”
    state_on: “ON”
    state_off: “OFF”
    optomistic: false
    qos: 0
    retain: true
    />
    Sorry old problem the block formatting doesn’t work for some reason

any suggestions please
Richard

The configuration of your MQTT Switch is incorrect.

For starters, there’s no host option for an MQTT Switch. The connection between Home Assistant and the MQTT Broker is configured in a separate section.

The log indicates the device publishes its status to this topic: /iot4/IOT4SH01RELAY_D341D/status
However, you’ve configured the MQTT Switch to subscribe to this topic:
state_topic: "/iot4/IOT4SH01RELAY_D34ID"

I may be wrong but it appears the log indicates the payloads the device uses to indicate on and off are 1 and 0, respectively. Therefore state_on: and state_off: ought to be changed accordingly.

Based on the log, I can’t be certain what payloads the device expects to receive to turn it on or off. It may be ON and OFF or 1 and 0. Whichever is the correct combination must be specified in payload_on: and payload_off. If the device expects ON/OFF then your configuration has it right.

I tried that , with no effect, but I seeing something strange watching the log file on the relay
I restarted mosquitto
and I’m seeing this
<
MQTT] TCP Disconnected
[MQTT] Disconnected!
[MQTT] Connecting to broker at 192.168.1.82:1883
[MQTT] Will topic: /iot4/IOT4SH01RELAY_D341D/status
[MQTT] QoS: 0
[MQTT] Retain flag: 1
[MQTT] TCP Disconnected
[MQTT] Disconnected!
[MQTT] Connecting to broker at 192.168.1.82:1883
[MQTT] Will topic: /iot4/IOT4SH01RELAY_D341D/status
[MQTT] QoS: 0
[MQTT] Retain flag: 1
[MQTT] TCP Disconnected
[MQTT] Disconnected!
[MQTT] Connecting to broker at 192.168.1.82:1883
[MQTT] Will topic: /iot4/IOT4SH01RELAY_D341D/status
[MQTT] QoS: 0
[MQTT] Retain flag: 1
[MQTT] TCP Disconnected
[MQTT] Disconnected!
[MQTT] Connecting to broker at 192.168.1.82:1883
[MQTT] Will topic: /iot4/IOT4SH01RELAY_D341D/status
[MQTT] QoS: 0
[MQTT] Retain flag: 1
[MQTT] TCP Disconnected
[MQTT] Disconnected!
/>
I found this site and I’ve altered the config and still nothing
https://www.iot4.eu/wiki/index.php/Home_assistant

Without seeing what you tried, I can’t comment on it or provide additional assistance.

As for the log, it’s very clear the device is having trouble maintaining a stable connection with the broker.

Hi
I rebooted and the relay now says it connected and it is sending to the mqtt broker
Its sending this every 5 mins
<
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/app => IOT4 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/version => 1.9.7 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/host => IOT4SH01RELAY_D341D (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/ip => 192.168.1.109 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/mac => 18:FE:34:D3:41:DE (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/rssi => -74 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/uptime => 6000 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/freeheap => 21840 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/relay/0 => 0 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/vcc => 3184 (PID 1)
[MQTT] Sending /iot4/IOT4SH01RELAY_D341D/status => 1 (PID 1)
/>
I dont think HA is talking to the broker, but it does with the iot4 sensor
my config file is
<
#IOT4SH01DS temperature MQTT topic
sensor:

  • platform: moon

  • platform: mqtt
    state_topic: “/iot4/IOT4SH01DS_A03625/temperature”
    name: “Hot Water Temp”
    unit_of_measurement: “C”

  • platform: darksky
    api_key: !secret darksky_api_key
    units: auto
    update_interval: ‘00:15’
    monitored_conditions:

    • summary
    • precip_type
    • precip_probability
    • temperature
    • humidity
    • precip_intensity
    • wind_speed
    • pressure
    • wind_bearing
    • cloud_cover

state_topic: “/iot4/IOT4SH01DS_A03625/temperature”

Switches

switch:

  • platform: tplink
    host: 192.168.1.83
    name: LR Lamp
  • platform: mqtt
    host: 192.168.1.109
    name: IOT4-Relay
    state_topic: “/iot4/IOT4SH01RELAY-D341D/relay/0”
    command_topic: “/iot4/IOT4SH01RELAY-D341D/relay/0”
    payload_on: “1”
    payload_off: “0”
    state_on: “1”
    state_off: “0”
    />
    the mosquitto log shows very little, just the local connection from HA
    just not passing dat to the relay
    TIA
    Richard

It’s highly unlikely the same topic can be used for both state_topic and command_topic.

Where’s your configuration for mqtt:? It should look something like this:

mqtt:
  broker: 192.168.1.82 # <--- or whatever is the IP address of your MQTT Broker
  # next 3 lines are optional and assume the broker requires a login account
  client_id: 'hass'
  username: 'homeassistant'
  password: 'whatever'

It might be helpful to subscribe to the topic. You probably already have it installed.

mosquitto_sub -v -h broker_ip -p 1883 -t '#'

Hi
I’ve enabled full logging on mosquitto
and toggling the relay from HA does this , its also talking to the temperature sensor
<
1554234091: Received PINGREQ from esp8266d341de
1554234091: Sending PINGRESP to esp8266d341de
1554234102: Received PINGREQ from esp8266a03625
1554234102: Sending PINGRESP to esp8266a03625
1554234112: Received PINGREQ from esp8266d341de
1554234112: Sending PINGRESP to esp8266d341de
1554234116: Received PUBLISH from esp8266a03625 (d0, q0, r1, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554234116: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554234123: Received PINGREQ from esp8266a03625
1554234123: Sending PINGRESP to esp8266a03625
1554234132: Received PINGREQ from home-assistant-1
1554234132: Sending PINGRESP to home-assistant-1
1554234133: Received PINGREQ from esp8266d341de
1554234133: Sending PINGRESP to esp8266d341de
1554234134: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))
1554234134: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))
1554234139: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))
1554234139: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))
1554234144: Received PINGREQ from esp8266a03625
/. sorry its line wrapping

the broker entry in config is
<
qtt:
broker: 192.168.1.82
port: 1883
client_id: home-assistant-1
keepalive: 60
username: None
password: None
/>
the output of mosquitto_sub
<
/iot4/IOT4SH01RELAY_D341D/rssi -75
/iot4/IOT4SH01RELAY_D341D/uptime 7800
/iot4/IOT4SH01RELAY_D341D/freeheap 21848
/iot4/IOT4SH01RELAY_D341D/relay/0 0
/iot4/IOT4SH01RELAY_D341D/vcc 3183
/iot4/IOT4SH01RELAY_D341D/status 1
/iot4/IOT4SH01RELAY_D34ID/set ON
/iot4/IOT4SH01RELAY_D34ID/relay/set 1
/iot4/IOT4SH01RELAY_D34IDE/relay/set 1
/iot4/IOT4SH01DS_A03625/app IOT4
/iot4/IOT4SH01DS_A03625/version 1.9.7
/iot4/IOT4SH01DS_A03625/host IOT4SH01DS_A03625
/iot4/IOT4SH01DS_A03625/ip 192.168.1.110
/iot4/IOT4SH01DS_A03625/mac 68:C6:3A:A0:36:25
/iot4/IOT4SH01DS_A03625/rssi -56
/iot4/IOT4SH01DS_A03625/uptime 10388734
/iot4/IOT4SH01DS_A03625/freeheap 24688
/iot4/IOT4SH01DS_A03625/vcc 3394
/iot4/IOT4SH01DS_A03625/status 1
/iot4/IOT4SH01DS_A03625/temperature 46.7
/iot4/switch/IOT4SH01RELAY-D341D/relay/0 0
/iot4/switch/IOT4SH01RELAY-D341D/relay/0 1
/iot4/IOT4SH01DS_A03625/temperature 46.7
/iot4/switch/IOT4SH01RELAY-D341D/relay/0 0
/iot4/switch/IOT4SH01RELAY-D341D/relay/0 1
/iot4/switch/IOT4SH01RELAY-D341D/relay/0 0
/>
you can see I toggled the relay/switch
but nothing happened on the switch log
richard

the “m” in mqtt is there is was me copying and pasting
sorry

The following log entry represents a smooth transaction. The temperature sensor publishes a payload to the broker and the broker forwards it to Home Assistant.

1554234116: Received PUBLISH from esp8266a03625 (d0, q0, r1, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554234116: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))

This next one is messed up, probably because the same topic is used for command_topic and state_topic. Home Assistant publishes a payload to the broker (via command_topic) and the broker forwards it to Home Assistant (via state_topic).

1554234134: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))
1554234134: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY-D341D/relay/0’, … (1 bytes))

You know this relay device better than I do so you need to identify the topic it uses for receiving commands (use that for command_topic) and the topic it uses to report its current state (use that for state_topic).

OK
I can see the point
from the moquitto log toggling the relay with the direct relay control , not HA
<
1554236592: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236592: Sending PUBLISH to mosqsub|1991-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236593: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236593: Sending PUBLISH to mosqsub|1991-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236595: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236595: Sending PUBLISH to mosqsub|1991-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236596: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236596: Sending PUBLISH to mosqsub|1991-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554236597: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
On the link from the manufacturer , he uses the same for command and state, but on the sensor only the state
hashing out the command_state
gives this
<
554237243: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554237243: Sending PUBLISH to mosqsub|1991-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
/>

toggling the relay from HA
<
/iot4/IOT4SH01RELAY_D341D/relay/0 1
/iot4/IOT4SH01RELAY_D341D/relay/0 1
/iot4/IOT4SH01RELAY_D341D/relay/0 1
/iot4/IOT4SH01RELAY_D341D/relay/0 1
/iot4/IOT4SH01RELAY_D341D/relay/0 1
/>
that looks like it sjust telling it to turn on and on and on, just sending a “1”

or am I misreading it

Still getting no where with this
if I toggle the relay from the web interface
I get this in the mosquitto log
<
1554291436: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291436: Sending PUBLISH to mosqsub|8448-odroid (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291436: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
Preformatted text/>
received from the relay passed in mosquitto to mosqsub|8448-odroid
then passed to homeassistant
if I toggle from HA which still doesn’t work, this :-

1554291692: Received PUBLISH from home-assistant (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291692: Sending PUBLISH to mosqsub|8448-odroid (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291692: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
/>
is this problem with mosquitto ?
I’ve followed the manufacturers instructions
It seems data sent via mosquitto to HA works OK as can be seen from the temp sensor
<
1554291952: Received PUBLISH from esp8266a03625 (d0, q0, r1, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554291952: Sending PUBLISH to mosqsub|8448-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554291952: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
/>
But data sent from HA goes to the intermediate moqsub|8448-odroid
but then gets sent back to HA
I dont have any other devices that use mqtt to test
my mosquitto version is
mosquitto version 1.4.15 (build date Wed, 13 Feb 2019 00:27:01 +0000)
.I’m going around in circles here
Richard.

one other thing is that you really need to get into the habit of formatting logs and code properly when posting here. it gets very difficult to read a wall of logs and code and it just makes it that much more complicated when you also need to try to decipher the bad formatting.

it would help if it formatted the same as other sites.
this site will not format for me been here before.
not my fault !!!
All other sites you click on </> and type/paste in between ,NOT THIS ONE.
makes me very hacked off when people complain, and nothing I can do about it
Richard

Put three consecutive backticks (```) on their own line before and after the text to be formatted.

Easy-peasy:

1554291952: Received PUBLISH from esp8266a03625 (d0, q0, r1, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554291952: Sending PUBLISH to mosqsub|8448-odroid (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554291952: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ‘/iot4/IOT4SH01DS_A03625/temperature’, … (4 bytes))
1554291692: Received PUBLISH from home-assistant (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291692: Sending PUBLISH to mosqsub|8448-odroid (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))
1554291692: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ‘/iot4/switch/IOT4SH01RELAY_D341D/relay/0’, … (1 bytes))

That’s all part of markdown which is used by this site and all others based on the Discourse software.

What a pity that cant be marked at the top , instead of putting something which doesn’t work

:slight_smile:
I can see why its called discourse s/w
Richard

I’ve installed HA on the laptop , but mosquitto it not installed , and the terminal hass --open-ui
is running in is say connected to mqtt server.
Has HA got a built in mqtt server ? and is that on port 1883
If so I have two brokers running on the same port

You stated Home Assistants configuration for mqtt is as follows:

mqtt:
  broker: 192.168.1.82
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: None
  password: None

Therefore it’s connecting to the MQTT Broker on 192.168.1.82.

If you have multiple MQTT Brokers in operation, obviously Home Assistant and your temperature sensor and relay device all need to use the same broker.