metbosch / homebridge-http-temperature

HomeBridge HomeKit Plugin for HTTP temperature endpoints
https://www.npmjs.com/package/homebridge-http-temperature
Apache License 2.0
33 stars 18 forks source link

Pull from Prometheus #27

Closed ferni7 closed 2 years ago

ferni7 commented 2 years ago

I expose my temperature sensor data via Prometheus (https://github.com/leahneukirchen/lywsd03mmc-exporter) and wanted a way to pull that into Homebridge using your plugin

Here is a curl command to get the temperature from Prometheus API

curl -g 'http://x.x.x.x:9090/api/v1/query?query=last_over_time(thermometer_temperature_celsius{room="Office"}[1h])' |jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   271  100   271    0     0   264k      0 --:--:-- --:--:-- --:--:--  264k
{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {
          "__name__": "thermometer_temperature_celsius",
          "instance": "x.x.x.x:9265",
          "job": "temperature-sensors",
          "mac": "A4C1383D02A0",
          "room": "Office",
          "sensor": "LYWSD03MMC"
        },
        "value": [
          1635139324.556,
          "21.8"
        ]
      }
    ]
  }
}

Here is what worked for me in case anyone else needs it...


        {
            "accessory": "HttpTemperature",
            "name": "Office",
            "url": "http://x.x.x.x:9090/api/v1/query?query=last_over_time(thermometer_temperature_celsius{room='Office'}[1h])",
            "http_method": "GET",
            "field_name": "data.result[0].value[1]"
        },
metbosch commented 2 years ago

Thanks for the information. Was it hard to figure out? Do you think the documentation is enough?

ferni7 commented 2 years ago

Hey, I had to look into closed issues to find an example of how to use the field_name so maybe some documentation with 2-3 examples of more complex field_name settings would be useful :)