MiguelRipoll23 / homebridge-securitysystem

Homebridge plugin that creates a security system accessory that can be triggered by HomeKit sensors.
https://www.npmjs.com/package/homebridge-securitysystem
MIT License
151 stars 13 forks source link

updateCurrentState - add URL request option #7

Closed 0ldF0x closed 5 years ago

0ldF0x commented 5 years ago

Hi, it would be great if you can expand a "updateCurrentState" method with ability to call URL on state change. I've an alarm system, which I can trigger with URL link. What I want to do is to call "alarm on" URL when alarm is triggered and "alarm off" URL when alarm is disabled. For URL request you could use something like:

var url = require('url');
...
    this.alarmOnUrl = url.parse(config['alarmOnUrl']);
...
 request({
           url: me.alarmOnUrl,
           method: 'GET',
       }, 
       function (error, response, body) {
       if (error) {
           // me.log('STATUS: ' + response.statusCode);
           // me.log(error.message);
           return callback(error);
       }

There should be option to define(optional) URL for every state (armed, triggered, ...).

MiguelRipoll23 commented 5 years ago

Hello!

A full URL for every state or something like this to avoid redundancy and improve clarity?

{
  'host': 'alarmsystem.local',
  'path_triggered': '__path_triggered_here__',
  'path_home': '__path_home_here__',
  'path_away': '__path_away_here__',
  ...
} 

Does your alarm system requires anything else like authentication, request headers, or parameters on the URL?

0ldF0x commented 5 years ago

Hi, actually I've found another plugin with similar functionality, check it out: https://github.com/codetwice/homebridge-http-securitysystem

I have home-made arduino alarm system which currently works only on local network and doesn't require any authentication. You trigger it with simple URL like this http://localhost/something.js/command=xxxx

MiguelRipoll23 commented 5 years ago

Great, that's all I needed to know!

The homebridge-http-securitysystem plugin may be more suited for what you are asking but if you are missing out the feature to trigger it from a HomeKit accessory I'm okay with adding the feature and releasing the update as soon as possible this weekend 🙂

0ldF0x commented 5 years ago

I want to use your plugin, so it would be great if you could add that feature! Thanks đź‘Ť

MiguelRipoll23 commented 5 years ago

I just released a new version (v1.2.0) that adds this feature 🎉

This is an example of the plugin's configuration based on the information you provided me about your web server:

{
    "accessory": "Security system",
    "name": "Security system",
    "default_mode": "home",
    "arm_seconds": 3,
    "trigger_seconds": 5,
    "host": "http://localhost",
    "path_home": "/something.js/command=home",
    "path_away": "/something.js/command=away",
    "path_night": "/something.js/command=night",
    "path_off": "/something.js/command=off",
    "path_triggered": "/something.js/command=triggered"
}

I'm glad you asked me to add this feature, sounds promising!

0ldF0x commented 5 years ago

Works perfect! Thanks for the quick implementation.

MiguelRipoll23 commented 5 years ago

You’re welcome! Feel free to follow-up this issue if there’s anything regarding this feature that could be improved or fixed.