Finding mqtt topic

just looking for a reason why its not functioning

If I toggle the relay locally it moves the switch button on the HA gui, pity it wont work the other way
tnx
Richard

Because youā€™ve specified either the wrong command_topic or payload_on.

Iā€™ve checked with info given on the iot4.eu website and the state and command topics are the
same

- platform: mqtt
  name: "LED"
  state_topic: "/iot4/switch/LED/relay/0"
  command_topic: "/iot4/switch/LED/relay/0"
  payload_on: "1"
  payload_off: "0"
#IOT4SH02BLINDER mqtt control topic
- platform: mqtt
  name: "Fel"
  state_topic: "/iot4/IOT4SH02_BLINDER_828D81/relay/0"
  command_topic: "/iot4/IOT4SH02_BLINDER_828D81/relay/0"
  payload_on: "1"
  payload_off: "0"

I tried the line with LED in and that didnā€™t function
I have

switch:
  - platform: tplink
    host: 192.168.1.83
    name: LR Lamp
  - platform: mqtt
    host: 192.168.1.109
    name: PIG
    state_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    command_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    payload_on: "1"
    payload_off: "0"

the website says

In the state_topic filed insert the root topic which you set, the end tag in the :

state_topic: "/iot4/switch/IOT4SH01DS_122F85/temperature"

IOT4SH01DS is /temperature
IOT4SH01RELAY is /relay/0
IOT4SH01BME is /pressure for the pressure sensor data
IOT4SH01BME is /humidity for the humidity sensor data
IOT4SH01BME is /temperature for the temperature sensor data
IOT4SH01BMP is /pressure for the pressure sensor data
IOT4SH01BMP is /temperature for the temperature sensor data

not sure what else ?
Richard

Hmmmā€¦:thinking:

interestingly, we had a substantively the same interaction in a thread when you first joined in November on this exact topic. And in that thread you eventually managed to figure out how to do it right. but now suddenly you donā€™t know how to post correctly and get ā€œhacked offā€ and say thereā€™s nothing you can do about it when people tell you you need to learn to do it so that it helps us to help you?

here is that thread to help jog your memory:

and I canā€™t tell you how many times Iā€™ve posted this gif in other threads but in case you havenā€™t seen it here it is again. Hopefully it gives you some help in figuring it out (againā€¦):

not sure what you are getting at ??/

