Hope you can help me with this one. I have already spent few days researching the forum and trying different option and have a feeling that I miss something very simple.
Here is the setup:
Raspberry Pi with Domoticz V3.5879
I have got a Particle device which accepts POST requests via web. Usually I would run "curl https://api.spark.io/v1/devices/devicecode/FUNCTION -d access_token=myToken -d params=MyArguments" which perfectly works from terminal (both laptop and mac).
End result of this request is that a pump connected to a relay would either turn on or off depending on the MyArguments.
Following the forum and wiki, I have created Virtual Hardware and a Virtual Device connected to it.
Then I created Virtual switch, type:on\off.
From this step on I had few options:
a) http request in the OnAction field won't work (if I understood correctly) since its a GET request.
b) One can create lua script and put into /scripts/lua/script_device_MyVirtualSwitchName.lua with a following code:
Code: Select all
print('Pump script executed')
commandArray = {}
if (devicechanged['MyVirtualSwitchName'] == 'On') then
os.execute('curl -s "https://api.spark.io/v1/devices/DeviceCode/Function -d access_token=myToken -d params=on" ')
end
if (devicechanged['MyVirtualSwitchName'] == 'Off') then
os.execute('curl -s "https://api.spark.io/v1/devices/DeviceCode/Function -d access_token=myToken -d params=off" ')
end
return commandArray
c) one can create custom lua script, MyVirtualSwitchName.lua with the same code as above and either call it from OnAction/OffAction fields or use Blockly event with Start Script.
I ended up with numerous errors: 32256, 32512, 512, 256 after going through adding #!/usr/bin/lua at the beginning of script and chmod to 777. Tried adding "> /dev/null &')" to fight 256 error without success and gave up.
d) created 2 bash scripts (one for on and one for off):
Code: Select all
#!/bin/bash
curl -s https://api.spark.io/v1/devices/DeviceCode/Function -d access_token=myToken -d params=off > /dev/null
This successfully works.
However, I would love to have one script and preferably in LUA, which ideally I could later upgrade to have more functionality and maybe even parse the json answer. Could you please point to what direction to look to?
Thanks a lot.
Aram