-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpsmqtt.yaml
181 lines (155 loc) · 7.19 KB
/
psmqtt.yaml
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
#
# PSMQTT configuration file
# All values shown here are the default values
#
logging:
level: INFO
# psmqtt will report its own status (e.g. number of errors) every N seconds on its log output
# and on the specific '<mqtt.publish_topic_prefix>/status' topic
report_status_period_sec: 10
mqtt:
# broker: details about the MQTT broker
broker:
host: localhost
port: 1883
#username:
#password:
# client_id: the identifier of the MQTT client created by psmqtt; this is useful to identify psmqtt
# when inspecting the MQTT broker logs
clientid: psmqtt
# clean_session: If "true", the broker will remove all information about this client when it disconnects.
# If "false", the client is a persistent client and subscription information and queued messages will
# be retained when the client disconnects
clean_session: false
# qos: it can be:
# - At most once (QoS 0)
# - At least once (QoS 1)
# - Exactly once (QoS 2)
# see https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels/
qos: 0
# retain: if set to true, the message will be set as the "last known good"/retained message for
# each topic populated by psmqtt
retain: false
# reconnect_period_sec: defines how frequently psmqtt will re-attempt a connection to the MQTT broker
# if the connection is lost. You should be setting this parameter to the smallest value that makes sense
# according to your PSMQTT scheduling rules.
reconnect_period_sec: 5
# request: name of the topic that psmqtt will subscribe to, and where it will wait for information requests;
# to activate the request just send any payload message (e.g. "REQUEST") to a topic like:
# <psmqtt/COMPUTER_NAME/request/cpu_percent>.
request_topic: "psmqtt/request/"
# publish_topic_prefix: defines the prefix for all published topics;
# if not provided, it defaults to "psmqtt/<hostname>/"
#publish_topic_prefix:
ha_discovery:
# ha_discovery.enabled: if set to true, psmqtt will publish a "homeassistant" MQTT discovery topic
# for each task having the 'ha_discovery' configuration parameters set.
# This will enable HomeAssistant to immediately recognize as sensors the information published by psmqtt
# (see https://www.home-assistant.io/integrations/sensor.mqtt/)
enabled: true
# ha_discovery.topic: defines the topic that psmqtt will publish its "homeassistant" MQTT discovery topics;
topic: homeassistant
# ha_discovery.device_name: the name of the device grouping all sensors published to HomeAssistant;
# it defaults to the <hostname> of the computer
#device_name:
options:
# exit_after_num_tasks: this configuration parameter is used to simulate the "psmqtt-publish.py" script variant that was
# provided in the past by psmqtt project; if exit_after_num_tasks=N, psmqtt will gracefully exit after
# publishing all data associated with N tasks, that are executed according to usual scheduling rules.
# The special value ZERO indicates that psmqtt publish tasks indefinitively, until stopped via SIGTERM.
exit_after_num_tasks: 0
schedule:
# each scheduling rule is defined by a cron expression and a list of tasks to be executed;
# the "cron" expression is a human-friendly expression, see https://github.com/kvh/recurrent/tree/master
# for example of supported syntaxes
- cron: "every 10 seconds"
tasks:
# each task is defined by
# * "task": the name (see PSMQTT docs for full list of available task handlers);
# * "params": optional task parameters (e.g. percentage or absolute value, the name of an hard drive or the index of a CPU, etc);
# * "topic": optional MQTT topic name; if this is not provided, the task name and all its parameters will be used as MQTT topic;
# * "formatter": optional formatter expression, which is a Jinja2 expression
# see "Usage docs" for more details
# simple task requesting to publish virtual_memory percentage into a topic named "foobar"
- task: virtual_memory
params: [ percent ]
topic: foobar
# task with 2 parameters, no formatter, no HA discovery message configuration:
- task: sensors_temperatures
params: [ coretemp, 0 ] # use "coretemp" sensor for CPU core 0
# task with 1 parameter, no formatter, HA discovery message configuration:
- task: cpu_percent
params: [ total ]
ha_discovery:
name: "CPU Percentage"
platform: sensor
unit_of_measurement: "%"
icon: mdi:speedometer
# task with 1 parameter, no formatter, HA discovery message configuration:
- task: virtual_memory
params: [ percent ]
ha_discovery:
name: "Memory Percentage"
platform: sensor
unit_of_measurement: "%"
icon: mdi:memory
# task with 2 parameters, no formatter, HA discovery message configuration:
- task: smart
params: [ /dev/nvme0, temperature ] # report only the "temperature" SMART attribute of "/dev/nvme0"
ha_discovery:
name: "NVMe0 Temperature"
platform: sensor
device_class: temperature
unit_of_measurement: "°C"
icon: mdi:thermometer
# task requesting ALL available SMART attributes of a specific disk to be published as individual topics
- task: smart
params: [ /dev/sda, "*" ]
topic: "/sda_smart_status/*"
# ha_discovery not supported for messages with wildcards
# task requesting ALL available SMART attributes of a specific disk to be published as a single topic with JSON payload
- task: smart
params: [ /dev/sda, "+" ]
topic: "/sda_smart_status"
# ha_discovery not supported for messages with wildcards
# task requesting to publish the result of the last SMART test, complete with HA discovery message configuration:
- task: smart
params: [ /dev/sda, "test[0]" ]
formatter: "{{hours}}"
topic: "sda_info_last_test"
ha_discovery:
name: "SDA SMART Test"
platform: sensor
device_class: duration
unit_of_measurement: "hours"
icon: mdi:clock
# task requesting to publish the overall SMART status, complete with HA discovery message configuration:
- task: smart
params: [ /dev/sda, smart_status ]
ha_discovery:
name: "SDA SMART Status"
platform: binary_sensor
payload_on: FAIL # the "on" condition indicates a problem, so associate it with the "FAIL" status of SMART test
payload_off: PASS
device_class: problem
icon: mdi:harddisk
- cron: "every 60 minutes"
tasks:
- task: disk_usage
params: [ percent, "/" ]
ha_discovery:
name: "Root Disk Usage"
platform: sensor
unit_of_measurement: "%"
icon: mdi:harddisk
- cron: "every 3 hours"
tasks:
# task with a Jinja2 formatter; single or double-quoting is necessary
- task: boot_time
formatter: "{{x|iso8601_str}}"
ha_discovery:
name: "Uptime"
platform: sensor
device_class: timestamp
icon: mdi:calendar
value_template: "{{ as_datetime(value) }}"