<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Google Smart Home onExecute delay when turning on smart fan (Node.js + Firebase + MQTT) in Smart Home Developer Forum</title>
    <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Google-Smart-Home-onExecute-delay-when-turning-on-smart-fan-Node-js/m-p/737241#M9465</link>
    <description>&lt;P data-start="131" data-end="482"&gt;Hello,&lt;/P&gt;
&lt;P data-start="131" data-end="482"&gt;The delay comes from creating subscriptions or cold starts inside &lt;CODE data-start="197" data-end="208"&gt;onExecute&lt;/CODE&gt;. To fix this, maintain a persistent MQTT client (don’t dynamically subscribe/unsubscribe on every request), publish directly during execution, and call &lt;CODE data-start="369" data-end="382"&gt;reportState&lt;/CODE&gt; after the action. If you’re on Firebase Functions, set minInstances to reduce cold-start lag.&lt;/P&gt;
&lt;P data-start="484" data-end="517"&gt;&lt;STRONG data-start="484" data-end="515"&gt;To your specific questions:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="518" data-end="839"&gt;
&lt;LI data-start="518" data-end="613"&gt;
&lt;P data-start="520" data-end="613"&gt;Should I avoid dynamic subscribe/unsubscribe? → Yes, use a persistent connection instead.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="614" data-end="839"&gt;
&lt;P data-start="616" data-end="839"&gt;Is there a better pattern for publishing MQTT commands? → Yes, keep the MQTT client alive, publish immediately on &lt;CODE data-start="732" data-end="743"&gt;onExecute&lt;/CODE&gt;, and then update Home Graph with &lt;CODE data-start="777" data-end="790"&gt;reportState&lt;/CODE&gt;. This ensures the device action feels instant.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 21 Aug 2025 17:51:58 GMT</pubDate>
    <dc:creator>Suc_dpe</dc:creator>
    <dc:date>2025-08-21T17:51:58Z</dc:date>
    <item>
      <title>Google Smart Home onExecute delay when turning on smart fan (Node.js + Firebase + MQTT)</title>
      <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Google-Smart-Home-onExecute-delay-when-turning-on-smart-fan-Node-js/m-p/736708#M9452</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am integrating Google Smart Home with my IoT devices (Node.js + Firebase Functions + MQTT).&lt;BR /&gt;When the user says &lt;STRONG&gt;“Turn on fan”&lt;/STRONG&gt;, the onExecute handler is triggered, but the fan operation happens with a noticeable delay (2–3 seconds).&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Here’s the relevant flow in my code:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;app.onExecute(&lt;SPAN class=""&gt;async&lt;/SPAN&gt; (body, headers) =&amp;gt; { &lt;SPAN class=""&gt;const&lt;/SPAN&gt; { requestId } = body; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; intent = body.inputs[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; commandResults = []; &lt;SPAN class=""&gt;for&lt;/SPAN&gt; (&lt;SPAN class=""&gt;const&lt;/SPAN&gt; command of intent.payload.commands) { &lt;SPAN class=""&gt;for&lt;/SPAN&gt; (&lt;SPAN class=""&gt;const&lt;/SPAN&gt; device of command.devices) { &lt;SPAN class=""&gt;const&lt;/SPAN&gt; deviceId = device.id; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; parts = deviceId.split(&lt;SPAN class=""&gt;'_'&lt;/SPAN&gt;); &lt;SPAN class=""&gt;const&lt;/SPAN&gt; boardSerial = parts[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; switchId = parts[&lt;SPAN class=""&gt;1&lt;/SPAN&gt;] || &lt;SPAN class=""&gt;null&lt;/SPAN&gt;; &lt;SPAN class=""&gt;await&lt;/SPAN&gt; withLock(boardSerial, &lt;SPAN class=""&gt;async&lt;/SPAN&gt; () =&amp;gt; { &lt;SPAN class=""&gt;await&lt;/SPAN&gt; Promise.all(command.execution.map(&lt;SPAN class=""&gt;async&lt;/SPAN&gt; (execution) =&amp;gt; { &lt;SPAN class=""&gt;await&lt;/SPAN&gt; updateDevice(execution, body, headers, boardSerial, switchId); &lt;SPAN class=""&gt;// inside updateDevice -&amp;gt; publishes MQTT command (VG094:11) to topic&lt;/SPAN&gt; })); }); commandResults.push({ ids: [deviceId], status: &lt;SPAN class=""&gt;'SUCCESS'&lt;/SPAN&gt;, states: { &lt;SPAN class=""&gt;on&lt;/SPAN&gt;: &lt;SPAN class=""&gt;true&lt;/SPAN&gt;, online: &lt;SPAN class=""&gt;true&lt;/SPAN&gt; } }); } } &lt;SPAN class=""&gt;return&lt;/SPAN&gt; { requestId, payload: { commands: commandResults }, }; });&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;The updateDevice function publishes MQTT commands (encrypted with key/iv) to the device’s topic.&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;After that, I also call reportState to update Google HomeGraph.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Devices eventually respond, but the &lt;STRONG&gt;Google Assistant action feels slow&lt;/STRONG&gt; compared to Alexa integration with the same backend.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;What I’ve tried / noticed:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;If I publish directly to MQTT (bypassing Google onExecute), the fan reacts instantly.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Delay seems to come from my cloud function or how I handle subscriptions inside updateDevice.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;I already added a withLock per device to avoid parallel execution clashes.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;I suspect client.on('message') listeners or subscribe/unsubscribe inside updateDevice may be introducing delay.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;How can I reduce the delay in the Google Smart Home onExecute → MQTT execution path?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Should I avoid dynamic subscribe/unsubscribe inside updateDevice and instead maintain a persistent subscription?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Is there a better pattern for publishing MQTT commands in response to Google Smart Home intents (so the device action is instant)?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 19 Aug 2025 05:02:15 GMT</pubDate>
      <guid>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Google-Smart-Home-onExecute-delay-when-turning-on-smart-fan-Node-js/m-p/736708#M9452</guid>
      <dc:creator>Pallab_Mishra</dc:creator>
      <dc:date>2025-08-19T05:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Google Smart Home onExecute delay when turning on smart fan (Node.js + Firebase + MQTT)</title>
      <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Google-Smart-Home-onExecute-delay-when-turning-on-smart-fan-Node-js/m-p/737241#M9465</link>
      <description>&lt;P data-start="131" data-end="482"&gt;Hello,&lt;/P&gt;
