Send Wemos D1 mini with Tasmota to DeepSleep via NodeRed

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

Hi.

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

Do you know how to use MQTT?

Yes, why not?
Maybe look into the node-contrib-counter node as a helper.

You can send commands via mqtt to the device, using the /cmd/ topic - another option is to use a rule on the device, that reacts on a mqtt command/event received.

Lots of info here:

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.

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:

[
    {
        "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 ....

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

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

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

Or

"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:

[{"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":""}]

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. :face_with_raised_eyebrow:

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?

This sounds like you also have some timer rules setup ?

Check DeepSleep - Tasmota

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

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

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