Page 1 of 1
MQTT Switch - Acknowledge?
Posted: Friday 17 February 2017 14:13
by nexustlc
Hello Guys,
I'm using last stable Domoticz Release with a Mosquitto Broker, so I'm using Virtual Sensors with "MQTT Client Gateway with LAN interface" as Hardware.
I've a fully working MQTT Switch, I'm able to switch on/off clearly; what I need to obtain is a feedback on the real switch status in order to know if switch set on/off in right way.
With MySensors Gateway Domoticz I can know when Switch is reachable or not; using MQTT how is possible to obtain the same feature?
I wish to disable switch command if MQTT device is not reachable...
How I can do it? I need an ACK with MQTT connection...how I can obatin it?
Thank you so much for support!

Re: MQTT Switch - Acknowledge?
Posted: Friday 17 February 2017 21:28
by SweetPants
nexustlc wrote:I've a fully working MQTT Switch, I'm able to switch on/off clearly; what I need to obtain is a feedback on the real switch status in order to know if switch set on/off in right way.
If you subscribe to topic 'domoticz/out' you receive the result of your command with the status of your switch
Re: MQTT Switch - Acknowledge?
Posted: Friday 17 February 2017 23:43
by Stevanovich
Hello ,
You can also use MQTTBox from chrome plugin to test publisher and subscriber domoticz/in and domoticz/out
Look in domoticz log to see what is wrong.
Best regards
Re: MQTT Switch - Acknowledge?
Posted: Saturday 18 February 2017 12:56
by nexustlc
Hello Stevanovich, Hello SweetPants,
thank you so much for your support!
Maybe I failed to explain my problem...
My Switch works well, I'm able to connect to MQTT publish/subscribe topic and to read Switch status.
What I mean is different, try to follow me:
1) Unplug switch, so it is not powered
2) Try to set ON switch via Domoticz WEB UI
3) WEB UI set ON switch and you see that switch status in ON
4) Switch real status is OFF because it's not powered!
This happens because Domotics doesn't have a feedback/ack when uses MQTT...
How I can solve this issue?
Thanks!
Re: MQTT Switch - Acknowledge?
Posted: Saturday 18 February 2017 18:50
by SweetPants
nexustlc wrote:This happens because Domotics doesn't have a feedback/ack when uses MQTT...
How I can solve this issue?
That is not so easy. Current implementation of MQTT does not support ACK and I wonder if it ever will. Also, what timeout you use to determine the switch should return an ACK? If you know your way arround in C++ you can try to implement it yourself and contribute it to the Domoticz project.
Re: MQTT Switch - Acknowledge?
Posted: Monday 20 February 2017 9:58
by nexustlc
SweetPants Thank you so much!
So it's not easy...bad news...I will try to implement it but I don't know if I've success.
About timeout, I don't think to implement a timeout but a check in command and state; if I switch in UI I will send a command to relay but I'll wait a status update from relay before update icon state in UI...what do you think?
Re: MQTT Switch - Acknowledge?
Posted: Thursday 20 April 2017 23:47
by moullas
What are you using on the ESP8266 to communicate with the MQTT broker?
If it's code you've written yourself, it should be possible to set the LWT message to be identical to let's say the Off status. This should be done when you initialize the connection to the MQTT broker from your switch.
In effect, when the broker would detect that the MQ client has disconnected, it would publish the LWT message of your MQTT switch.
That's the only way I can think of right now to work around that issue.
Re: MQTT Switch - Acknowledge?
Posted: Friday 21 April 2017 11:55
by nexustlc
Hi moullas,
thank you so much for your reply!
I've written code myself, so I can set LWT but in this way I will know only if the switch is "online/offline" but I will not have a feedback from the switch, it's right?
Re: MQTT Switch - Acknowledge?
Posted: Friday 21 April 2017 18:29
by SweetPants
nexustlc wrote:I've written code myself, so I can set LWT but in this way I will know only if the switch is "online/offline" but I will not have a feedback from the switch, it's right?
Right. LWT is used by the broker to signal that a device keep alive is not received anymore. Bare in mind, it only sends this LWT message once.
Re: MQTT Switch - Acknowledge?
Posted: Sunday 23 April 2017 7:45
by Arsenius
How about making a device lua script that triggers when you press the switch in domoticz.
Then update the code on your mqqt switch to publish on a topic the lua script waits for.
then make the lua script reset the switch in domoticz if no mqqt message is received with the topic in 10 seconds after it is triggered.
Re: MQTT Switch - Acknowledge?
Posted: Tuesday 30 May 2017 21:16
by MYLE
nexustlc wrote:Hello Guys,
I'm using last stable Domoticz Release with a Mosquitto Broker, so I'm using Virtual Sensors with "MQTT Client Gateway with LAN interface" as Hardware.
I've a fully working MQTT Switch, I'm able to switch on/off clearly; what I need to obtain is a feedback on the real switch status in order to know if switch set on/off in right way.
With MySensors Gateway Domoticz I can know when Switch is reachable or not; using MQTT how is possible to obtain the same feature?
I wish to disable switch command if MQTT device is not reachable...
How I can do it? I need an ACK with MQTT connection...how I can obatin it?
Thank you so much for support!

