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

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.