# Reed Switch Whitepaper

### Introduction <a href="#introduction" id="introduction"></a>

The reed switch is an **electrical switch operated by applying a magnetic field**. Without the magnetic field, the switch is open, with the magnetic field, the switch closes. This sensor allows Simple Hardware devices to cover a great number of use cases - **when combined with a magnet**.

{% hint style="info" %}
The reed switch replaces the button functionality in the **SimpleIndustry and SimpleMeter** devices and is used to trigger **downlink**!
{% endhint %}

**There are three API 6 user modes that work with the sensor:**

* Reed switch on/off
* Reed switch counter
* Reed switch pipeline

Each of these modes covers a different **business logic** by having sending **different data** based on **different triggers**. Let's have a closer look.

{% hint style="success" %}
**IMPORTANT: The reed switch functionality below works exactly the same with switch/dry contacts!**
{% endhint %}

### Reed switch on/off <a href="#reed-switch-onoff" id="reed-switch-onoff"></a>

**How it works**: When the reed switch **closes**, a message is sent **immediately**. When the magnetic field is no longer present and the switch **opens**, a different **instant message is sent**. Very simple!

{% hint style="info" %}
Reed switch on/off is also available in three different WiFi versions. You can read about them [right here!](https://ask.simplehw.eu/kb/pre-sales-support/untitled/location-tracking-whitepaper)
{% endhint %}

### Reed switch counter <a href="#reed-switch-counter" id="reed-switch-counter"></a>

**How it works**: The device will count the number of **times the reed switch has closed** (number of magnetic field presences/magnet rotations). You can choose the **trigger** of the message: either it's **time** (number of switches in e.g. one hour) or the exact **count** (message sent after e.g. 50 switches.)

### Reed switch pipeline <a href="#reed-switch-pipeline" id="reed-switch-pipeline"></a>

**How it works**: The device will measure how long the reed switch **was open** and then how long it **was closed**. This will then be reported in a message that contains a total of **8 time periods**: 4 for both states. E.g. reed switch closed for 12 minutes, then opened for 10 minutes, then closed again for 8 minutes, etc.

### Reed switch modes comparison table <a href="#reed-switch-modes-comparison-table" id="reed-switch-modes-comparison-table"></a>

| Mode                      | Reed switch on/off        | Reed switch counter          | Reed switch pipeline  |
| ------------------------- | ------------------------- | ---------------------------- | --------------------- |
| Mode hex (API 6)          | 0x0C                      | 0x13                         | 0x08                  |
| WiFi versions available   | ✔️                        | ❌                            | ❌                     |
| Message trigger           | switch open/closed        | time/count reached           | time - pipeline full  |
| Message availability      | instant                   | customizable as per settings | when pipeline is full |
| Appended payload possible | ✔️ (not in WiFi versions) | ❌                            | ❌                     |

### API 6 downlink register related to the reed switch <a href="#api-6-downlink-register-related-to-the-reed-switch" id="api-6-downlink-register-related-to-the-reed-switch"></a>

Reed switch-based modes can be fine-tuned with these downlink registers:

| Register name                                              | Register hex | Register value range | What it is and what it does                                                                          | Useful for                              |
| ---------------------------------------------------------- | ------------ | -------------------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------- |
| Sleep time                                                 | 0x04         | SimpleTime           | Time after record/message during which the device will ignore any sensor input.                      | Reed switch on/off, Reed switch counter |
| Reed switch measurement period interval                    | 0x37         | SimpleTime           | How often the processor wakes the sensor up and asks for data input - how often the sensor measures. | All reed switch modes                   |
| Reed switch pipeline time threshold for exponent selection | 0x46         | SimpleTime           | Please see the mode documentation for detailed information.                                          | Reed switch pipeline                    |
| Reed switch detection delay                                | 0x4B         | SimpleTime           | How long should the change of state last before the message is triggered or data recorded.           | All reed switch modes                   |
| Reed switch counter count trigger                          | 0x50         | Number 1-255         | After how many reed switches should the message be sent.                                             | Reed switch counter                     |
| Reed switch counter time trigger                           | 0x51         | SimpleTime           | After how long should the message be sent.                                                           | Reed switch counter                     |

[Here's the API 6 table for more information!](https://docs.google.com/spreadsheets/d/1hGcSu_Wcld7ZAccNz29Ni4D3gWtkkKHsiGtZQLGJE6g/)
