Coder Social home page Coder Social logo

aexel90 / shelly_exporter Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 1.1 MB

Shelly humidity sensor exporter for prometheus

License: Apache License 2.0

Go 96.14% Dockerfile 3.86%
prometheus go shelly humidity humidity-monitoring humidity-sensor grafana grafana-dashboard exporter prometheus-exporter

shelly_exporter's Introduction

Prometheus Shelly Exporter and Grafana integration

This exporter exports some metrics from Shelly to Prometheus.

Testes with:

Shelly H&T Shelly Plus 2PM

Shelly API

Shelly API: https://shelly-api-docs.shelly.cloud/#shelly-h-amp-t

Shelly cloud API access: https://shelly.cloud/documents/developers/shelly_cloud_api_access.pdf

Test API with HTTP POST:

https://<url>/device/status?auth_key=<auth_key>&id=<id>

Configuration File: shelly-metrics.json

Determine "auth_key", "id" and "url" of your device via Shelly cloud API access and update in shelly-metrics.json. "shelly_name" and "name" can be determined on your own.

{
"account":{
    "auth_key": "...",
    "url": "..."
},
"products": [
    {
        "type": "ht",
        "export": {
            "isok": "isok",
            "temperature": "data.device_status.tmp.value",
            "humidity": "data.device_status.hum.value",
            "battery": "data.device_status.bat.value",
            "has_update": "data.device_status.update.has_update",
            "firmware": "data.device_status.getinfo.fw_info.fw",
            "mac": "data.device_status.mac",
            "updated": "data.device_status._updated"
        },
        "devices": [
            {
                "id": "956b54",                  
                "shelly_name": "S1",
                "name": "Indoor"
            },
            {
                "id": "9574a8",                   
                "shelly_name": "S2",
                "name": "Outdoor"
            }
        ]
    },
    ...

Build

go get github.com/aexel90/shelly_exporter/
cd $GOPATH/src/github.com/aexel90/shelly_exporter
go install

Execution

Usage:

$GOPATH/bin/shelly_exporter -h

Usage of ./shelly_exporter:
    -listen-address string
            The address to listen on for HTTP requests. (default "127.0.0.1:9784")
    -metrics-file string
            The JSON file with the metric definitions. (default "shelly-metrics.json")
    -test
            Test configured metrics

Execute:

$GOPATH/go/bin/shelly_exporter -metrics-file $GOPATH/go/bin/shelly-metrics.json

Testing:

$GOPATH/go/bin/shelly_exporter -metrics-file $GOPATH/go/bin/shelly-metrics.json -test

Metric: shelly_ht_info
- Exporter Result:
- Exporter Result 0:
    - humidity="53"
    - mac="E09806956B54"
    - name="Indoor"
    - isok="true"
    - shelly_name="S1"
    - temperature="22.88"
    - battery="85"
    - has_update="false"
    - firmware=""
    - updated="2021-11-23 19:43:54"
- Exporter Result 1:
    - has_update="false"
    - firmware="20210323-104951/v1.10.1-gf276b51"
    - isok="true"
    - name="Outdoor"
    - temperature="6.38"
    ...

Docker

    cp shelly-metrics.json.template shelly-metrics.json
    vi shelly-metrics.json
    docker-compose up -d --build

Grafana Dashboard

weather widget

https://weatherwidget.io/

<!doctype html> <html lang="de">
<head>
</head>
<body>
<a class="weatherwidget-io" href="https://forecast7.com/de/51d0513d74/dresden/" data-label_1="DRESDEN" data-theme="original" data-highcolor="#88d976" >DRESDEN</a>
<script>
!function(d,s,id){
    var js,fjs=d.getElementsByTagName(s)[0];
    if(!d.getElementById(id)){
    js=d.createElement(s);
    js.id=id;
    js.src='https://weatherwidget.io/js/widget.min.js';
    fjs.parentNode.insertBefore(js,fjs);
    setInterval('__weatherwidget_init()', 1800000) <!-- refresh widget every 30 minutes (1800000 milliseconds): -->
    }
}(document,'script','weatherwidget-io-js');
</script>
</body>
</html>

dashboard

Grafana-ID: 13739 https://grafana.com/grafana/dashboards/13739

grafana.ini

[panels]
# If set to true Grafana will allow script tags in text panels. Not recommended as it enable XSS vulnerabilities.
disable_sanitize_html = true

Grafana Grafana Rollo

shelly_exporter's People

Contributors

aexel90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shelly_exporter's Issues

Nix package

Hello,

I would like to monitor my shellys and it seems your package might be a good fit for my router.
As I'm using NixOS, I would like to use this package and let the community enjoy it as well.

I'm planning to create a pull-request to submit your software to Nix.
However, it would be super nice if you could make a tag, it would be easier for me for the submission process.

Do you think you can make a tag?

Cannot connect to shelly api

Hi.

When I try to run the script it only gives me the following:

Error: Response not OK: 400 Bad Request
Metric: shelly_ht_info

  • Exporter Result:
  • Metric: shelly_ht_temperature
  • Exporter Result:
  • Metric: shelly_ht_humidity
  • Exporter Result:

The command I use is this: /home/ikt/go/bin/shelly_exporter -metrics-file /home/ikt/go/bin/shelly-metrics.json -test

shelly-metrics.json is filled in with the correct url, auth key and device id

When I use the same device id, auth key and url in the following curl command, it works:
curl -X POST https://shelly-38-eu.shelly.cloud/device/status -d "id=XXXXXX&auth_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

Any idea what might be wrong?

Could not read temperature...

Hi,

I'm trying to setup shelly_exporter in my home.

I can read the information from the shelly using the -test option but the temperature informations are not available.

# shelly_exporter -metrics-file /tmp/shelly-metrics.json -test
Metric: shelly_ht_info
 - Exporter Result:
   - Exporter Result 0:
     - humidity=""
     - name="Serverrom"
     - has_update="false"
     - firmware="20221108-153925/v1.12.1-1PM-fix-g2821131"
     - updated="2023-01-28 10:23:03"
     - isok="true"
     - mac="DC4F22608D2A"
     - temperature=""
     - battery=""
     - shelly_name="ht"
   - prom desc: Desc{fqName: "shelly_ht_info", help: "Non-numeric data, value is always 1", constLabels: {}, variableLabels: [shelly_name name isok temperature humidity battery has_update firmware mac updated]}
     - prom metric type: 2
     - prom metric value: 1
     - prom label values: [ht Serverrom 1    0 20221108-153925/v1.12.1-1PM-fix-g2821131 DC4F22608D2A 2023-01-28 10:23:03]
Metric: shelly_ht_temperature
 - Exporter Result:
   - Exporter Result 0:
     - updated="2023-01-28 10:23:03"
     - isok="true"
     - humidity=""
     - name="Serverrom"
     - has_update="false"
     - firmware="20221108-153925/v1.12.1-1PM-fix-g2821131"
     - battery=""
     - shelly_name="ht"
     - mac="DC4F22608D2A"
     - temperature=""
   - prom desc: Desc{fqName: "shelly_ht_temperature", help: "shellyht temperature", constLabels: {}, variableLabels: [shelly_name name]}
     - prom metric type: 2
     - prom metric value: 0
     - prom label values: [ht Serverrom]
Metric: shelly_ht_humidity
 - Exporter Result:
   - Exporter Result 0:
     - updated="2023-01-28 10:23:03"
     - isok="true"
     - humidity=""
     - name="Serverrom"
     - has_update="false"
     - firmware="20221108-153925/v1.12.1-1PM-fix-g2821131"
     - battery=""
     - shelly_name="ht"
     - mac="DC4F22608D2A"
     - temperature=""
   - prom desc: Desc{fqName: "shelly_ht_humidity", help: "shellyht humidity", constLabels: {}, variableLabels: [shelly_name name]}
     - prom metric type: 2
     - prom metric value: 0
     - prom label values: [ht Serverrom]
#

The Shelly 1pm attached is working fine:

image

My json configuration file is:

{
    "account":{
        "auth_key": "<MY-KEY>",
        "url": "<SERVER>.shelly.cloud"
    },
        "products": [
                {
                        "type": "ht",
                        "export": {
                                "isok": "isok",
                                "temperature": "data.device_status.tmp.value",
                                "humidity": "data.device_status.hum.value",
                                "battery": "data.device_status.bat.value",
                                "has_update": "data.device_status.update.has_update",
                                "firmware": "data.device_status.getinfo.fw_info.fw",
                                "mac": "data.device_status.mac",
                                "updated": "data.device_status._updated"
                        },
                        "devices": [
                                {
                                        "id": "608d2a",
                                        "shelly_name": "ht",
                                        "name": "Serverrom"
                                }
                        ]
                }
        ],
        "metrics": [
                {
                        "type": "ht",
                        "fqname": "shelly_ht_info",
                        "help": "Non-numeric data, value is always 1",
                        "labels": [
                                "shelly_name",
                                "name",
                                "isok",
                                "temperature",
                                "humidity",
                                "battery",
                                "has_update",
                                "firmware",
                                "mac",
                                "updated"
                        ]
                },
                {
                        "type": "ht",
                        "fqname": "shelly_ht_temperature",
                        "help": "shellyht temperature",
                        "resultKey": "temperature",
                        "labels": [
                                "shelly_name",
                                "name"
                        ]
                },
                {
                        "type": "ht",
                        "fqname": "shelly_ht_humidity",
                        "help": "shellyht humidity",
                        "resultKey": "humidity",
                        "labels": [
                                "shelly_name",
                                "name"
                        ]
                }
        ]
}

What am I doing wrong here?

@aexel90 Pinging you just in case you missed this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.