<commit_before># node-red-contrib-mytimeout Readme
This is a fork of <NAME>'s node-red-contrib-timeout module for node-red. I have different ideas of what a timer should do and how it should operate so I've taken to butchering Pete's code until it does what I want.

## Timeout
Pete's code would start a timer running if you sent it any trigger. It would contiunue to run if further triggers were sent before the timeout occurred.

You can configure the timeout module with the settings for the Safe and Unsafe messages. Safe is sent on the start of the timer, the unsafe message sent when the timeout occurs.

* Name
* Output topic
* Safe state payload
* Warning state payload
* Unsafe state payload
* Warning (sec)
* Countdown (sec)

* [ ] Repeat message every second
* [ ] Auto-restart when timed out
* [ ] Run at start

All of this is very useful for things like lights that are motion activated. If motion is detected, the Safe payload is sent (On or 1). The timer can be started when motion is detected and as long as the motion continues there will be no timeout. When the timeout occurs the Unsafe payload is sent (Off or 0). When the timeout warning time (n seconds before the timeout).

## MyTimeout
My additions to the code allows the user to send JSON in the triggers. You can override the timeout and warning times. 

```
{
    "payload": "on",
    "timeout": 3600,
    "warning": 300
}

{
    "payload": "off"
}

{
    "payload": "stop"
}

{
    "payload": "cancel"
}
```

When sending the JSON on message, payload, timeout and warning are required. The JSON message off will immediately cause a timeout sending the off as the message. The JSON stop (or cancel) message will stop the timeout and send the stop as the message.

# Timeout (original Readme)

A simple timeout by <NAME> (<EMAIL>). After setting the topic and both safe and unsafe messages, for, for example MQTT (or simply puttting 1 and 0 into the two messages) the node is triggered by any input and will send the SAFE message out. If continually triggered nothing more will happen but if allowed to timeout, the UNSAFE message will be sent. Hence this can be used as a watchdog. 

For more IOT, visit https://tech.scargill.net<commit_msg>Clarified the JSON messages and expected output<commit_after># node-red-contrib-mytimeout Readme
This is a fork of <NAME>'s node-red-contrib-timeout module for node-red. I have different ideas of what a timer should do and how it should operate so I've taken to butchering Pete's code until it does what I want.

## myTimeout
Pete's code would start a timer running if you sent it any trigger (tickle the timer). It would contiunue to run if further triggers were sent before the timeout occurred. A trigger was anything sent to the input of the timer.

My code goes a step further, allowing you to send JSON (see below) to overrride the timer, to turn off the timer or to cancel or stop the timer. It still retains Pete's behaviors. You can still send almost anything to tickle the timer with the exception of the JSON below which will cause the timer to do specific things.

You can configure the timeout module with the settings for the Safe and Unsafe messages. Safe is sent on the start of the timer, the unsafe message sent when the timeout occurs.

* Name
* Output topic
* On state payload
* Warning state payload
* Off state payload
* Warning (sec)
* Countdown (sec)

* [ ] Repeat message every second
* [ ] Auto-restart when timed out
* [ ] Run at start

All of this is very useful for things like lights that are motion activated. If motion is detected, the Safe payload is sent (On or 1). The timer can be started when motion is detected and as long as the motion continues there will be no timeout. When the timeout occurs the Unsafe payload is sent (Off or 0). When the timeout warning time (n seconds before the timeout).

## MyTimeout
My additions to the code allows the user to send JSON in the triggers. You can override the timeout and warning times. 

```
{
    "payload": "on",
    "timeout": 3600,
    "warning": 300
}

{
    "payload": "off"
}

{
    "payload": "stop"
}

{
    "payload": "cancel"
}
```
### Payload
* *on* - turns on the timer. Requires the addition fields *timeout* and *warning*. Both field values are integers and are in seconds. This payload will cause the timer to send a *Timer on payload* message in the msg.payload output
* *off* - turns off the timer. This payload will cause the timer to send a *Timer off payload* in the msg.payload output
* *stop* - stops the timer. This payload will cause the timer to send *stop* in the msg.payload output
* *cancel* - cancels the timer. This payload will cause the timer to cancel but send nothing in the msg.payload output

When sending the JSON *on* message, payload, timeout and warning are
all required. The JSON message *off* will immediately cause a timeout
sending an *Timer off payload* as the message. The JSON *stop* message
will stop the timeout and send the stop as the message. The JSON
*cancel* (or *cancel*) message will stop the timeout and not send a
message. There is very little difference in the *off*, *stop* and
*cancel* behaviors other than what is sent or not sent to the
topic. They all stop the timer.

# Timeout (original Readme)

A simple timeout by <NAME> (<EMAIL>). After setting
the topic and both safe and unsafe messages, for, for example MQTT (or
simply puttting 1 and 0 into the two messages) the node is triggered
by any input and will send the SAFE message out. If continually
triggered nothing more will happen but if allowed to timeout, the
UNSAFE message will be sent. Hence this can be used as a watchdog.

For more IOT, visit https://tech.scargill.net
{'fraction_non_alphanumeric': 0.06036146692402176, 'fraction_numerical': 0.003860326373047903, 'mean_word_length': 3.918032786885246, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '157780', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1466, 'n_words': 927}