# Send Wemos D1 mini with Tasmota to DeepSleep via NodeRed

**URL:** <https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139>\
**Category:** General\
**Created:** [1 July 2024 08:00 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139 "2024-07-01T08:00:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 July 2024 08:00 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/1 "2024-07-01T08:00:06Z")

</div>

Hi all,

I am using a Wemos D1 mini (flashed with Tasmota 14.x) and in deepsleep konfiguration (connection established between D0 and RST pin).

Each time the D1 mini wakes up I want to collect 5 values, calculate the median and send it to DeepSleep again.

1. Is there a possibility to count up to 5 incoming messages and trigger an outgoing message based on that ?
2. Is it possible to create an MQTT message in Node-Red that triggeres a DeepSleep on the D1 mini ? (so far all I was able to do, is to tell the device to go to sleep via console).  
BR  
G

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 July 2024 08:17 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/2 "2024-07-01T08:17:13Z")

</div>

Hi.

So I'm guessing you will have to use MQTT to _talk_ to the device?

Do you know how to use MQTT?

---

<div class="post-metadata">

**Author:** ![hominidae](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hominidae/32/4174_2.png) [@hominidae](https://discourse.nodered.org/u/hominidae)\
**Post date:** [1 July 2024 08:17 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/3 "2024-07-01T08:17:33Z")

</div>

> [@Gawan](#):
>
> Is there a possibility to count up to 5 incoming messages and trigger an outgoing message based on that ?

Yes, why not?  
Maybe look into the [node-contrib-counter](https://flows.nodered.org/node/node-red-contrib-counter) node as a helper.

> [@Gawan](#):
>
> Is it possible to create an MQTT message in Node-Red that triggeres a DeepSleep on the D1 mini ? (so far all I was able to do, is to tell the device to go to sleep via console).

You can send [commands via mqtt](https://tasmota.github.io/docs/MQTT/#commands-over-mqtt) to the device, using the /cmd/ topic - another option is [to use a rule on the device, that reacts on a mqtt](https://tasmota.github.io/docs/MQTT/#subscribe) command/event received.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [1 July 2024 08:24 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/4 "2024-07-01T08:24:40Z")

</div>

Lots of info here:

> **[DeepSleep - Tasmota](https://tasmota.github.io/docs/DeepSleep/)**
>
> Documentation (Wiki) for Tasmota

---

<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:** [1 July 2024 10:06 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/5 "2024-07-01T10:06:53Z")

</div>

As I recall my experiments with deep sleep (Tasmota v11 I think so it may have changed)

The duration of the ESP's sleep is controlled by DeepSleepTime.  
The time it stays awake can be influenced by the TelePeriod command.

If the ESP is set to go into deep sleep, on waking it:

1. Connects to WiFi
2. Connects to MQTT, sending the LWT Birth message
3. Sends a Telemetry message
4. Waits for the period specified by it's TelePeriod setting
5. Sends a second Telemetry message
6. Goes to sleep

If you set TelePeriod to 3600 it will stay awake for 1 hour, sending Telemetry messages at the beginning and the end of the hour.  
But if you send a DeepSleepTime command it responds with a Telemetry message and goes to sleep.

Node-red knows that the ESP woke by subscribing to it's Birth MQTT topic.  
You can then request data from the ESP by sending Status commands (Status10?) and put it back to sleep with DeepSleepTime.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 July 2024 19:21 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/6 "2024-07-01T19:21:37Z")

</div>

I tried to send DeepSleepTime several times via MQTT to the D1 mini, but it seems that it is not received.

This is one of the flows I wrote:

```auto
[
    {
        "id": "1803504d1109453d",
        "type": "mqtt out",
        "z": "32832e30.00f1c2",
        "name": "esp/ESP018/RESULT",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "{\"DeepSleepTime\":0}",
        "correl": "",
        "expiry": "",
        "broker": "eda6156a.d73db8",
        "x": 740,
        "y": 440,
        "wires": []
    },
    {
        "id": "632076ab1be49b36",
        "type": "inject",
        "z": "32832e30.00f1c2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 260,
        "y": 420,
        "wires": [
            [
                "ed2cd9af835268b4"
            ]
        ]
    },
    {
        "id": "ed2cd9af835268b4",
        "type": "function",
        "z": "32832e30.00f1c2",
        "name": "function 4",
        "func": "msg.payload = '{\"DeepSleepTime\":0}';\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 440,
        "wires": [
            [
                "1803504d1109453d"
            ]
        ]
    },
    {
        "id": "eda6156a.d73db8",
        "type": "mqtt-broker",
        "name": "IOT",
        "broker": "10.0.0.14",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "5",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

```

This is how it looks like in the Tasmota Console - thats how it should be received:

20:10:16.293 MQT: esp/ESP018/RESULT = {"DeepSleepTime":0}

But something is going wrong ....

---

<div class="post-metadata">

**Author:** ![hominidae](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hominidae/32/4174_2.png) [@hominidae](https://discourse.nodered.org/u/hominidae)\
**Post date:** [1 July 2024 19:54 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/7 "2024-07-01T19:54:29Z")

</div>

> [@Gawan](#):
>
> I tried to send DeepSleepTime several times via MQTT to the D1 mini, but it seems that it is not received.

...that doesn't look like your are using the correct syntax and cmnd topic, as defined in the docs.

---

<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:** [1 July 2024 20:01 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/8 "2024-07-01T20:01:40Z")

</div>

If the Topic in your ESP MQTT config is "esp/ESP018" then you have to send commands to topic `cmnd/esp/ESP018/<something>`

Responses arrive on topic "stat/esp/ESP018/RESULT"

There are two approaches. You could send

```auto
"topic": "cmnd/esp/ESP018/backlog",
"payload": "deepsleeptime 600;"

```

Or

```auto
"topic": "cmnd/esp/ESP018/deepsleeptime",
"payload": 600

```

An example flow. You can import it but you will have to change the topic in inject and mqtt-in nodes to match your device and the broker details to match your broker:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6ffe9c3c77c45a906365e543787fb611cdefdf55.png)

```auto
[{"id":"a96eb3a25d991dfb","type":"inject","z":"699e0a72d49c76f3","name":"Request current deepsleeptime","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cmnd/gosund/1/deepsleeptime","payload":"","payloadType":"str","x":450,"y":2600,"wires":[["b4e1d7d965ba43c8"]]},{"id":"c1d79d5ed072f325","type":"mqtt in","z":"699e0a72d49c76f3","name":"","topic":"stat/gosund/1/#","qos":"2","datatype":"auto-detect","broker":"bf2923ac3d80c3c0","nl":false,"rap":true,"rh":0,"inputs":0,"x":380,"y":2800,"wires":[["99c583ccce420dd8"]]},{"id":"99c583ccce420dd8","type":"debug","z":"699e0a72d49c76f3","name":"Messages from Tasmota","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":2800,"wires":[]},{"id":"b4e1d7d965ba43c8","type":"mqtt out","z":"699e0a72d49c76f3","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"bf2923ac3d80c3c0","x":710,"y":2660,"wires":[]},{"id":"96e45a38f230983e","type":"inject","z":"699e0a72d49c76f3","name":"Set deepsleeptime 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cmnd/gosund/1/deepsleeptime","payload":"0","payloadType":"num","x":410,"y":2640,"wires":[["b4e1d7d965ba43c8"]]},{"id":"01262c5e832f36cf","type":"inject","z":"699e0a72d49c76f3","name":"Request one of the status options","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cmnd/gosund/1/status","payload":"10","payloadType":"num","x":450,"y":2680,"wires":[["b4e1d7d965ba43c8"]]},{"id":"bf98646888e7a8d9","type":"inject","z":"699e0a72d49c76f3","name":"Request status and set deepsleeptime 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cmnd/gosund/1/backlog","payload":"status 0; deepsleeptime 0;","payloadType":"str","x":470,"y":2720,"wires":[["b4e1d7d965ba43c8"]]},{"id":"bf2923ac3d80c3c0","type":"mqtt-broker","name":"","broker":"192.168.1.11","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [1 July 2024 21:21 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/9 "2024-07-01T21:21:44Z")

</div>

Perfect, this really works fine now !

Now I collect 5 messages in a "calculate" node and get the median from there.  
Then I send the median value to my chart and the D1 mini via MQTT to DeepSleep 600.  
Unfortunately the device sends some more MQTT messages while counting from 60 to 0 before going into DeepSleep and I do not know what I can do to do not mess up the calculate node. 🤨

---

<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:** [1 July 2024 21:40 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/10 "2024-07-01T21:40:28Z")

</div>

> [@Gawan](#):
>
> Unfortunately the device sends some more MQTT messages while counting from 60 to 0 before going into DeepSleep

I don't understand "while counting from 60 to 0". If you send a deepsleeptime message I would expect it to send 1 telemetry message and go straight to sleep.

What are the topics of these messages?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [2 July 2024 01:13 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/11 "2024-07-02T01:13:39Z")

</div>

> [@Gawan](#):
>
> the device sends some more MQTT messages while counting from 60 to 0

This sounds like you also have some timer rules setup ?

Check [DeepSleep - Tasmota](https://tasmota.github.io/docs/DeepSleep/#deepsleep-wakeup-based-on-timer-events)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [2 July 2024 04:10 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/12 "2024-07-02T04:10:21Z")

</div>

> [@Gawan](#):
>
> I do not know what I can do to do not mess up the calculate node

In addition, you should filter the messages and only use those that are of interest for the calculation

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [2 July 2024 05:48 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/13 "2024-07-02T05:48:17Z")

</div>

This sounds like you need to do a bit more study of MQTT and Tasmota structure - there will be System type messages that Tasmota sends out (State topic usually) as well as RESULT messages that are a function of something you send it to do and then there are information messages that come out based on what sensors etc you are reading - by subscribing to the correct Topics in your MQTT node and have a switch node that only sends the appropriate ones to your Calculate node

Craig

---

<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:** [30 September 2024 05:48 UTC](https://discourse.nodered.org/t/send-wemos-d1-mini-with-tasmota-to-deepsleep-via-nodered/89139/14 "2024-09-30T05:48:30Z")

</div>

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