MQTT Switch - Acknowledge?

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
nexustlc
Posts: 4
Joined: Friday 17 February 2017 12:33
Target OS: Linux
Domoticz version:
Contact:

MQTT Switch - Acknowledge?

Post 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! ;)
SweetPants

Re: MQTT Switch - Acknowledge?

Post 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
Stevanovich
Posts: 12
Joined: Saturday 30 January 2016 13:24
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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
nexustlc
Posts: 4
Joined: Friday 17 February 2017 12:33
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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!
SweetPants

Re: MQTT Switch - Acknowledge?

Post 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.
nexustlc
Posts: 4
Joined: Friday 17 February 2017 12:33
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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?
moullas
Posts: 1
Joined: Thursday 20 April 2017 23:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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.
nexustlc
Posts: 4
Joined: Friday 17 February 2017 12:33
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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?
SweetPants

Re: MQTT Switch - Acknowledge?

Post 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.
Arsenius
Posts: 8
Joined: Thursday 23 April 2015 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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.
MYLE
Posts: 20
Joined: Monday 10 April 2017 8:29
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post 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!
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post 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!
SweetPants

Re: MQTT Switch - Acknowledge?

Post 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
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post 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
kisse66
Posts: 5
Joined: Sunday 01 April 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.9268
Location: Finland
Contact:

Re: MQTT Switch - Acknowledge?

Post 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
tontze
Posts: 317
Joined: Thursday 12 January 2017 15:30
Target OS: Linux
Domoticz version: Beta Ch
Location: Finland
Contact:

Re: MQTT Switch - Acknowledge?

Post 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.
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post 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!
aatdeheer
Posts: 1
Joined: Sunday 06 September 2015 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest