Skip to content

Import πŸ”₯ Prometheus query results into 🏑 Home Assistant πŸ“ˆ

License

Notifications You must be signed in to change notification settings

mweinelt/ha-prometheus-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Prometheus sensor for Home Assistant

Use PromQL expressions to query Prometheus-compatible APIs and expose the results as sensor values in Home Assistant.

Contributions welcome!

Compatibility

Tested against Home Asisstant 2024.5.5.

Example usage

sensor:
  - platform: prometheus_sensor
    url: http://localhost:9090
    queries:
      - name: Energy usage
        expr: energy_usage_wh / 1000
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
      - name: Energy solar production
        expr: energy_solar_wh / 1000
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
      - name: Energy grid consumption
        unit_of_measurement: kWh
        expr: energy_grid_wh / 1000
        device_class: energy
        state_class: total_increasing

Upstream integration

I tried to get this component merged into home-assistant in 2020/12.

home-assistant/core#44508

That effort failed when the requirement to create a third party library to handle the interaction with the Prometheus API came up.

The code is using async aiohttp calls and reuses the home-assistant internal aiohttp client session. At the time I did not find a ready to use async prometheus client library, and the search for one wasn't easy due to the term client being overloaded in the Prometheus world. I was also not going to start maintaining such a library, when the class to wrap the Prometheus instant query API was a mere 36 LoC.

Everyone is welcome to pick up this effort!

About

Import πŸ”₯ Prometheus query results into 🏑 Home Assistant πŸ“ˆ

Topics

Resources

License

Stars

Watchers

Forks