-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathpixelix_send_sensor_data.yaml
More file actions
473 lines (454 loc) · 17.2 KB
/
pixelix_send_sensor_data.yaml
File metadata and controls
473 lines (454 loc) · 17.2 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
blueprint:
# https://www.home-assistant.io/docs/blueprint/schema/
# https://www.home-assistant.io/docs/automation/basics/
name: Pixelix - Send sensor data to Pixelix device
description: |
# Pixelix Automation Blueprint
This blueprint allows you to monitor multiple sensors in realtime on Pixelix.
You can choose between the JustText, IconText or IconTextLamp plugin to display the sensor data.
domain: automation
author: Pixelix & Friends <https://github.com/BlueAndi/Pixelix>
source_url: https://www.blue-andi.de/vscp/pixelix_send_sensor_data.yaml
homeassistant:
min_version: 2024.10.0
# https://www.home-assistant.io/docs/blueprint/selectors/
input:
section_general:
name: General Section
description: General configuration independed of using REST or MQTT API.
input:
plugin_type:
name: Plugin Type
description: The type of the plugin.
selector:
select:
options:
- label: JustText Plugin
value: justtext
- label: IconText Plugin
value: icontext
- label: IconTextLamp Plugin
value: icontextlamp
uid:
name: Plugin UID
description: |
The plugin UID of the plugin instance. See display page in the Pixelix web interface.
0 means invalid UID, like UID not set.
If both UID and alias are set, the alias is used.
default: 0
selector:
number:
min: 0
max: 65535
mode: box
alias:
name: Plugin Alias
description: |
The plugin alias of the plugin instance. See display page in the Pixelix web interface.
If both UID and alias are set, the alias is used.
default: ''
selector:
text:
sensors:
name: Sensors
description: The sensors to monitor in realtime.
selector:
entity:
multiple: true
user_triggers:
name: User Triggers
description: Additional triggers defined by the user.
default:
selector:
trigger:
user_conditions:
name: User Conditions
description: User defined conditions for the automation.
default: []
selector:
condition:
icon_selector:
name: Icon Selector
description: 'Optional: Keep current icon or change it. Only used by IconText and IconTextLamp plugins.'
default: keep
selector:
select:
options:
- label: Keep current icon
value: keep
- label: Change icon
value: change
icon_file_id:
name: Icon File ID
description: |
The file ID of the icon to display.
See Pixelix icons web page for the available icons.
255 means no icon.
A icon is only supported by IconText and IconTextLamp plugins.
default: 255
selector:
text:
horizontal_alignment:
name: Horizontal Alignment
description: The horizontal alignment of the text.
default: default
selector:
select:
options:
- label: Default
value: default
- label: Left
value: hl
- label: Center
value: hc
- label: Right
value: hr
vertical_alignment:
name: Vertical Alignment
description: The vertical alignment of the text.
default: default
selector:
select:
options:
- label: Default
value: default
- label: Top
value: vt
- label: Center
value: vc
- label: Bottom
value: vb
prefix_text:
name: Prefix Text
description: 'Optional: The text to display before the sensor value(s).'
default: ''
selector:
text:
suffix_text:
name: Suffix Text
description: 'Optional: The text to display after the sensor value(s).'
default: ''
selector:
text:
sensor_labels:
name: Sensor labels
description: 'Optional: The labels of the sensors. Please use \"-\" before each entry and add as many entries as the number of your selected sensors. Each line should contain one entry.'
default: []
selector:
object:
section_color:
name: Color Section
description: Configuration of the text color.
input:
color_selector:
name: Color Selector
description: The color selector of the text.
default: default
selector:
select:
options:
- label: Default
value: default
- label: Solid Color
value: solid_color
- label: Linear Gradient Color
value: linear_gradient_color
solid_color:
name: Color of the solid color brush
description: The solid color of the text.
default: "#FFFFFF"
selector:
text:
type: color
linear_gradient_color1:
name: Color 1 of the linear gradient brush
description: The first color of the linear gradient of the text.
default: "#FF0000"
selector:
text:
type: color
linear_gradient_color2:
name: Color 2 of the linear gradient brush
description: The second color of the linear gradient of the text.
default: "#0000FF"
selector:
text:
type: color
linear_gradient_direction:
name: Gradient Direction
description: 'Optional: The gradient direction of the text color.'
default: vertical
selector:
select:
options:
- label: Vertical (Top to bottom)
value: vertical
- label: Horizontal (Left to right)
value: horizontal
linear_gradient_offset:
name: Gradient Offset
description: 'Optional: The offset of the gradient in pixels.'
default: 0
selector:
number:
min: 0
max: 32767
mode: box
linear_gradient_length:
name: Gradient Length
description: 'Optional: The length of the gradient in pixels.'
default: 32
selector:
number:
min: 0
max: 65535
mode: box
section_protocol:
name: Protocol Section
description: |
# Protocol specific configuration.
## MQTT API
For the communication to Pixelix via MQTT API, you need to install the MQTT integration in Home Assistant and
configure it to connect to your MQTT broker.
Enable MQTT in Pixelix via the settings web page. Pixelix uses the MQTT automatic discovery feature.
## REST API
For the REST API add the following REST command to your configuration.yaml in Home Assistant.
It will be called by the automation blueprint.
```yaml
rest_command:
pixelix_plugin_command:
url: "http://{{ hostname }}{{ endpoint }}?{{ url_parameter }}"
method: POST
```
input:
protocol:
name: Communication Protocol
description: The protocol to use for communication.
default: mqtt
selector:
select:
options:
- label: MQTT API
value: mqtt
- label: REST API
value: rest
pixelix_device:
name: MQTT Pixelix device
description: |
The Pixelix device to use for MQTT communication.
Only used by MQTT API protocol selection.
default:
selector:
device:
integration: mqtt
manufacturer: BlueAndi & Friends
model: Pixelix
pixelix_hostname:
name: Pixelix Hostname
description: |
Enter the hostname (e.g. pixelix-FFFFFFFF or 192.168.178.110) of the Pixelix device.
Only used by REST API protocol selection.
default: ""
selector:
text:
variables:
var_plugin_type: !input plugin_type
var_uid: !input uid
var_alias: !input alias
var_sensors: !input sensors
var_icon_selector: !input icon_selector
var_icon_file_id: !input icon_file_id
var_horizontal_alignment: !input horizontal_alignment
var_vertical_alignment: !input vertical_alignment
var_color_selector: !input color_selector
var_prefix_text: !input prefix_text
var_suffix_text: !input suffix_text
var_sensor_labels: !input sensor_labels
var_protocol: !input protocol
var_solid_color: !input solid_color
var_linear_gradient_color1: !input linear_gradient_color1
var_linear_gradient_color2: !input linear_gradient_color2
var_linear_gradient_direction: !input linear_gradient_direction
var_linear_gradient_offset: !input linear_gradient_offset
var_linear_gradient_length: !input linear_gradient_length
var_device: !input pixelix_device
var_hostname: !input pixelix_hostname
var_alignment: >-
{% set horizontal_alignment = var_horizontal_alignment %}
{% set vertical_alignment = var_vertical_alignment %}
{% set alignment = 'default' %}
{% if horizontal_alignment != 'default' %}
{% set alignment = horizontal_alignment %}
{% endif %}
{% if vertical_alignment != 'default' %}
{% if alignment != '' %}
{% set alignment = alignment + vertical_alignment %}
{% else %}
{% set alignment = vertical_alignment %}
{% endif %}
{% endif %}
{{ alignment }}
var_color_tag: >-
{% set color_selector = var_color_selector %}
{% set solid_color = var_solid_color %}
{% set linear_gradient_color1 = var_linear_gradient_color1 %}
{% set linear_gradient_color2 = var_linear_gradient_color2 %}
{% set linear_gradient_direction = var_linear_gradient_direction %}
{% set linear_gradient_offset = var_linear_gradient_offset %}
{% set linear_gradient_length = var_linear_gradient_length %}
{% set color_tag = 'default' %}
{% if color_selector == 'solid_color' %}
{% set color_tag = solid_color %}
{% elif color_selector == 'linear_gradient_color' %}
{% if linear_gradient_direction == 'vertical' %}
{% set color_tag = 'lgv ' + linear_gradient_color1 + ',' + linear_gradient_color2 + ',' + linear_gradient_offset|string + ',' + linear_gradient_length|string %}
{% else %}
{% set color_tag = 'lgh ' + linear_gradient_color1 + ',' + linear_gradient_color2 + ',' + linear_gradient_offset|string + ',' + linear_gradient_length|string %}
{% endif %}
{% endif %}
{{ color_tag }}
var_plugin_topic: >-
{% set plugin_type = var_plugin_type %}
{% set plugin_topic = '' %}
{% if plugin_type == 'justtext' %}
{% set plugin_topic = 'text' %}
{% else %}
{% set plugin_topic = 'iconText' %}
{% endif %}
{{ plugin_topic }}
var_text: >-
{% set sensors = var_sensors %}
{% set prefix_text = var_prefix_text %}
{% set suffix_text = var_suffix_text %}
{% set sensor_labels = var_sensor_labels %}
{% set alignment = var_alignment %}
{% set color_tag = var_color_tag %}
{% set ns = namespace(texts = [], tags = []) %}
{% if alignment != 'default' %}
{% set ns.tags = ns.tags + [alignment] %}
{% endif %}
{% if color_tag != 'default' %}
{% set ns.tags = ns.tags + [color_tag] %}
{% endif %}
{% if prefix_text != '' %}
{% set ns.texts = ns.texts + [prefix_text] %}
{% endif %}
{% for sensor in sensors %}
{% set state = states(sensor) %}
{% set unit = state_attr(sensor, 'unit_of_measurement') %}
{% set label = '' %}
{% if ((sensor_labels is defined) and (loop.index <= sensor_labels|length)) %}
{% set label = sensor_labels[loop.index - 1] %}
{% endif %}
{% if (state != 'unknown') and (state != 'unavailable') %}
{% if label != '' %}
{% set state = label + ':' + state %}
{% endif %}
{% if unit != None %}
{% set ns.texts = ns.texts + [state + unit] %}
{% else %}
{% set ns.texts = ns.texts + [state] %}
{% endif %}
{% endif %}
{% endfor %}
{% if suffix_text != '' %}
{% set ns.texts = ns.texts + [suffix_text] %}
{% endif %}
{{ ns.tags | map('regex_replace', '^(.*)$', '{\\1}') | join() }}{{ ns.texts | join(' ') }}
var_mqtt_payload: >-
{% set icon_selector = var_icon_selector %}
{% set icon_file_id = var_icon_file_id %}
{% set text = var_text %}
{% if (icon_selector == 'change') and ((var_plugin_type == 'icontext') or (var_plugin_type == 'icontextlamp')) %}
{"iconFileId": {{ icon_file_id }}, "text": "{{ text }}"}
{% else %}
{"text": "{{ text }}"}
{% endif %}
var_rest_url_parameter: >-
{% set icon_selector = var_icon_selector %}
{% set icon_file_id = var_icon_file_id %}
{% set text = var_text %}
{% if (icon_selector == 'change') and ((var_plugin_type == 'icontext') or (var_plugin_type == 'icontextlamp')) %}
{{ ("iconFileId=" + icon_file_id + "&text=" + text) | urlencode() }}
{% else %}
{{ ("text=" + text) | urlencode() }}
{% endif %}
# https://www.home-assistant.io/docs/automation/trigger/
triggers:
- trigger: state
entity_id: !input sensors
- trigger: homeassistant
event: start
id: update
- trigger: event
event_type: automation_reloaded
id: update
# Merge user defined triggers
- triggers: !input user_triggers
# https://www.home-assistant.io/docs/automation/condition/
conditions: !input user_conditions
# https://www.home-assistant.io/docs/automation/action/
actions:
- choose:
# Use MQTT API with plugin UID
- conditions:
- condition: template
value_template: "{{ var_protocol == 'mqtt' }}"
- condition: template
value_template: "{{ var_device and var_hostname == '' }}"
- condition: template
value_template: "{{ (var_alias == '') or (var_uid != 0) }}"
sequence:
- action: mqtt.publish
data:
topic: "{{ device_attr(var_device, 'name') }}/display/uid/{{ var_uid }}/{{ var_plugin_topic }}/set"
payload: "{{ var_mqtt_payload }}"
# Use MQTT API with plugin alias
- conditions:
- condition: template
value_template: "{{ var_protocol == 'mqtt' }}"
- condition: template
value_template: "{{ var_device and var_hostname == '' }}"
- condition: template
value_template: "{{ (var_alias != '') or (var_uid == 0) }}"
sequence:
- action: mqtt.publish
data:
topic: "{{ device_attr(var_device, 'name') }}/display/alias/{{ var_alias }}/{{ var_plugin_topic }}/set"
payload: "{{ var_mqtt_payload }}"
# Use REST API with plugin UID
- conditions:
- condition: template
value_template: "{{ var_protocol == 'rest' }}"
- condition: template
value_template: "{{ var_device is none and var_hostname != '' }}"
- condition: template
value_template: "{{ (var_alias == '') or (var_uid != 0) }}"
sequence:
- action: rest_command.pixelix_plugin_command
data:
hostname: "{{ var_hostname }}"
endpoint: "/rest/api/v1/display/uid/{{ var_uid }}/{{ var_plugin_topic }}"
url_parameter: "{{ var_rest_url_parameter }}"
# Use REST API with plugin alias
- conditions:
- condition: template
value_template: "{{ var_protocol == 'rest' }}"
- condition: template
value_template: "{{ var_device is none and var_hostname != '' }}"
- condition: template
value_template: "{{ (var_alias != '') or (var_uid == 0) }}"
sequence:
- action: rest_command.pixelix_plugin_command
data:
hostname: "{{ var_hostname }}"
endpoint: "/rest/api/v1/display/alias/{{ var_alias }}/{{ var_plugin_topic }}"
url_parameter: "{{ var_rest_url_parameter }}"
# Default
default:
- service: persistent_notification.create
data:
title: "Pixelix Automation Notification"
message: "Error: Could not send text to Pixelix device. Please check your configuration."
# https://www.home-assistant.io/docs/automation/modes/
mode: single