<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic.]]></title><description><![CDATA[<p dir="auto">Essentially right now, if i turn on a light/fan/binary/etc. over MQTT by using my in topic, it does what it is supposed to. But there is no output on the out topic to confirm to the Home Automation controller, (Home Assistant in this case), that the state was changed. I have to use optimistic mode, which does not help me if i want to know if the equipment is on/off.  So after receive of a change via MQTT, send a update of the current status on the out topic.</p>
]]></description><link>https://forum.mysensors.org/topic/7409/mqtt-gateway-add-a-confirmation-acknowledgement-to-the-publish-topic-upon-setting-via-subscribe-topic</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 16:05:31 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/7409.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Aug 2017 22:07:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Wed, 30 Aug 2017 05:50:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-morris" aria-label="Profile: Brian-Morris">@<bdi>Brian-Morris</bdi></a></p>
<p dir="auto">Don't invert the state before you send it back to the controller . Ie this part:</p>
<pre><code>state?false:true
</code></pre>
<p dir="auto">should be:</p>
<pre><code>state?true:false
</code></pre>
<p dir="auto">in the receive function.</p>
]]></description><link>https://forum.mysensors.org/post/74884</link><guid isPermaLink="true">https://forum.mysensors.org/post/74884</guid><dc:creator><![CDATA[martinhjelmare]]></dc:creator><pubDate>Wed, 30 Aug 2017 05:50:45 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Tue, 29 Aug 2017 21:39:32 GMT]]></title><description><![CDATA[<p dir="auto">with it here, I attempt to turn on the switch by sending a payload of "1" to turn on the switch via MQTT. The gateway receives it, sends it to the node, where the node reverses it, sends it back 0.  I can press the button many times over, stays 0/off.</p>
<pre><code>void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
  } else if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);
     send(msg.set(state?false:true));


     if (state == true){
       colorSet(strip.Color(0, 255, 0));  // Green
     } else {
       colorSet(strip.Color(255, 255, 255));  // White
     }
</code></pre>
<p dir="auto">Node DEBUG</p>
<pre><code>0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
4 TSM:INIT
4 TSF:WUR:MS=0
12 TSM:INIT:TSP OK
14 TSM:INIT:STATID=80
16 TSF:SID:OK,ID=80
18 TSM:FPAR
55 TSF:MSG:SEND,80-80-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
557 TSF:MSG:READ,0-0-80,s=255,c=3,t=8,pt=1,l=1,sg=0:0
563 TSF:MSG:FPAR OK,ID=0,D=1
2062 TSM:FPAR:OK
2062 TSM:ID
2064 TSM:ID:OK
2066 TSM:UPL
2070 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2076 TSF:MSG:READ,0-0-80,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2082 TSF:MSG:PONG RECV,HP=1
2086 TSM:UPL:OK
2088 TSM:READY:ID=80,PAR=0,DIS=1
2127 !TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=NACK:0100
4136 TSF:MSG:SEND,80-80-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=1,st=OK:2.1.1
4147 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
6158 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:Living Room Fan Switch
6170 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.5
6178 TSF:MSG:SEND,80-80-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
6187 MCO:REG:REQ
6191 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
6197 TSF:MSG:READ,0-0-80,s=255,c=3,t=27,pt=1,l=1,sg=0:1
6203 MCO:PIM:NODE REG=1
6207 MCO:BGN:STP
8660 MCO:BGN:INIT OK,TSP=1
170743 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1
170752 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
Incoming change for sensor:1, New status: 1
173297 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1
173305 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
Incoming change for sensor:1, New status: 1
294385 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:0
294391 TSF:MSG:ACK
This is an ack from gateway
</code></pre>
<p dir="auto">GW</p>
<pre><code>0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
IP: 10.200.62.10
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/0/0/18
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/11
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/12
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/10/0/0/3
pm open,type:2 0
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
</code></pre>
<p dir="auto">moving it to here, the physical switch stays at 1 no matter how many times you click.  Controller to MQTT works and the switch works, but still no response back to the controller.</p>
<pre><code>void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
     send(msg.set(state?false:true));
  } else if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);

     if (state == true){
       colorSet(strip.Color(0, 255, 0));  // Green
     } else {
       colorSet(strip.Color(255, 255, 255));  // White
     }	 
