# Trigger node - send payload & topic

**URL:** <https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650>\
**Category:** General\
**Created:** [23 December 2022 23:20 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650 "2022-12-23T23:20:22Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [23 December 2022 23:20 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/1 "2022-12-23T23:20:22Z")

</div>

I have a flow controlling a light which I control via Google Home voice commands, to MQTT, to a tasmota remote device.

If I tell google to switch the device `on`, it sends;  
`{"payload":"on","topic":"cmnd/sonoff2/POWER"}` to the MQTT node.  
...but, I don't want to forget to turn it off, so I've included a trigger node, and set it send another msg 5 minutes later to turn it off;

![delay](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/bae707c32a81fc40cf3cdb6242271c5d65b02784.jpeg)

..but it doesn't produce the correct msg format & fails, it produces;

```auto
{"payload":{"payload":"off","topic":"cmnd/sonoff2/POWER"},"topic":"cmnd/sonoff2/POWER"}

```

Where have I gone wrong?

instead of `{"payload":"off","topic":"cmnd/sonoff2/POWER"}`

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 December 2022 23:31 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/2 "2022-12-23T23:31:34Z")

</div>

As you would expect, as the trigger node sends a msg.payload not a msg.

Why not set the topic prior to the trigger and send both on and off from the trigger (to same or different outputs).  
e.g.

```auto
[{"id":"b5db95460639fe7a","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":580,"wires":[["56e5fb6e81c96f21"]]},{"id":"56e5fb6e81c96f21","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"tasmota/topic","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":580,"wires":[["86dfb82af7806939"]]},{"id":"86dfb82af7806939","type":"trigger","z":"da8a6ef0b3c9a5c8","name":"","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":580,"wires":[["441b83f51eec6037"]]},{"id":"441b83f51eec6037","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 116","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":660,"wires":[]}]

```

---

<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:** [23 December 2022 23:48 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/3 "2022-12-23T23:48:40Z")

</div>

Yes thanks @E1cid .  
Shouldn't there be an option to send a complete msg object?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 December 2022 23:58 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/4 "2022-12-23T23:58:07Z")

</div>

It does send a complete msg you just have to construct it beforehand, would be nice to be able to construct internally though. As it stands you can not sent a payload to a msg property either.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 December 2022 01:50 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/5 "2022-12-24T01:50:51Z")

</div>

Does the Sonoff have Tasmota?  
Set PulseTime 1 to 400 and the relay should turn itself off 5 minutes after the last ON message. (Not specifically tsted with Sonoff but it's a basic Tasmota option.)

---

<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:** [28 December 2022 22:20 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/6 "2022-12-28T22:20:45Z")

</div>

> [@jbudd](#):
>
> Set PulseTime 1 to 400 and the relay should turn itself off 5 minutes after the last ON message

Thanks, I'd forgotten about that feature. It's probably a better solution because it's not dependent upon a reliable network, as once the command is received, it executes without further commands.

---

<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:** [11 January 2023 22:21 UTC](https://discourse.nodered.org/t/trigger-node-send-payload-topic/72650/7 "2023-01-11T22:21:38Z")

</div>

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