Getting Slack Notifications from a Shelly Device

So maybe there is an easier way to do this, but this method was the first to come up to my mind!

I wanted to get Slack notifications on my #alerts channel when Power Consumption on my Electrical appliance gets above or below a specific threshold.

Required software: 

  • Apache (or any) web server

A Shelly device, for my purpose, I used:

  • Shelly EM WiFi Energy Meter and Contactor Control
  • Shelly Current Transformer 120A
  •  After wiring and setting up my shelly, I accessed the web interface from a browser and configured the "Actions" Menu.

    I set up CHANNEL 1 OVER POWER/ CHANNEL 1 UNDER POWER to call a specific URL configured in my monitoring server.


     

    My apache config on the server looks like the following, after adding some basic security, allowing only the shelly device to access the scripts:

            <Location ~ "/(shelly1a|shelly1b)"> 
    Order deny,allow
    Deny from all
    Allow from 192.168.1.30
    </Location>
    ScriptAlias /shelly1a /usr/lib/shelly-cgi-bin/hz.sh
    ScriptAlias /shelly1b /usr/lib/shelly-cgi-bin/hzunder.sh
    <Directory "/usr/lib/shelly-cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Require all granted
    </Directory>


    An example of one of the two scripts:

    #!/bin/bash

    message="⚠️ HZ is on"

    #slack webhook URL
    alertswh="https://hooks.slack.com/services/xxxxxxx"

    curl -X POST -H 'Content-type: application/json' --data @<(cat <<EOF
    {
    "text": "${message}",
    "channel": "#alerts",
    "username": "bot"
    }
    EOF
    ) $alertswh


     

     

    Σχόλια

    Δημοφιλείς αναρτήσεις από αυτό το ιστολόγιο

    Get Telegram notifications for APC UPS using SNMP traps in Linux

    Using IFTTT recipe to run a shell script

    Setting up your openwrt adsl router for Forthnet IPv6 (Dual Stack) - Static Pilot