What about doing a ping test if not there disable it
Re: MQTT Switch - Acknowledge?
Posted: Saturday 21 October 2017 16:43
by salopette
Hello, can someone help me remove my device from domoticz?
It was a virtual switch 205, which I have from the hardware etnfertn, but it still come complaining about MQTT purely.
How can I delete this?
RFLink Detected, Version: 1.1 Revision: 48 Build: 4
2017-10-21 16:36:41.301 MQTT: Subscribed
2017-10-21 16:36:41.402 MQTT: Topic: domoticz/in, Message: {"idx": 205, "nvalue": 0, "svalue": ""}
2017-10-21 16:36:41.402 Error: MQTT: unknown idx received!
I can not find this switch nowhere!
And also other switches do not have this IDx 205
Thank you!
Re: MQTT Switch - Acknowledge?
Posted: Saturday 21 October 2017 16:43
by salopette
Hello, can someone help me remove my device from domoticz?
It was a virtual switch 205, which I have from the hardware etnfertn, but it still come complaining about MQTT purely.
How can I delete this?
RFLink Detected, Version: 1.1 Revision: 48 Build: 4
2017-10-21 16:36:41.301 MQTT: Subscribed
2017-10-21 16:36:41.402 MQTT: Topic: domoticz/in, Message: {"idx": 205, "nvalue": 0, "svalue": ""}
2017-10-21 16:36:41.402 Error: MQTT: unknown idx received!
I can not find this switch nowhere!
And also other switches do not have this IDx 205
Thank you!
Re: MQTT Switch - Acknowledge?
Posted: Saturday 21 October 2017 21:23
by SweetPants
looks like the device is removed from domoticz but something is still transmitting to topic domoticz/in to update the device via MQTT
Re: MQTT Switch - Acknowledge?
Posted: Saturday 21 October 2017 22:10
by salopette
Yeah, I think so, too. But how to remove it?
EDIT
sudo service mosquitto stop
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start
Re: MQTT Switch - Acknowledge?
Posted: Tuesday 17 April 2018 19:11
by kisse66
maybe the message was retained. You can remove a retained message from mosquitto by publishing a retained zero-length message with that topic.
E.g. mosquitto_pub -t domoticz/in -n -r
Re: MQTT Switch - Acknowledge?
Posted: Tuesday 17 April 2018 19:33
by tontze
salopette wrote: ↑Saturday 21 October 2017 22:10
Yeah, I think so, too. But how to remove it?
EDIT
sudo service mosquitto stop
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start
You have some hardware that is trying to update that switch idx. Check your hardware.
Re: MQTT Switch - Acknowledge?
Posted: Tuesday 17 April 2018 20:10
by salopette
tontze wrote: ↑Tuesday 17 April 2018 19:33
salopette wrote: ↑Saturday 21 October 2017 22:10
Yeah, I think so, too. But how to remove it?
EDIT
sudo service mosquitto stop
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start
You have some hardware that is trying to update that switch idx. Check your hardware.
No, that is not correct! These IDX do not appear anywhere.
After deleting the .db everything works!
Re: MQTT Switch - Acknowledge?
Posted: Monday 30 April 2018 22:52
by aatdeheer
Back to the original subject of this thread: Feedback
I have developed a solution, using a Domoticz virtual sensor with sensor type "text" (see settings/hardware).
In the ESP program i have added a couple of lines to send a confirmation via MQTT (subscription: Domoticz/in) that a MQTT message, eg. to switch a relay, has been received and actioned. It sends an "on" or "off" text message, which is displayed in Domoticz.
Hopefully this explains clearly how my solution works.
By the way the MQTT protocol has by design the functionality to send message acknowlegdements and "last will" messages. However, in the Arduino IDE eg the "Pubsubclient" plugin doesnot support this functionality.