</code></pre>
<p dir="auto">Node</p>
<pre><code>0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
4 TSM:INIT
4 TSF:WUR:MS=0
12 TSM:INIT:TSP OK
14 TSM:INIT:STATID=80
16 TSF:SID:OK,ID=80
18 TSM:FPAR
55 TSF:MSG:SEND,80-80-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
704 TSF:MSG:READ,0-0-80,s=255,c=3,t=8,pt=1,l=1,sg=0:0
708 TSF:MSG:FPAR OK,ID=0,D=1
2062 TSM:FPAR:OK
2062 TSM:ID
2064 TSM:ID:OK
2066 TSM:UPL
2070 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2084 TSF:MSG:READ,0-0-80,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2091 TSF:MSG:PONG RECV,HP=1
2093 TSM:UPL:OK
2095 TSM:READY:ID=80,PAR=0,DIS=1
2101 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2109 TSF:MSG:READ,0-0-80,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2117 TSF:MSG:SEND,80-80-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
2129 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
4141 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:Living Room Fan Switch
4153 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.5
4161 TSF:MSG:SEND,80-80-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
4169 MCO:REG:REQ
4173 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
4239 TSF:MSG:READ,0-0-80,s=255,c=3,t=27,pt=1,l=1,sg=0:1
4245 MCO:PIM:NODE REG=1
4247 MCO:BGN:STP
6701 MCO:BGN:INIT OK,TSP=1
▒&amp;L▒TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1
Incoming change for sensor:1, New status: 1
M▒TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:▒2▒Ɂ▒▒▒ͽ▒▒brU▒▒.]X▒us: 1
54794 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1
54800 TSF:MSG:ACK
This is an ack from gateway
54806 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
96909 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0
Incoming change for sensor:1, New status: 0
99350 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
99360 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1
99366 TSF:MSG:ACK
This is an ack from gateway
99371 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
101445 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1
101451 TSF:MSG:ACK
This is an ack from gateway
101455 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
113451 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0
Incoming change for sensor:1, New status: 0
118966 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1
Incoming change for sensor:1, New status: 1
121210 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0
Incoming change for sensor:1, New status: 0
</code></pre>
<p dir="auto">GW</p>
<pre><code>0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
IP: 10.200.62.10
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/0/0/18
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/11
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/12
0;255;3;0;9;Sending message on topic: /mysgw1-out/0/10/0/0/3
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
pm open,type:2 0
Incoming change for sensor:1, New status: 0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 0
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2
Incoming change for sensor:1, New status: 1
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2
0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0
</code></pre>
<p dir="auto">Whole code</p>
<pre><code>#define MY_DEBUG
#define MY_RADIO_NRF24
#define MY_NODE_ID 80
#define MY_REPEATER_FEATURE

#include &lt;Arduino.h&gt;
#include &lt;Adafruit_NeoPixel.h&gt;
#include &lt;Ticker.h&gt;
#include &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;
#include &lt;Bounce2.h&gt;

#define RELAY_PIN  2  // Arduino Digital I/O pin number for relay
#define BUTTON_PIN  3  // Arduino Digital I/O pin number for button
#define CHILD_ID 1   // Id of the sensor child
#define RGB_CHILD_ID 2   // Id of the sensor child
#define RELAY_ON 1
#define RELAY_OFF 0

#define NUMPIXELS 1
#define PIXELPIN 4
#define BRIGHTNESS 10

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
long RGB_values[3] = {0,0,0};

Bounce debouncer = Bounce();
int oldValue=0;
bool state;

MyMessage msg(CHILD_ID,V_LIGHT);

void setup()
{
  // Setup the button
  pinMode(BUTTON_PIN,INPUT);
  // Activate internal pull-up
  digitalWrite(BUTTON_PIN,HIGH);

  // After setting up the button, setup debouncer
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(5);

  // Make sure relays are off when starting up
  digitalWrite(RELAY_PIN, RELAY_OFF);
  // Then set relay pins in output mode
  pinMode(RELAY_PIN, OUTPUT);

  // Set relay to last known state (using eeprom storage)
  state = loadState(CHILD_ID);
  digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);

  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show(); // Update the strip, to start they are all 'off'

  startupSequence();

}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Living Room Fan Switch", "1.5");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID, S_LIGHT);
  //present(RGB_CHILD_ID, S_RGB_LIGHT);
}

/*
*  Example on how to asynchronously check for new messages from gw
*/
void loop()
{
  debouncer.update();
  // Get the update value
  int value = debouncer.read();
  if (value != oldValue &amp;&amp; value==0) {
      send(msg.set(state?false:true), true); // Send new state and request ack back
      if (value == true){
        colorSet(strip.Color(0, 255, 0));  // Green
      } else {
        colorSet(strip.Color(255, 255, 255));  // White
      }
  }
  oldValue = value;
}

void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
     send(msg.set(state?false:true));
  } else if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);

     if (state == true){
       colorSet(strip.Color(0, 255, 0));  // Green
     } else {
       colorSet(strip.Color(255, 255, 255));  // White
     }

     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   }
}


void startupSequence(){
  colorSet(strip.Color(255, 0, 0));  // Red
  delay(350);
  colorSet(strip.Color(255, 255, 0));  // Yellow
  delay(350);
  colorSet(strip.Color(0, 255, 0));  // Green
  delay(350);
  colorSet(strip.Color(0, 0, 0));  // Black
  delay(350);
  colorSet(strip.Color(0, 255, 0));  // Green
  delay(350);
  colorSet(strip.Color(255, 255, 255));  // White
  delay(350);
  colorSet(strip.Color(0, 0, 0));  // Black
  delay(350);
  colorSet(strip.Color(255, 255, 255));  // White
}


