# KNX Water Leakage Sensor: Convert Alternating 0|1 to Alarm Flag

**URL:** https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100
**Category:** General
**Created:** [14 July 2022 14:39 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100 "2022-07-14T14:39:58Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![mathias-ewald](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathias-ewald/32/64611_2.png) [@mathias-ewald](https://discourse.nodered.org/u/mathias-ewald)
#### Post date: [14 July 2022 14:39 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/1 "2022-07-14T14:39:58Z")

</div>

Hi there,

I have a KNX water leakage sensor that sends nothing to the group address when there is no water detected. When there's a leakage it begins sending alternating zeroes and ones to the group address.

In Node-RED I want to convert this to a simple flag that indicates if there's an alarm (1) or not (0). Being new to Node-RED I have no clue how to approach this.

Any ideas?

cheers,  
Mathias

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [14 July 2022 15:40 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/3 "2022-07-14T15:40:39Z")

</div>

ok we need a bit more what KNX node are you using\> Ultimate?  
can you copy your flow and paste into this thread pls flow these instructions.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506/8):
>
> @dclear thanks - have updated the guidance to match

---

<div class="post-metadata">

### Author: ![mathias-ewald](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathias-ewald/32/64611_2.png) [@mathias-ewald](https://discourse.nodered.org/u/mathias-ewald)
#### Post date: [14 July 2022 15:48 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/4 "2022-07-14T15:48:35Z")

</div>

There is no flow, yet, since that's what I am trying to figure out. I use KNX Ultimate and created a "KNX Device" node with the respective group address in KNX. When I connect a debug node, there is nothing. The devices does not emit any messages. When I spill water on the sensor, the messages keep coming with payloads alternating 0 and 1:

So, when there's  
no alarm: ... nothing, no message  
an alarm: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, and so on

I think the idea of the device is to connect an light that will flash when there's a water leak, but I'd prefer to get message on the phone somehow 😃

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 July 2022 16:03 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/5 "2022-07-14T16:03:17Z")

</div>

You could use a Trigger node set to send the alarm message every time there is a message in. Set the timeout to greater than the longest time between the 0/1 messages and then to send the alarm off message. Follow that with a Filter node to suppress the repeated alarms, so you will get an alarm on when the first transition occurs and then an alarm off when the input stream stops.

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [14 July 2022 17:40 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/6 "2022-07-14T17:40:34Z")

</div>

This is the msg from a Gira PS3 button to turn lights on

```auto
{"topic":"10/1/3","payload":true,"devicename":"local bus","payloadmeasureunit":"unknown","payloadsubtypevalue":"On","knx":{"event":"GroupValue_Write","dpt":"1.001","dptdesc":"Switch","source":"1.1.1","destination":"10/1/3","rawValue":[1]},"_msgid":"56649462.bbe86c"}

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db89819e47274c2d5b2d95976031ed445912b8e3.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 July 2022 19:41 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/7 "2022-07-14T19:41:07Z")

</div>

I am confused, what has that got to do with determining whether there is an alarm state or not?

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [14 July 2022 20:20 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/8 "2022-07-14T20:20:55Z")

</div>

It is an example of a working KNX device that uses the same Data type the Mathias should see with his device.

@mathias-ewald are you monitoring via ETS group monitor to see 0/1 values ?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 July 2022 20:29 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/9 "2022-07-14T20:29:21Z")

</div>

Oh, sorry, I thought that message had come from the OP.

In terms of detecting the alarm it doesn't matter what is in the message if using the Trigger node technique that I suggested. It is just a matter of distinguishing between a stream of messages and no messages.

---

<div class="post-metadata">

### Author: ![mathias-ewald](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathias-ewald/32/64611_2.png) [@mathias-ewald](https://discourse.nodered.org/u/mathias-ewald)
#### Post date: [15 July 2022 06:07 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/10 "2022-07-15T06:07:51Z")

</div>

Good morning 🙂 I think my KNX node works fine. I double checked the data I am seeing: It is actually true/false (not 0/1) that I am getting in Node-RED.

I tried the approach with the Trigger, but the result doesn't seem to be right. I used an Inject node at a 1s interval and a Function node to generate the true/false sequence for testing since I don't want to have to spill water behind my washing machine every time to test the flow 😃 I might have configured the Trigger node wrong but I still get alternating true/false from it just with a delay:

```auto
[
    {
        "id": "9da7dd49afa1d6a5",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "dd3b7f2116359ec3",
        "type": "inject",
        "z": "9da7dd49afa1d6a5",
        "name": "Clock",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 210,
        "y": 280,
        "wires": [
            [
                "b921967f8d5c1620"
            ]
        ]
    },
    {
        "id": "b921967f8d5c1620",
        "type": "function",
        "z": "9da7dd49afa1d6a5",
        "name": "True/False",
        "func": "msg.payload = context.get(\"alternate\") || false;\nmsg.payload = (msg.payload === false) ? true : false;\ncontext.set(\"alternate\", msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 280,
        "wires": [
            [
                "14f68eda2ef8d1d6"
            ]
        ]
    },
    {
        "id": "c3f1d5fed9ba2bc8",
        "type": "debug",
        "z": "9da7dd49afa1d6a5",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 280,
        "wires": []
    },
    {
        "id": "14f68eda2ef8d1d6",
        "type": "trigger",
        "z": "9da7dd49afa1d6a5",
        "name": "",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 620,
        "y": 280,
        "wires": [
            [
                "c3f1d5fed9ba2bc8"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [15 July 2022 07:25 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/11 "2022-07-15T07:25:47Z")

</div>

> [@mathias-ewald](#):
>
> I might have configured the Trigger node wrong

Sorry, I should have said to set 'Extend delay if new message arrives'. That stops it sending the false message until no input is received for 5 seconds.

---

<div class="post-metadata">

### Author: ![mathias-ewald](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathias-ewald/32/64611_2.png) [@mathias-ewald](https://discourse.nodered.org/u/mathias-ewald)
#### Post date: [15 July 2022 08:09 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/12 "2022-07-15T08:09:47Z")

</div>

Nice. I read that option but didn't understand its purpose. Works now, thanks!

---

<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: [29 July 2022 08:10 UTC](https://discourse.nodered.org/t/knx-water-leakage-sensor-convert-alternating-0-1-to-alarm-flag/65100/13 "2022-07-29T08:10:36Z")

</div>

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