HowTo: Node Red / Tasmota – A “dead man switch” or how to use the absence of status messages as an event

I must admit I've never seen them, but there are supposed to be so-called dead man's switches on trains.

These switches with the somewhat macabre name are quite a sensible invention. These switches must be pressed repeatedly by the train driver within a certain time. If the train driver forgets to do this, for example because he is physically unable to do so, first a warning signal sounds and if the train driver then still does not press the corresponding button, the train brakes automatically.

This system ensures that a train never travels without a driver and that the control station is always manned.

What makes sense in train traffic can only be helpful in a SmartHome system.
There you can also use this method - in a slightly modified form.
For example, this method could be used to switch on the radiator whenever a certain device sends messages at a fixed interval. As soon as these messages are missing, the radiator is switched off again.

For example, I use it at my desk: If the socket for the desk is switched on, the SmartHome reacts to the regularly sent info messages of a Tasmota device (connected to the socket) and automatically switches on the heating in the study. As soon as the desk is switched off again, the regular info messages remain off and the SmartHome switches the heating on.

This example explains how to use the status messages of a Tasmota device. This is because they send a status message to the standard topic “tele/NAME/STATE” at an adjustable interval – five minutes by default. This will then turn on another Tasmota lamp. If the original Tasmota device does not send a signal for more than five minutes - five minutes and ten seconds to be precise - the Tasmota lamp will be switched off again.

How to do this is explained in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
To be able to use this configuration, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

The following articles describe what has to be done to prepare the RaspberryPi so far:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH

NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes

Required tool:
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log into the NodeRed configuration interface

Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Import node code

To try this example you have to import the following Node code into your NodeRed installation.

Node configuration view in the NodeRed editor.
If you want to set the time limit after which a new signal must be received, you can do this in the function node. Change the value marked in the picture. This is the maximum time between two signals in milliseconds. Five minutes and ten seconds correspond to ((5*60seconds)+10seconds)*1000=310000 milliseconds.

Node code:

[{"id":"e2fc26ae.3ff008","type":"mqtt in","z":"4131a41e.b9233c","name":"","topic":"tele/MiniLichterkette/STATE","qos":"2","broker":"3c2a29eb.148006","x":380,"y":1380,"wires":[["a5563ed4.23a7e"]]},{"id":"60f3b2d3.5c1c5c","type":"inject","z":"4131a41e.b9233c","name":"check time","topic":"","payload":"check","payloadType":"str","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":430,"y":1420,"wires":[["a5563ed4.23a7e"]]},{"id":"a5563ed4.23a7e","type":"function","z":"4131a41e.b9233c","name":"check","func":"if (msg.payload=="check")
{
    if ((Date.now()-context.flow.signalTimestamp)>310000)
    {
        context.flow.signalTimestamp=0;
        msg.payload=false;
    } else
    {
        msg.payload=true;
    }
} else
{
    context.flow.signalTimestamp=Date.now();
    msg.payload=true;
}
return msg;","outputs":1,"noerr":0,"x":600,"y":1400,"wires":[["3ab4ab0f.883254","d2419bcd.1368d8"]]},{"id":"3ab4ab0f.883254","type":"trigger","z":"4131a41e.b9233c","op1":"ON","op2":"0","op1type":"str","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"false","bytopic":"all","name":"","x":800,"y":1380,"wires":[["4d720e6.97ee2f","b05ef19f.d9d03"]]},{"id":"d2419bcd.1368d8","type":"trigger","z":"4131a41e.b9233c","op1":"OFF","op2":"0","op1type":"str","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"true","bytopic":"all","name":"","x":800,"y":1420,"wires":[["4d720e6.97ee2f","b05ef19f.d9d03"]]},{"id":"4d720e6.97ee2f","type":"debug","z":"4131a41e.b9233c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1010,"y":1460,"wires":[]},{"id":"b05ef19f.d9d03","type":"mqtt out","z":"4131a41e.b9233c","name":"","topic":"cmnd/GluehbirnenLampe40W/POWER","qos":"","retain":"","broker":"3c2a29eb.148006","x":1120,"y":1420,"wires":[]},{"id":"3c2a29eb.148006","type":"mqtt-broker","z":"","name":"Server-Mqtt","broker":"server.fritz.box","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

2 comments

    1. Hi,
      Unfortunately I can't help you. The code works for me. If you tell me what isn't working for you I can try to help you.
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.