NOWHERE on the box at the start does it say to use ```
and my previous posts were on the sensor.

whty not be constructive ???
Richard

I am being constructive. Iā€™m telling you that there are many times that we wonā€™t be able to help you if you donā€™t post your code correctly. Either that or we will have to work harder to both figure out your code the way that it is while also trying to decipher your improperly formatted code so we can try to figure out what you are doing in the first place.

Iā€™m trying to help to help you

Yes, your previous thread was on a sensor but we had the same (similarā€¦) discussion about the importance of posting code properly and how to do it. Thatā€™s why itā€™s relevant here. And in that thread you figured out how to do it.

So I can only assume at this point you are just willfully not wanting to do it correctly. so you will be the one that might not get the help you need because most people wonā€™t want to take the time to try to decipher your code especially if it isnā€™t properly posted just because you wonā€™t do it.

EDIT to add: if you click the links contained in the blue box above it actually does contain the information about the three back ticks. just an FYI.

If you want our assistance, youā€™re going to have to follow through on our requests and suggestions. For example, when I stated that host: is an invalid option for an MQTT switch, I expected you to remove it. Yet in your previous post I still see it shown in the switchā€™s configuration:

switch:
  - platform: tplink
    host: 192.168.1.83
    name: LR Lamp
  - platform: mqtt
    host: 192.168.1.109 # <---- NO! This is an invalid option.
    name: PIG
    state_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    command_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    payload_on: "1"
    payload_off: "0"

Examples like the one above give me no confidence that anything we are suggesting is actually being applied. As a consequence, it make me lose interest in continuing to provide assistance.

I just looked at the siteā€™s instructions and the suggestion to set command_topic and state_topic to the same topic is, to put it politely, sloppy.

It implies the device has no means of reporting its status so the suggested solution is to make the controlling device (Home Assistant) ā€˜listen to itselfā€™. Whatever command Home Assistant transmits is echoed back to itself by the broker and not the relay.

Thereā€™s already a way to handle devices that do not report their status and thatā€™s by using optimistic: true and excluding the state_topic.

Anyway, what you need to do is confirm that publishing a 1 or 0 to /iot4/IOT4SH01RELAY_D341D/relay/0 can turn it on and off. Go to Home Assistantā€™s MQTT page and enter the relayā€™s topic and set the payload to 1. Click PUBLISH and see if it turns on the relay.

Screenshot%20from%202019-04-03%2013-36-52

If that fails then the possibilities are the relay:

  • is not connected to the broker
  • is not listening to payloads from topic /iot4/IOT4SH01RELAY_D341D/relay/0
  • is expecting a different payload than 1
  • is defective

To solve the problem, work your way down through that list of possibilities.

Sorry 123 , I did nā€™t read properly the note on the host option.
publishing from the gui did not change the switch state

1554313453: Received PUBLISH from home-assistant (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (1 bytes))
1554313453: Sending PUBLISH to home-assistant (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (1 bytes))
1554313453: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (1 bytes)
``
deleting the host:entry and restarting the server
same result 

1554313806: Received PUBLISH from home-assistant (d0, q0, r0, m0, ā€˜/iot4/switch/IOT4SH01RELAY_D341D/relay/0ā€™, ā€¦ (1 bytes))
1554313806: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, ā€˜/iot4/switch/IOT4SH01RELAY_D341D/relay/0ā€™, ā€¦ (1 bytes))
1554313806: Sending PUBLISH to home-assistant (d0, q0, r0, m0, ā€˜/iot4/switch/IOT4SH01RELAY_D341D/relay/0ā€™, ā€¦ (1 bytes))
``
changing the payload to ON & OFF

1554314130: Received PUBLISH from home-assistant (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (3 bytes))
1554314130: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (3 bytes))
1554314130: Sending PUBLISH to home-assistant (d0, q0, r0, m0, '/iot4/switch/IOT4SH01RELAY_D341D/relay/0', ... (3 bytes))

there is a delay of about 6 seconds bewteen receiving and sending
my config is now

switch:
  - platform: tplink
    host: 192.168.1.83
    name: LR Lamp
  - platform: mqtt
    name: PIG
#    state_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    command_topic: "/iot4/switch/IOT4SH01RELAY_D341D/relay/0"
    payload_on: "1"
    payload_off: "0"
    optimistic: true

the root topic on the mqtt setting on the device are

/iot4/switch/{identifier} Hostname IOT4SH01RELAY_D341D

Iā€™ve tried from The HA publish sending 1,0, ON, OFF, 0x01, 0x00 just incase it would accept a hex number
the log shows its now stopped sending back to homeassistant when switched from the over view switch, but not from publishing a packet
Iā€™ve also tried publishing ā€œ2ā€ which on his other units just quickly toggle back to the original state.
the relay must be connected to the broker as as change of relay state is sent to HA and it is shown on the HA gui.
Iā€™m not sure of anything else I can put as a payload , open to suggestions.
Defective ??? , I can ask for fresh software as there is a facility to update.
What I dont understand is the time delay from mosquitto receiving published data and
publishing data.
The delay works both ways , infact longer 10secs plue from locally toggling the relay
and mosquitto showing a recieved publish from the relay, it shows no delay publishing to HA
Richard

I have a question for you regarding these messages:

1554314130: Received PUBLISH from home-assistant 
1554314130: Sending PUBLISH to mosqsub|2122-odroid 
1554314130: Sending PUBLISH to home-assistant 

The broker receive the published payload from home-assistant then sent it to two subscribers:

  1. mosqsub|2122-odroid
  2. home-assistant

What is mosqsub|2122-odroid? Is that how the relay device identifies itself to the broker? Or is it something else?

The temperature sensor identified itself as esp8266a03625. I need to know what name the relay device uses.

Its not come from the relay
Its something within mosquitto, this version of mosquitto is
mosquitto version 1.4.15 (build date Wed, 13 Feb 2019 00:27:01 +0000)

At least it wasnā€™t Friday 13th
It seems to be an intermediate server within mosquitto.
I think the main version of mosquitto is around 1.5 , github says 1.5.8
so that must be a ubuntu build
Iā€™m running linux mint 19.1 on this laptop and the current version here is 1.4.15 and thatā€™s ubuntu 18.04 build.
It looks to be a security fix for password problems where any malformed password was acceptedā€¦
sorry I dont know any more than that
Richard

any device called ā€˜odroidā€™ wouldnā€™t be something internal in normal mosquittoā€¦there is no ā€œintermediate server within mosquittoā€

Based on the brokerā€™s log, it would appear the relay device is either:

  • not connected to the broker
  • not subscribed to any topics

If it was connected and subscribed to a topic, the broker would be sending it payloads via the subscribed topic ā€¦ but the log shows no record of that happening. The relay deviceā€™s name isnā€™t listed in the log.

ā€¦ or its name is mosqsub|2122-odroid (but I have my doubts) and isnā€™t responding to the received payloads.

Anyway, thereā€™s more here than meets the eye. MQTT problems really arenā€™t that difficult to debug so I canā€™t help but feel thereā€™s missing information.

Do you have any other software to monitor MQTT such as MQTTFx or MQTT Explorer? If you donā€™t I recommend getting either if those (MQTT Explorer would be the preferred). Even if they donā€™t help you here and now they are a great troubleshooting tool for things MQTT related.

Iā€™m pretty sure from your logs posted that the payload should be 0 & 1 for off & on. With an MQTT sniffer/client I think you will be more able to easily prove that.

Is there a way to modify the topics so that you have a separate command and state topic or, since you mentioned being able to get updated firmware, can you put any third party firmware on the device such as Tasmota or ESPHome?

From reading all of this I really think that the lack of a separate state and command topic is the cause of all your woes now.

(homeassistant) odroid@odroid:~/.homeassistant$ sudo netstat -tpan | grep mosquitto
[sudo] password for odroid: 
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      1971/mosquitto      
tcp        0      0 192.168.1.82:1883       192.168.1.82:39988      ESTABLISHED 1971/mosquitto      
tcp        0      0 192.168.1.82:1883       192.168.1.110:13993     ESTABLISHED 1971/mosquitto      
tcp        0      0 192.168.1.82:1883       192.168.1.109:9207      ESTABLISHED 1971/mosquitto      
tcp        0      0 192.168.1.82:1883       192.168.1.82:55867      ESTABLISHED 1971/mosquitto      
tcp        0      0 192.168.1.82:39988      192.168.1.82:1883       ESTABLISHED 2122/mosquitto_sub  
tcp6       0      0 :::1883                 :::*                    LISTEN      1971/mosquitto      

192.168.1.109 is the relay
here a bit from the mosquitto log:-

1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/app', ... (4 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/app', ... (4 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/version', ... (5 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/version', ... (5 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/host', ... (3 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/host', ... (3 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/ip', ... (13 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/ip', ... (13 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/mac', ... (17 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/mac', ... (17 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/rssi', ... (3 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/rssi', ... (3 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/uptime', ... (4 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/uptime', ... (4 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/freeheap', ... (5 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/freeheap', ... (5 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/relay/0', ... (1 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/relay/0', ... (1 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/vcc', ... (4 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/vcc', ... (4 bytes))
1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/status', ... (1 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/status', ... (1 bytes))
1554324219: Received PINGREQ from esp8266d341de
1554324219: Sending PINGRESP to esp8266d341de
1554324220: Received PINGREQ from mosqsub|2122-odroid
1554324220: Sending PINGRESP to mosqsub|2122-odroid
1554324220: Received PINGREQ from esp8266a03625
1554324220: Sending PINGRESP to esp8266a03625

esp8266d341de is the relay
so its connected and mosquitto is getting packets from it, its just not sending packets to it

Richard

OK.

Weā€™re now 35 posts into this long-winded thread so why are we now seeing new information like this? This is the first time weā€™re seeing the topic PIG/relay/0.

1554324212: Received PUBLISH from esp8266d341de (d0, q0, r1, m0, 'PIG/relay/0', ... (1 bytes))
1554324212: Sending PUBLISH to mosqsub|2122-odroid (d0, q0, r0, m0, 'PIG/relay/0', ... (1 bytes))

Whatā€™s that all about?

Finity
no way of getting at the devices as the whole thing is potted
The upgrade function seems to be something built in to the s/w in it

when a packet is published by HA it get published by mosquitto to mosqsub
when a packet is published by the relay ( PIG) mosquitto publishes to mosqsub
Its like it decided to use a DMZ or something similar.
Iā€™'l down load MQTT explorer and see if anything shows up, hope it runs in linux , its a MS free zone here
Richard

Once you get MQTT Explorer running connect to your broker and subscribe to all topics (#). Then we can go on from there.

:man_facepalming:

Youā€™re running it on an Odroidā€¦as user odroidā€¦so

IS your Home Assistant server

I have been following along trying to figure out a lot of thingsā€¦

dont think so as this is the homeassistant server

1554325261: Received PUBLISH from home-assistant (d0, q0, r0, m0, 'PIG/relay/0', ... (1 bytes))

You literally just showed you running a command prompt ON an ODROID as the ODROID userā€¦that you are running home assistant on.