IoT button for PC-independent alarming

<< Click to display Table of Contents >>

Navigation:  Alarm > Alarm >

IoT button for PC-independent alarming

To trigger an alarm without a PC, it is possible to connect SMART Wi-Fi buttons. These can either be carried along or installed stationary in the premises.

 

The following examples describe how a Shelly Smart Wi-Fi Button is configured in the network and connected to the Cordaware bestinformed Alarm Edition.

 

 

Network configuration of the Shelly Button

 

hmtoggle_arrow1Option 1: Setup in a local WiFi

 

hmtoggle_arrow1Option 2: Setup via a mobile hotspot for mobile use with a smartphone

 

 

Keypress configuration

 

1. Open the configuration web interface of your Shelly Button and switch to the "Actions" tab.

 

 

If you did not specify a static IP address during WLAN configuration, Shelly provides a simple tool for locating Shelly devices on the local network:

 

Windows: https://shelly.cloud/documents/device_finders/ShellyFinderWindows.zip

Mac OS: https://shelly.cloud/documents/device_finders/ShellyFinderOSX.zip

 

shelly_button_webinterface_actions

 

 

2. Now expand the action you want to configure.

If you want an action to be executed when the button is pressed short, then expand the "BUTTON SHORT PRESSED URL" item.

 

Activate the "Enabled" checkbox and enter a URL under "Url to be hit when the button is pressed short", which should be called when the button is pressed short.

To trigger PC-independent alarms, a PHP script can be addressed here, for example, which uses the MailToInfo interface of Cordaware bestinformed to generate a corresponding info.

 

Afterwards, click on the "SAVE" button to confirm your changes.

 

shelly_button_webinterface_button_short_pressed_url

 

 

You can find a sample PHP script below that uses the external library "PHPMailer" to address the MailToInfo interface of Cordaware bestinformed.

 

1. Copy the script below into any text editor and save the file as a PHP file in any directory.

Fill in the necessary variables in the "CONFIGURATION" section for your installation and save the script again.

 

2. Download the "PHPMailer" library: https://github.com/PHPMailer/PHPMailer/archive/master.zip

Unzip it to the same directory as the PHP file and rename the folder "PHPMailer-master" to "PHPMailer".

 

To use this script with the Shelly button, you have to provide it on a web server accessible for your network.

 

In addition, you must specify the name of an existing alarm template in Cordaware bestinformed when calling the script.

To do this, specify a query parameter "templatename" with the name of the template as value in the URL.

 

Additionally, you can specify any other query parameters that will be passed to the template as values for ScriptVars with the same name.

 

Examples:

 

http://your.server.address/shelly_button/alarm_script.php?templatename=Basic%20Alarm

 

The alarm template "Basic Alarm" is used here.

 

 

http://your.server.address/shelly_button/alarm_script.php?templatename=Extended%20Alarm&realname=Max.Mustermann&alarmroom=Mobile%20workplace

 

In this example, the alarm template "Extended Alarm" is used, which contains the two ScriptVars "realname" and "alarmroom" in its infotext.

These were also appended to the URL as query parameters and thus the value "Max.Mustermann" is used for the ScriptVar "realname" and the value "Mobile workplace" for "alarmroom".

 

 

<?php

 

// PHPMailer 6.x - PHPMailer as ZIP Archive

// https://github.com/PHPMailer/PHPMailer/archive/master.zip

require('PHPMailer/src/PHPMailer.php');

require('PHPMailer/src/SMTP.php');

require('PHPMailer/src/Exception.php');

use PHPMailer\PHPMailer\PHPMailer;

 

///-------------------------------------------------------------------

/// CONFIGURATION

///-------------------------------------------------------------------

 

// Enter here "admin" or the login name of a user who has the rights to use the MailToInfo interface of Cordaware bestinformed.

$username = "admin";

 

// Enter the MailToInfo password of your bestinformed installation here.

// By default, the default admin password is also used for this interface.

// In the web interface under "System > System (local)" you can adjust the password of this interface at any time.

$password = "PASSWORD";

 

// Enter the address of your Cordaware bestinformed server here.

$host = "SERVER_ADDRESS";

 

// Enter your SMTP port configured in Cordaware bestinformed here. (Default: 8025)

$port = 8025;

 

///-------------------------------------------------------------------

/// INTERNAL FUNCTIONS

///-------------------------------------------------------------------

 

if (isset($_GET["templatename"])) {

  $templatename = $_GET["templatename"];

  $body = implode("\r\n", explode("\n", trim(<<<BODY

 

    username=$username

    password=$password

    templatename=$templatename

 

    BODY)));

 

  // ScriptVars

  foreach ($_GET as $script_var => $script_var_value) {

    if ($script_var == "templatename") {

      continue;

    }

    $body .= "\r\n@" . $script_var . "=" . $script_var_value;

  }

  if (!isset($_GET["realname"])) {

    $body .= "\r\n@realname=Someone";

  }

  if (!isset($_GET["alarmroom"])) {

    $body .= "\r\n@alarmroom=Unknown";

  }

 

  $body .= "\r\n";

 

  // E-mail

  $mail = new PHPMailer();

 

  // Server settings

  $mail->SMTPDebug   = false;

  $mail->isSMTP();

  $mail->Host        = $host;

  $mail->SMTPAuth    = false;

  $mail->Port        = $port;

 

  // Receiver

  $mail->setFrom('shelly.button@cordaware.com', 'Shelly Button');

  $mail->addAddress('shelly.button@cordaware.com');

 

  // Content

  $mail->Subject     = "newinfo";

  $mail->Body        = $body;

  $mail->ContentType = "text/plain"; 

  $mail->CharSet     = "utf-8";

 

  // Send e-mail

  $mail->Send();

 

  echo '<strong style="font-family: Verdana, Geneva, Tahoma, sans-serif;">Alarm was sent!</strong>';

}

 

?>

 

 

Once everything is set up correctly, the Shelly Button can now be mounted in a central location or used from anywhere via mobile hotspot.