mweinelt / ha-prometheus-sensor

Import 🔥 Prometheus query results into 🏡 Home Assistant 📈
MIT License
20 stars 7 forks source link

There are no tmax_over_time values. #19

Closed garry0garry closed 3 weeks ago

garry0garry commented 3 weeks ago
sensor:
  - platform: prometheus_sensor
    url: http://localhost:9090
    queries:
      - name: in3_voltage_max
        expr: max_over_time(homeassistant_sensor_voltage_v{entity="sensor.pzem_004t_v3_in3_voltage"}[1y])
        unit_of_measurement: V
        device_class: voltage
      - name: in3_voltage_max_timestamp
        expr: tmax_over_time(homeassistant_sensor_voltage_v{entity="sensor.pzem_004t_v3_in3_voltage"}[1y])
        device_class: timestamp

The timestamp sensor is always unavailable. How to find the cause of the problem?

mweinelt commented 3 weeks ago

Can you check the home-assistant log for clues? If a metric is unavailable it will generally log the reason there. Not sure if there is a good way to propagate errors into the UI :thinking:

mweinelt commented 3 weeks ago

Looks to me like tmax_over_time is specific to VictoriaMetrics; https://docs.victoriametrics.com/metricsql/#tmax_over_time

What Prometheus implementation are you using?

garry0garry commented 3 weeks ago

Understood thanks. I don't have VictoriaMetrics. And I don’t know how to get the time and date of an event :-(

How to assign a unique identifier to a sensor?

mweinelt commented 3 weeks ago

Understood thanks. I don't have VictoriaMetrics. And I don’t know how to get the time and date of an event :-(

The integration is using the Query API of Prometheus, which will always return the latest value for your given expression. The time that Home Assistant records as the last update is probably the best you're going to get.

How to assign a unique identifier to a sensor?

Set the unique_id field for a query.

garry0garry commented 3 weeks ago

The integration is using the Query API of Prometheus, which will always return the latest value for your given expression. The time that Home Assistant records as the last update is probably the best you're going to get.

I need to find the maximum value and time when the event occurred.

mweinelt commented 3 weeks ago

I would recommend taking that question to the Prometheus community.

They're on Slack, Matrix and IRC: https://prometheus.io/community/