void colorSet(uint32_t color)
{
    for (int i = 0; i &lt; strip.numPixels(); i++)
    {
        strip.setPixelColor(i, color);
    }
    strip.show();
}
</code></pre>
]]></description><link>https://forum.mysensors.org/post/74876</link><guid isPermaLink="true">https://forum.mysensors.org/post/74876</guid><dc:creator><![CDATA[Brian Morris]]></dc:creator><pubDate>Tue, 29 Aug 2017 21:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Tue, 29 Aug 2017 20:18:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-morris" aria-label="Profile: Brian-Morris">@<bdi>Brian-Morris</bdi></a> I think</p>
<pre><code>send(msg.set(state?false:true), true);
</code></pre>
<p dir="auto">should be moved to inside the else if.<br />
If that doesn't help, could you please post a debug log from the node and the gateway, with your complete sketch? Easier to get all the cards on the table :)</p>
]]></description><link>https://forum.mysensors.org/post/74874</link><guid isPermaLink="true">https://forum.mysensors.org/post/74874</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Tue, 29 Aug 2017 20:18:16 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Tue, 29 Aug 2017 18:12:19 GMT]]></title><description><![CDATA[<p dir="auto">Changed to the following. Still no change. Still loops.</p>
<pre><code>if (message.isAck()) {
     Serial.println("This is an ack from gateway");
     send(msg.set(state?false:true), true);
  } else if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);


     if (state == true){
       colorSet(strip.Color(0, 255, 0));  // Green
     } else {
       colorSet(strip.Color(255, 255, 255));  // White
     }

     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   }
}```</code></pre>
]]></description><link>https://forum.mysensors.org/post/74871</link><guid isPermaLink="true">https://forum.mysensors.org/post/74871</guid><dc:creator><![CDATA[Brian Morris]]></dc:creator><pubDate>Tue, 29 Aug 2017 18:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Tue, 29 Aug 2017 16:29:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-morris" aria-label="Profile: Brian-Morris">@<bdi>Brian-Morris</bdi></a> you can probably fix the looping by changing the second if in an else if.<br />
Now the ack message can/will trigger a new message...</p>
]]></description><link>https://forum.mysensors.org/post/74865</link><guid isPermaLink="true">https://forum.mysensors.org/post/74865</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Tue, 29 Aug 2017 16:29:27 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Tue, 29 Aug 2017 15:27:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> that did not seem to work. It causes a loop where it sends the state back and forth, changing the value and switch state.  This topic could be moved to troubleshooting if someone can do so as well.</p>
<pre><code>void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
  }

  if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);
     send(msg.set(state?false:true), true);

     if (state == true){
       colorSet(strip.Color(0, 255, 0));  // Green
     } else {
       colorSet(strip.Color(255, 255, 255));  // White
     }

     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   }
}

</code></pre>
]]></description><link>https://forum.mysensors.org/post/74864</link><guid isPermaLink="true">https://forum.mysensors.org/post/74864</guid><dc:creator><![CDATA[Brian Morris]]></dc:creator><pubDate>Tue, 29 Aug 2017 15:27:29 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Mon, 28 Aug 2017 22:59:15 GMT]]></title><description><![CDATA[<p dir="auto">btw, it looks like the dimmable led example already does what you're requesting: <a href="https://www.mysensors.org/build/dimmer" rel="nofollow ugc">https://www.mysensors.org/build/dimmer</a></p>
]]></description><link>https://forum.mysensors.org/post/74808</link><guid isPermaLink="true">https://forum.mysensors.org/post/74808</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Mon, 28 Aug 2017 22:59:15 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Mon, 28 Aug 2017 22:56:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-morris" aria-label="Profile: Brian-Morris">@<bdi>Brian-Morris</bdi></a> a global feature could be nice. To my knowledge, the current protocol does not support sending ack to a controller but maybe it can be added.</p>
]]></description><link>https://forum.mysensors.org/post/74807</link><guid isPermaLink="true">https://forum.mysensors.org/post/74807</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Mon, 28 Aug 2017 22:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Mon, 28 Aug 2017 22:28:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> I did not think of that That should definitely work. I will give it a shot. Thanks!</p>
<p dir="auto">Also for the record, I was thinking of a feature request globally.  MySensors already does the acknowledgements in its own protocol, could be cool to do it with MQTT as well.</p>
]]></description><link>https://forum.mysensors.org/post/74802</link><guid isPermaLink="true">https://forum.mysensors.org/post/74802</guid><dc:creator><![CDATA[Brian Morris]]></dc:creator><pubDate>Mon, 28 Aug 2017 22:28:43 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT Gateway: Add a confirmation&#x2F;acknowledgement to the publish topic upon setting via subscribe topic. on Mon, 28 Aug 2017 22:16:10 GMT]]></title><description><![CDATA[<p dir="auto">Welcome to the MySensors community <a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-morris" aria-label="Profile: Brian-Morris">@<bdi>Brian-Morris</bdi></a>. Can't you just send a reply after switching the output? See <a href="https://www.mysensors.org/download/sensor_api_20#sending-data" rel="nofollow ugc">https://www.mysensors.org/download/sensor_api_20#sending-data</a></p>
]]></description><link>https://forum.mysensors.org/post/74799</link><guid isPermaLink="true">https://forum.mysensors.org/post/74799</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Mon, 28 Aug 2017 22:16:10 GMT</pubDate></item></channel></rss>