Monitor temperature via mqqt/telegraf; Proxmox... No results displayed

I followed this instruction:

Monitor temperature via mqqt/telegraf on proxmox

But at the end I’m not getting results in HA.



telegraf.conf

# Telegraf Configuration

[global_tags]
[agent]
  interval = "60s"  ## Default data collection interval for all inputs
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "5s"
  precision = ""
  hostname = "192.168.1.15"
  omit_hostname = false

##########################################################
#                           OUTPUT PLUGINS
##########################################################

### Configuration for MQTT server to send metrics to
[[outputs.mqtt]]
  servers = ["192.168.1.15:1883"] # required.
  topic = "telegraf"
  qos = 2
### username and password to connect MQTT server.
  username = "mqtt" 
  password = "231264"
  retain = false
  data_format = "json"

#########################################################
#                            INPUT PLUGINS
#########################################################

### Monitor disks' temperatures using hddtemp
[[inputs.hddtemp]]
  address = "127.0.0.1:7634"
  devices = ["sda"] ##Depending on which HDD are connected, you may need to change these

### Monitor sensors, requires lm-sensors package
[[inputs.sensors]]
    timeout = "5s"
root@proxmox:~# hddtemp /dev/sda
/dev/sda: SPCC Solid State Disk: 33°C

root@proxmox:~# sensors
iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:            N/A  

acpitz-acpi-0
Adapter: ACPI interface
temp1:        +61.0°C  (crit = +115.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +47.0°C  (high = +90.0°C, crit = +90.0°C)
Core 1:       +54.0°C  (high = +90.0°C, crit = +90.0°C)
Core 2:       +57.0°C  (high = +90.0°C, crit = +90.0°C)
Core 3:       +51.0°C  (high = +90.0°C, crit = +90.0°C)

root@proxmox:~#

But no any signals/info arrive at HA:

What I’m doing wrong?

I’ll answer myself - wrong ‘topic’ was used… Should be only ‘telegraf’.

I played around with the same instructions and I used MQTT Explorer to discover the topic. I did not like the format of the topic, since it can be confusing for which host it is meant. So I modified the configuration:

# Telegraf Configuration

[global_tags]
[agent]
  interval = "10s"  ## Default data collection interval for all inputs
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "5s"
  precision = ""
  hostname = ""
  omit_hostname = false

##########################################################
#                    OUTPUT PLUGINS                                   
##########################################################

### Configuration for MQTT server to send metrics to
### https://github.com/influxdata/telegraf/blob/56aac4f0e15d195733002e0bc501f229cef9db02/plugins/outputs/mqtt/README.md
[[outputs.mqtt]]
  servers = ["##ADD MQTT SERVER IP HERE##:1883"] # required.
  topic = "telegraf/{{ .Hostname }}/{{ .PluginName }}"
  qos = 2
    
### username and password to connect MQTT server.
  username = "##ADD MQTT SERVER IP HERE##" 
  password = "##ADD MQTT PASSWORD HERE##"
  retain = false
  data_format = "json"

#########################################################
#                    INPUT PLUGINS                                    
#########################################################

### Monitor sensors, requires lm-sensors package
### https://github.com/influxdata/telegraf/blob/56aac4f0e15d195733002e0bc501f229cef9db02/plugins/inputs/sensors/README.md
[[inputs.sensors]]
  timeout = "5s"

Note: I removed the HDD section since I don’t have a HDD device that reports via that tool :

### Monitor disks' temperatures using hddtemp
[[inputs.hddtemp]]
  address = "127.0.0.1:7634"
  devices = ["sda"] ##Depending on which HDD are connected, you may need to change these

And now after this change I have:
image

And if I start the MQTT listener:

Now the next thing is to figure out how the sensors work :thinking: :crazy_face:

My metrics went all over the place

So I went back to the config and added layout = "batch" to the mqtt output plugins.

# Telegraf Configuration

[global_tags]
[agent]
  interval = "10s"  ## Default data collection interval for all inputs
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "5s"
  precision = ""
  hostname = ""
  omit_hostname = false

##########################################################
#                    OUTPUT PLUGINS                                   
##########################################################

### Configuration for MQTT server to send metrics to
### https://github.com/influxdata/telegraf/blob/56aac4f0e15d195733002e0bc501f229cef9db02/plugins/outputs/mqtt/README.md
[[outputs.mqtt]]
  servers = ["##ADD MQTT SERVER IP HERE##:1883"] # required.
  topic = "telegraf/{{ .Hostname }}/{{ .PluginName }}"
  qos = 2
    
### username and password to connect MQTT server.
  username = "##ADD MQTT SERVER IP HERE##" 
  password = "##ADD MQTT PASSWORD HERE##"
  retain = false
  data_format = "json"
  layout = "batch"

#########################################################
#                    INPUT PLUGINS                                    
#########################################################

### Monitor sensors, requires lm-sensors package
### https://github.com/influxdata/telegraf/blob/56aac4f0e15d195733002e0bc501f229cef9db02/plugins/inputs/sensors/README.md
[[inputs.sensors]]
  timeout = "5s"

So now I get all metrics in one message, and then its is much easier to handle:

The next thing is to create sensors in the configuration.yaml file, like so:

mqtt:
  sensor:
    - name: "Proxmox CPU Temperature Core Package"
      unique_id: proxmox_cpu_temp_core_package
      device_class: temperature
      unit_of_measurement: "°C"
      #state_class: measurement
      icon: mdi:thermometer
      qos: 2
      state_topic: "telegraf/proxmox/sensors"
      json_attributes_topic: "telegraf/proxmox/sensors"
      json_attributes_template: >-
        {{(value_json.metrics|
        selectattr('tags.chip','eq','coretemp-isa-0000')|
        selectattr('tags.feature','eq','package_id_0')|
        list|first).fields|tojson
        }}
      value_template: >
        {{(value_json.metrics|
        selectattr('tags.chip','eq','coretemp-isa-0000')|
        selectattr('tags.feature','eq','package_id_0')|
        list|first).fields.temp_input
        }}
      expire_after: 120
      device:
        name: Proxmox
        model: Intel(R) Pentium(R) Silver N6005 @ 2.00GHz by Proxmox VE
        identifiers:
          - 0x4E71
        configuration_url: "https://proxmox.#####:8006/"
        hw_version: 8.0.3

This is just an example of a single sensor but the MQTT message contains many sensors. So for each I created a new sensor similar to the above

Finally, the correct result :partying_face: :partying_face: :partying_face::


I hope that this also helps someone, as it did for me :slight_smile: