Zigbee Button in Node-RED

In this short article I show how to use a Zigbee button to control automations in Node-RED.

The Button and Home Assistant

I am using the Aqara Wireless Mini Switch from Xiaomi. This is a Zigbee button that is integrated in my Home Assistant via deConz.

Such buttons are not added as entities in the Home Assistant like other devices. Instead, events are triggered when the button is pressed. These events can then be used as triggers for automations.

Usage in Node-RED

The Flow in Node-RED consists of three necessary nodes and four optional nodes. Flow Overview

First, I use an events: all node to catch the events of type “deconz_event”.

Event Node

Next, a switch node is used to filter for the button’s Id in ‘msg.payload.event.id’. The id is derived from the name given in the Phoscon interface.

Switch Node for Button ID

Thirdly, the type of event is filtered with another switch node. The Aqara button returns these four events:

Event Description
1002 single click
1004 double click
1001 hold
1003 release

Switch Node for Event Nummer

Now you can connect your flows directly to the corresponding outputs of the second switch node. But since I can never remember which number stands for which click, I added delay nodes, which are configured to rate limit. This does not affect the flow, they are just to make programming easier for me.

And here is the whole flow to import:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[
	{
		"id": "9b4d7173.f7538",
		"type": "server-events",
		"z": "e0fe8a5c.1c4ed8",
		"name": "DeconzEvent",
		"server": "db71ae1a.4969e",
		"event_type": "deconz_event",
		"x": 110,
		"y": 140,
		"wires": [
			[
				"92b4d903.eda7f8"
			]
		]
	},
	{
		"id": "92b4d903.eda7f8",
		"type": "switch",
		"z": "e0fe8a5c.1c4ed8",
		"name": "ID auslesen",
		"property": "payload.event.id",
		"propertyType": "msg",
		"rules": [
			{
				"t": "eq",
				"v": "smart_switch",
				"vt": "str"
			}
		],
		"checkall": "true",
		"repair": false,
		"outputs": 1,
		"x": 310,
		"y": 140,
		"wires": [
			[
				"bf4a2cc8.ced0c"
			]
		]
	},
	{
		"id": "bf4a2cc8.ced0c",
		"type": "switch",
		"z": "e0fe8a5c.1c4ed8",
		"name": "Event auslesen",
		"property": "payload.event.event",
		"propertyType": "msg",
		"rules": [
			{
				"t": "eq",
				"v": "1002",
				"vt": "str"
			},
			{
				"t": "eq",
				"v": "1004",
				"vt": "str"
			},
			{
				"t": "eq",
				"v": "1001",
				"vt": "str"
			},
			{
				"t": "eq",
				"v": "1003",
				"vt": "str"
			}
		],
		"checkall": "true",
		"repair": false,
		"outputs": 4,
		"x": 560,
		"y": 140,
		"wires": [
			[
				"db107f64.bbcf6"
			],
			[
				"7b49a1f5.e5728"
			],
			[
				"2f180c9f.1abab4"
			],
			[
				"cc777d04.e73a4"
			]
		]
	},
	{
		"id": "db107f64.bbcf6",
		"type": "delay",
		"z": "e0fe8a5c.1c4ed8",
		"name": "Klick",
		"pauseType": "rate",
		"timeout": "1",
		"timeoutUnits": "seconds",
		"rate": "1",
		"nbRateUnits": "1",
		"rateUnits": "second",
		"randomFirst": "1",
		"randomLast": "5",
		"randomUnits": "seconds",
		"drop": false,
		"x": 790,
		"y": 120,
		"wires": [
			[
				"5ee59413.880bac",
				"288d2bb8.d00f44"
			]
		]
	},
	{
		"id": "7b49a1f5.e5728",
		"type": "delay",
		"z": "e0fe8a5c.1c4ed8",
		"name": "Doppel-Klick",
		"pauseType": "rate",
		"timeout": "1",
		"timeoutUnits": "seconds",
		"rate": "1",
		"nbRateUnits": "1",
		"rateUnits": "second",
		"randomFirst": "1",
		"randomLast": "5",
		"randomUnits": "seconds",
		"drop": false,
		"x": 810,
		"y": 160,
		"wires": [
			[
				"c0c2b9f1.29de48",
				"288d2bb8.d00f44"
			]
		]
	},
	{
		"id": "2f180c9f.1abab4",
		"type": "delay",
		"z": "e0fe8a5c.1c4ed8",
		"name": "Halten",
		"pauseType": "rate",
		"timeout": "1",
		"timeoutUnits": "seconds",
		"rate": "1",
		"nbRateUnits": "1",
		"rateUnits": "second",
		"randomFirst": "1",
		"randomLast": "5",
		"randomUnits": "seconds",
		"drop": false,
		"x": 790,
		"y": 200,
		"wires": [
			[]
		]
	},
	{
		"id": "cc777d04.e73a4",
		"type": "delay",
		"z": "e0fe8a5c.1c4ed8",
		"name": "Loslassen",
		"pauseType": "rate",
		"timeout": "1",
		"timeoutUnits": "seconds",
		"rate": "1",
		"nbRateUnits": "1",
		"rateUnits": "second",
		"randomFirst": "1",
		"randomLast": "5",
		"randomUnits": "seconds",
		"drop": false,
		"x": 800,
		"y": 240,
		"wires": [
			[]
		]
	},
	{
		"id": "db71ae1a.4969e",
		"type": "server",
		"z": "",
		"name": "Home Assistant",
		"legacy": false,
		"addon": true,
		"rejectUnauthorizedCerts": true,
		"ha_boolean": "y|yes|true|on|home|open",
		"connectionDelay": true,
		"cacheJson": true
	}
]

Translated with www.DeepL.com/Translator (free version)

updatedupdated2020-08-232020-08-23