/
/
/
1# Glances - Sensors for {{ ha_display_name }}
2# Auto-generated by monitoring role deployment
3#
4# Integration setup: Settings > Integrations > Add > Glances
5# Host: {{ inventory_hostname }}.home
6# Port: {{ glances_web_port }}
7# SSL: disabled | Version: 4 | Verify SSL: unchecked
8#
9# The Glances integration creates entities with prefix: {{ ha_entity_prefix }}_
10# Examples:
11# sensor.{{ ha_entity_prefix }}_cpu_usage - CPU usage %
12# sensor.{{ ha_entity_prefix }}_memory_usage - Memory usage %
13# sensor.{{ ha_entity_prefix }}_{{ ha_temp_entity_suffix }} - CPU temp
14# sensor.{{ ha_entity_prefix }}_containers_active - Docker containers
15# sensor.{{ ha_entity_prefix }}_uptime - Uptime (timestamp)
16# sensor.{{ ha_entity_prefix }}_wlan0_rx / _tx - WiFi I/O
17{% if glances_gpu_monitoring | bool and ha_gpu_entity_slug %}
18# sensor.{{ ha_entity_prefix }}_{{ ha_gpu_entity_slug }}_processor_usage - GPU utilization %
19# sensor.{{ ha_entity_prefix }}_{{ ha_gpu_entity_slug }}_memory_usage - GPU VRAM usage %
20# sensor.{{ ha_entity_prefix }}_{{ ha_gpu_entity_slug }}_temperature - GPU temperature
21{% endif %}
22#
23# The sensors below supplement the integration with system identification
24# data not exposed by the native integration.
25
26# --- Binary sensor: online/offline status ---
27# Add under your existing template: section in configuration.yaml
28
29template:
30 - binary_sensor:
31 - name: "{{ ha_display_name }} Online"
32 unique_id: glances_{{ ha_integration_name }}_online
33 state: >-
34 {{ '{{' }} states('sensor.{{ ha_entity_prefix }}_cpu_usage') not in ['unavailable', 'unknown'] {{ '}}' }}
35 device_class: connectivity
36{% if glances_gpu_monitoring | bool and ha_gpu_entity_slug %}
37 - sensor:
38 - name: "{{ ha_display_name }} VRAM Usage"
39 unique_id: glances_{{ ha_integration_name }}_vram_usage
40 state: >-
41 {{ '{{' }} states('sensor.{{ ha_entity_prefix }}_{{ ha_gpu_entity_slug }}_memory_usage') | float(0) | round(1) {{ '}}' }}
42 unit_of_measurement: "%"
43 icon: mdi:memory
44{% endif %}
45
46# --- REST sensors: system identification ---
47# Add as top-level rest: entries in configuration.yaml
48
49rest:
50 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/quicklook
51 scan_interval: 60
52 sensor:
53 - name: "{{ ha_display_name }} CPU Name"
54 unique_id: glances_{{ ha_integration_name }}_cpu_name
55 value_template: >-
56 {{ '{{' }} value_json.cpu_name | default('Unknown') {{ '}}' }}
57 icon: mdi:chip
58 - name: "{{ ha_display_name }} CPU Cores"
59 unique_id: glances_{{ ha_integration_name }}_cpu_cores
60 value_template: >-
61 {{ '{{' }} value_json.cpu_log_core | default(0) {{ '}}' }}
62 icon: mdi:cpu-64-bit
63
64 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/mem
65 scan_interval: 60
66 sensor:
67 - name: "{{ ha_display_name }} Memory Total"
68 unique_id: glances_{{ ha_integration_name }}_memory_total
69 value_template: >-
70 {{ '{{' }} (value_json.total | float(0) / 1073741824) | round(1) {{ '}}' }}
71 unit_of_measurement: "GB"
72 icon: mdi:memory
73
74 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/system
75 scan_interval: 300
76 sensor:
77 - name: "{{ ha_display_name }} OS"
78 unique_id: glances_{{ ha_integration_name }}_os
79 value_template: >-
80 {{ '{{' }} value_json.linux_distro | default(value_json.hr_name | default('Unknown')) {{ '}}' }}
81 icon: mdi:linux
82 - name: "{{ ha_display_name }} Kernel"
83 unique_id: glances_{{ ha_integration_name }}_kernel
84 value_template: >-
85 {{ '{{' }} value_json.os_version | default('Unknown') {{ '}}' }}
86 icon: mdi:cog
87{% if glances_gpu_monitoring | bool %}
88
89 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/gpu
90 scan_interval: 15
91 sensor:
92 - name: "{{ ha_display_name }} GPU Name"
93 unique_id: glances_{{ ha_integration_name }}_gpu_name
94 value_template: >-
95 {{ '{{' }} value_json[0].name | default('Unknown') if value_json is iterable and value_json | length > 0 else 'N/A' {{ '}}' }}
96 icon: mdi:expansion-card
97{% endif %}
98{% if glances_storage_monitoring %}
99
100 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/raid
101 scan_interval: 60
102 sensor:
103 - name: "{{ ha_display_name }} RAID Status"
104 unique_id: glances_{{ ha_integration_name }}_raid_status
105 value_template: >-
106 {{ '{%' }} if value_json and value_json.keys() | list | length > 0 {{ '%}' }}
107 {{ '{%' }} set raid_name = value_json.keys() | list | first {{ '%}' }}
108 {{ '{{' }} value_json[raid_name].status | default("unknown") {{ '}}' }}
109 {{ '{%' }} else {{ '%}' }}
110 No RAID
111 {{ '{%' }} endif {{ '%}' }}
112 icon: mdi:harddisk-plus
113 - name: "{{ ha_display_name }} RAID Type"
114 unique_id: glances_{{ ha_integration_name }}_raid_type
115 value_template: >-
116 {{ '{%' }} if value_json and value_json.keys() | list | length > 0 {{ '%}' }}
117 {{ '{%' }} set raid_name = value_json.keys() | list | first {{ '%}' }}
118 {{ '{{' }} value_json[raid_name].type | default("unknown") | upper {{ '}}' }}
119 {{ '{%' }} else {{ '%}' }}
120 N/A
121 {{ '{%' }} endif {{ '%}' }}
122 icon: mdi:harddisk-plus
123 - name: "{{ ha_display_name }} RAID Drives"
124 unique_id: glances_{{ ha_integration_name }}_raid_drives
125 value_template: >-
126 {{ '{%' }} if value_json and value_json.keys() | list | length > 0 {{ '%}' }}
127 {{ '{%' }} set raid_name = value_json.keys() | list | first {{ '%}' }}
128 {{ '{{' }} value_json[raid_name].used | default(0) {{ '}}' }}/{{ '{{' }} value_json[raid_name].available | default(0) {{ '}}' }}
129 {{ '{%' }} else {{ '%}' }}
130 N/A
131 {{ '{%' }} endif {{ '%}' }}
132 icon: mdi:harddisk-plus
133 - name: "{{ ha_display_name }} RAID Config"
134 unique_id: glances_{{ ha_integration_name }}_raid_config
135 value_template: >-
136 {{ '{%' }} if value_json and value_json.keys() | list | length > 0 {{ '%}' }}
137 {{ '{%' }} set raid_name = value_json.keys() | list | first {{ '%}' }}
138 {{ '{{' }} value_json[raid_name].config | default("unknown") {{ '}}' }}
139 {{ '{%' }} else {{ '%}' }}
140 N/A
141 {{ '{%' }} endif {{ '%}' }}
142 icon: mdi:harddisk-plus
143
144 - resource: http://{{ inventory_hostname }}.home:{{ glances_web_port }}/api/4/smart
145 scan_interval: 120
146 sensor:
147{% for drive in glances_storage_drives %}
148 - name: "{{ ha_display_name }} {{ drive.label }} Temp"
149 unique_id: glances_{{ ha_integration_name }}_{{ drive.device }}_temp
150 value_template: >-
151 {{ '{%' }} set ns = namespace(temp='N/A') {{ '%}' }}
152 {{ '{%' }} for disk in value_json if disk.DeviceName is defined and '{{ drive.device }}' in disk.DeviceName {{ '%}' }}
153 {{ '{%' }} if '194' in disk {{ '%}' }}
154 {{ '{%' }} set ns.temp = disk['194'].raw | string | regex_findall('\\d+') | first | default(0) {{ '%}' }}
155 {{ '{%' }} elif '2' in disk and disk['2'].key is defined and disk['2'].key == '_temperature' {{ '%}' }}
156 {{ '{%' }} set ns.temp = disk['2'].raw | default(0) {{ '%}' }}
157 {{ '{%' }} endif {{ '%}' }}
158 {{ '{%' }} endfor {{ '%}' }}
159 {{ '{{' }} ns.temp {{ '}}' }}
160 unit_of_measurement: "°C"
161 icon: mdi:thermometer
162 - name: "{{ ha_display_name }} {{ drive.label }} Health"
163 unique_id: glances_{{ ha_integration_name }}_{{ drive.device }}_health
164 value_template: >-
165 {{ '{%' }} set ns = namespace(found=false, status='Unknown') {{ '%}' }}
166 {{ '{%' }} for disk in value_json if disk.DeviceName is defined and '{{ drive.device }}' in disk.DeviceName {{ '%}' }}
167 {{ '{%' }} set ns.found = true {{ '%}' }}
168 {{ '{%' }} set realloc = disk['5'].raw | string | regex_findall('\\d+') | first | default('0') | int if '5' in disk else 0 {{ '%}' }}
169 {{ '{%' }} set pending = disk['197'].raw | string | regex_findall('\\d+') | first | default('0') | int if '197' in disk else 0 {{ '%}' }}
170 {{ '{%' }} if realloc > 0 or pending > 0 {{ '%}' }}
171 {{ '{%' }} set ns.status = 'Warning' {{ '%}' }}
172 {{ '{%' }} else {{ '%}' }}
173 {{ '{%' }} set ns.status = 'Healthy' {{ '%}' }}
174 {{ '{%' }} endif {{ '%}' }}
175 {{ '{%' }} endfor {{ '%}' }}
176 {{ '{{' }} ns.status if ns.found else 'Unknown' {{ '}}' }}
177 icon: mdi:harddisk
178 - name: "{{ ha_display_name }} {{ drive.label }} Power Hours"
179 unique_id: glances_{{ ha_integration_name }}_{{ drive.device }}_power_hours
180 value_template: >-
181 {{ '{%' }} set ns = namespace(hours=0) {{ '%}' }}
182 {{ '{%' }} for disk in value_json if disk.DeviceName is defined and '{{ drive.device }}' in disk.DeviceName {{ '%}' }}
183 {{ '{%' }} if '9' in disk {{ '%}' }}
184 {{ '{%' }} set ns.hours = disk['9'].raw | string | regex_findall('\\d+') | first | default(0) {{ '%}' }}
185 {{ '{%' }} elif '14' in disk and disk['14'].key is defined and disk['14'].key == 'powerOnHours' {{ '%}' }}
186 {{ '{%' }} set ns.hours = disk['14'].raw | default(0) {{ '%}' }}
187 {{ '{%' }} endif {{ '%}' }}
188 {{ '{%' }} endfor {{ '%}' }}
189 {{ '{{' }} ns.hours {{ '}}' }}
190 unit_of_measurement: "h"
191 icon: mdi:clock-outline
192{% endfor %}
193{% endif %}
194