# Sending mqtt msg every 20 seconds

**URL:** <https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853>\
**Category:** General\
**Created:** [18 May 2020 14:31 UTC](https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853 "2020-05-18T14:31:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@Ian](https://discourse.nodered.org/u/Ian)\
**Post date:** [18 May 2020 14:31 UTC](https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853/1 "2020-05-18T14:31:11Z")

</div>

Hi

I need to send an mqtt msg every 20 second with the content based on a received input that is updated about once every 4 hours.  
The input is on or off and the output 1 for on and 0 for off. Any suggestions as to the best method.

Regards

Ian

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 May 2020 14:45 UTC](https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853/2 "2020-05-18T14:45:37Z")

</div>

Possibly you can use a Trigger node in Resend Every .. mode.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [18 May 2020 16:01 UTC](https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853/3 "2020-05-18T16:01:09Z")

</div>

...or you could save the input state to context using a change node.  
Then set an inject node to run every 20 seconds, sending the saved context value to a MQTT node.  
If you used a filesystem storage module, the saved value would survive a restart, and continue sending the last saved value.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 July 2020 16:01 UTC](https://discourse.nodered.org/t/sending-mqtt-msg-every-20-seconds/26853/4 "2020-07-17T16:01:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
