MQTT Switch - Acknowledge?

Everything about esp8266 and more.
Post Reply
nexustlc
Posts: 4
Joined: Friday 17 February 2017 13:33
Target OS: Linux
Domoticz version:
Contact:

MQTT Switch - Acknowledge?

Post by nexustlc » Friday 17 February 2017 15:13

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
Posts: 2351
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10215
Location: The Netherlands
Contact:

Re: MQTT Switch - Acknowledge?

Post by SweetPants » Friday 17 February 2017 22:28

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
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Stevanovich
Posts: 12
Joined: Saturday 30 January 2016 14:24
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by Stevanovich » Saturday 18 February 2017 0:43

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 13:33
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by nexustlc » Saturday 18 February 2017 13:56

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
Posts: 2351
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10215
Location: The Netherlands
Contact:

Re: MQTT Switch - Acknowledge?

Post by SweetPants » Saturday 18 February 2017 19:50

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.
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

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

Re: MQTT Switch - Acknowledge?

Post by nexustlc » Monday 20 February 2017 10:58

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
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by moullas » Thursday 20 April 2017 23:47

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 13:33
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by nexustlc » Friday 21 April 2017 11:55

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
Posts: 2351
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10215
Location: The Netherlands
Contact:

Re: MQTT Switch - Acknowledge?

Post by SweetPants » Friday 21 April 2017 18:29

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.
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Arsenius
Posts: 9
Joined: Thursday 23 April 2015 7:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by Arsenius » Sunday 23 April 2017 7:45

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: 23
Joined: Monday 10 April 2017 8:29
Target OS: Linux
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by MYLE » Tuesday 30 May 2017 21:16

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: 46
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post by salopette » Saturday 21 October 2017 16:43

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: 46
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post by salopette » Saturday 21 October 2017 16:43

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
Posts: 2351
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10215
Location: The Netherlands
Contact:

Re: MQTT Switch - Acknowledge?

Post by SweetPants » Saturday 21 October 2017 21:23

looks like the device is removed from domoticz but something is still transmitting to topic domoticz/in to update the device via MQTT
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

salopette
Posts: 46
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post by salopette » 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

kisse66
Posts: 12
Joined: Sunday 01 April 2018 10:13
Target OS: Raspberry Pi
Domoticz version: v3.9268
Location: Finland
Contact:

Re: MQTT Switch - Acknowledge?

Post by kisse66 » Tuesday 17 April 2018 19:11

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: 335
Joined: Thursday 12 January 2017 16:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by tontze » 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.
-----------------------------------------
Rpi 3 / Razberry 2
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
ESP82xx

salopette
Posts: 46
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: MQTT Switch - Acknowledge?

Post by salopette » Tuesday 17 April 2018 20:10

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
Domoticz version:
Contact:

Re: MQTT Switch - Acknowledge?

Post by aatdeheer » Monday 30 April 2018 22:52

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 2 guests