I started off by asking about creating an interface to/smart app for a system called Qwikswitch on the ST forum. The discussion turned towards webCore, so I thought I should continue the discussion here. (I hope this is an acceptable way of doing that.)
I currently use GET requests linked to virtual switches in a piston to control the Qwikswitch devices. The Qwickswitch API is available here. I however also use time triggers in pistons to turn lights on/off. The problem is that the Virtual Switch state and the actual device switch are most of the time out of sync and I thought there could be an easy way to create a smart app to correct this.
@Ryan780 suggested that I enhance my piston to update the Virtual Device state. He suggested using $args to obtain the device status:
I created a piston but I could not get the {args.FROMCAMP1} (as suggested by him) to return a result other than “null”. Don’t know if I’m being stupid and perhaps had to change the FROMCAMP1 part?
Looking at other pistons example I tried the $response variable instead. Running the GET request http://qwikswitch.com/api/v1/control/?device=@&setlevel=100 to turn a switch on, produces the following result:
[level:100, device:@1111, success:true]
My issue is that this result (in respect of the particular device) is only produced following a GET request to turn the device on/off.
According to my understanding of the API, the only way to get the state of a device, is via this GET request: https://qwikswitch.com/api/v1/state/:API_KEY/, which returns the status of all devices:
Calculating (string) @1111:[firmware:2b, epoch:1518243799, value:0, rssi:65%, type:RELAY QS-R-S5], @2222:[firmware:32, epoch:1518243618, value:0, rssi:45%, type:RELAY QS-R-S5], @3333:[firmware:2b, epoch:1518243798, value:0, rssi:62%, type:RELAY QS-R-S5], @4444:[firmware:2b, epoch:1518243796, value:0, rssi:59%, type:RELAY QS-R-S5], @5555:NO_REPLY, @207100:[firmware:40, epoch:1518243926, value:0, rssi:52%, type:RELAY QS-R-S30-SPEC] truncated
The device ID of each device follows after the “@” (which I have changed in the result above for security concerns). The state of the device is indicated by a 0 or 1 following “value:” I don’t know what “epoch” is.
I understand that what I need to do to get the status of a particular device, is referred to as parsing? My questions are therefore:
How do I parse the result of the state GET request to a variable which only contains the status of a particular device? My understanding is that I should look for the Device ID within the result of the GET request and then in some or other way, look what the value of “value” is immediately following the device’s ID?
I suppose once I have that information, I will use IF contents of variableContainingStateOfDevice555= 1, turn virtualSwitch555 On?
There will obviously be a statement in my piston IF virtualSwitch555 changes to On, run GET request to turn on Device555. If Device555 was turned on by a GET request from a piston, virtualSwitch555 will show as being Off, until the state statement of the piston turns it On to reflect the true state of Device555. The piston will also contain a statement IF virtualSwitch555 turns on, run GET request to turn on Device555. How will I prevent a status update to run this command? Or should I just live with that (since a GET request to turn on a device which is already on, will do nothing.) I’m just worried about the amount of traffic I’m going to generate on the system.