&lt;P data-start="131" data-end="482"&gt;The delay comes from creating subscriptions or cold starts inside &lt;CODE data-start="197" data-end="208"&gt;onExecute&lt;/CODE&gt;. To fix this, maintain a persistent MQTT client (don’t dynamically subscribe/unsubscribe on every request), publish directly during execution, and call &lt;CODE data-start="369" data-end="382"&gt;reportState&lt;/CODE&gt; after the action. If you’re on Firebase Functions, set minInstances to reduce cold-start lag.&lt;/P&gt;
&lt;P data-start="484" data-end="517"&gt;&lt;STRONG data-start="484" data-end="515"&gt;To your specific questions:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="518" data-end="839"&gt;
&lt;LI data-start="518" data-end="613"&gt;
&lt;P data-start="520" data-end="613"&gt;Should I avoid dynamic subscribe/unsubscribe? → Yes, use a persistent connection instead.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="614" data-end="839"&gt;
&lt;P data-start="616" data-end="839"&gt;Is there a better pattern for publishing MQTT commands? → Yes, keep the MQTT client alive, publish immediately on &lt;CODE data-start="732" data-end="743"&gt;onExecute&lt;/CODE&gt;, and then update Home Graph with &lt;CODE data-start="777" data-end="790"&gt;reportState&lt;/CODE&gt;. This ensures the device action feels instant.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 21 Aug 2025 17:51:58 GMT</pubDate>
      <guid>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Google-Smart-Home-onExecute-delay-when-turning-on-smart-fan-Node-js/m-p/737241#M9465</guid>
      <dc:creator>Suc_dpe</dc:creator>
      <dc:date>2025-08-21T17:51:58Z</dc:date>
    </item>
  </channel>
</rss>

