Feature Request - Make it easier to create button to send HTTP requests

I can confirm this code is working for me using a “baseURL”.

This is an example URL that is sent to Multi System Reactor to run a “Global Reaction” (Scene).

http://192.168.1.101:8111/api/v1/reaction/re-kofxitkx/run

This is the value I have specified for the button in its EventTrigger (Reaction ID).
image

This is the code for the HTTP script:

plugin.Name = "HTTPMSRGlobalReactions";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;

var http = new HTTPClient();
var baseUrl = "http://192.168.1.101:8111/api/v1/reaction/";

function onChangeRequest(device, attribute, value) {
    console.log("Sending " + value + " for " + device.Name);
        switch (attribute) {
        case "HttpCommand":
            http.get(baseUrl + value + "/" + "run");
            break;
        default:
            break;
    
}
    
}

function onConnect() {
}

function onDisconnect() {
}

function onPoll() {
}

function onSynchronizeDevices() {
    var switch1 = new Device();
    switch1.Id = "1";
    switch1.DisplayName = "Switch 1";
    switch1.Capabilities = ["Switch"];
    switch1.Attributes = [];
    plugin.Devices[switch1.Id] = switch1;
}

So now I no longer need to specify the full URL in each buttons EventTrigger, I just have to now specify the Multi System Reactor’s “Reaction” ID only.

1 Like

@Bill

I’ve been trying to create either a button or an image button to act as a Toggle button, to work with the HTTP plugin to turn ON / OFF a device via HTTP commands.

I can’t get this working at all, when I press the button the device turns on, but when I press the button again (toggle) the device does not turn off, it remains on.

I then tried to use the ToggleSwitch instead and that works OK fine. It turns on and off the device.

I’ve never been able to have one button for on and off.

Any tips ?

Thanks

Did you change the ButtonType to Toggle?

They default to Normal so don’t forget that step. That’s really the only extra thing you have to do vs a standard ToggleSwitch.

Yes I changed it from Normal to Toggle type

When you use the standard ToggleSwitch, does the Label show “On” when the switch is On & “Off” when the switch is Off. For toggles to work you really need to make sure status is being tracked correctly.

I’ve not been able to get the label working to say ON or OFF it just says unknown.

And I don’t think it can track the device state? Not the real device I am sending the HTTP commands to anyway.

Maybe it can track the state of the “Switch1” device in HR however ?

Yeah, that’s the problem then. You aren’t going to be able to use a toggle if status isn’t working. Think about it like this, say just open the application, how’s the toggle supposed to know which On/Off position it’s supposed to be in? It can’t. If you want to use a Toggle you need to update your plugin to track the status of that switch.

It doesn’t have to be too sophisticated. You could even simply update the Switch state after you send the request. Obviously this way isn’t going to stay in sync with all of your devices but it could be a suitable solution for you depending on your needs.

That’s OK for me, I know it could get out of sync with the real device.

I am just testing some stuff. I have one RGB Z-Wave bulb paired to an Ezlo Plus hub.

I wanted just a tile that matched the design of my current Home Remote app to turn it on / off. My tiles are all toggles, you click any where on the tile to turn the light on or off again etc.

As Home Remote doesn’t support imported devices from an Ezlo hub, my option was to send HTTP commands to the Ezlo hubs local HTTP API etc.

I’m just using the standard code at the moment from your HTTP Plugin example:

plugin.Name = "HTTPExample";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;

var http = new HTTPClient();

function onChangeRequest(device, attribute, value) {
    console.log("Sending " + value + " for " + device.Name);
    if (device.Id == "1") {
        switch (value) {
            case "On":
                http.get("https://192.168.1.100:17000/v1/method/hub.item.value.set?_id=60e47f4f120bab11f9d77f61&value_int=1");
                break;
            case "Off":
                http.get("https://192.168.1.100:17000/v1/method/hub.item.value.set?_id=60e47f4f120bab11f9d77f61&value_int=0");
                break;
            default:
                break;
        }
    }
    else {
        throw "Commands for this device Id have not been implemented";
    }
}

function onConnect() {
}

function onDisconnect() {
}

function onPoll() {
}

function onSynchronizeDevices() {
    var switch1 = new Device();
    switch1.Id = "1";
    switch1.DisplayName = "Switch 1";
    switch1.Capabilities = ["Switch"];
    switch1.Attributes = [];
    plugin.Devices[switch1.Id] = switch1;
}

But not sure how to change it to make it work for this issue.

Use this code.

plugin.Name = "HTTPExample";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;

var http = new HTTPClient();

function onChangeRequest(device, attribute, value) {
    console.log("Sending " + value + " for " + device.Name);
    if (device.Id == "1") {
        switch (value) {
            case "On":
                http.get("https://192.168.1.100:17000/v1/method/hub.item.value.set?_id=60e47f4f120bab11f9d77f61&value_int=1");
                device.Switch = "On";
                break;
            case "Off":
                http.get("https://192.168.1.100:17000/v1/method/hub.item.value.set?_id=60e47f4f120bab11f9d77f61&value_int=0");
                device.Switch = "Off";
                break;
            default:
                break;
        }
    }
    else {
        throw "Commands for this device Id have not been implemented";
    }
}

function onConnect() {
}

function onDisconnect() {
}

function onPoll() {
}

function onSynchronizeDevices() {
    var switch1 = new Device();
    switch1.Id = "1";
    switch1.DisplayName = "Switch 1";
    switch1.Capabilities = ["Switch"];
    switch1.Attributes = [];
    plugin.Devices[switch1.Id] = switch1;
}

Thanks Bill

Its working now with the image button and the label I added next to it, is now also saying On or Off correctly.

I will try and edit one of my other tiles now, that I normally use where the whole tile acts as the button.

I understand if I turn that light on by some other means other than Home Remote, then it will not be in sync in the Home Remote app.

I think you can send HTTP commands to the Ezlo hub to get a devices current status in JSON I think, Might have to look at that maybe.

I actually got an Ezlo hub here that I plan on testing later this summer. An official integration is coming.

1 Like

That’s great, if you need any help with their API’s let me know and I can put you in touch directly with the right developers at Ezlo as I have them all on my Skype.

I am still running my Vera Plus as my production hub, but I have some Z-Wave devices paired to the Ezlo Plus hub now.

Their software isn’t ready yet, its all still in beta. But the hardware and Z-Wave command response times are great, much faster than my Vera hub.

Patrick who makes Reactor has also just announced he is now making Mutli System Reactor work with Ezlo hubs !

So we will have a proper Logic Engine and a decent dashboard app with Home Remote. Best of both worlds. The Ezlo hub can then just act as a “Z-Wave Radio” that the devices are paired to etc.

I can use a Curl command like this to return the ON or OFF state of the light (true or false)

You have to specify the devices ID number and also the “Item” ID number you are looking for, in this case I am using the “Switch” item.

curl --insecure --http1.1 https://EZLO-IP:17000/v1/request -d '{"method": "hub.data.list", "id": "60e47f4e120bab11f9d77f5b", "params": {"items":{"ids":["60e47f4f120bab11f9d77f61"],"fields":{"include":["valueFormatted"]}}}}'

The Ezlo HTTP API requires POST I think to retrieve data for devices, so its not as simple as the old Vera hubs you could use simple one line HTTP commands.

No idea how I could get Home Remote to get the lights actual real status and display it on the tile.

I can get the data using Postman application also, example here

Think I’ll wait for your official integration !

Sounds good. I’ll let you know when I have something you can test.

1 Like

Is there a way to create an HttpStatus? Which receives the status from the server.