How do I send a REST command?



  • Hi I just managed to integrate my first mysensors.org switch into domoticz. If I flick the switch it gets updated correctly in domotiz, and now I want to send a REST command witch look like this whenever the switch is switched:

    "PUT 192.168.0.22:4455/devices/{udn} The body should be "application/json" as {"STATE": true } "

    How do I do this? I guess i need to write a script somehow and place it in the right folder and then specifying it under the switch options.

    But I have no idea of how to write a script for this.



  • An example of using the Domoticz api over http would be http://192.168.0.22:4455/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

    Not sure where you got your info from but the API is detailed here.
    Domoticz API



  • But will that send a PUT command? And where do I enter the body info:{"STATE": true }



  • What are you trying to archieve with this? What is the receiving end?

    I think you can send your "ajax call" from lua script with os.execute method using curl if you are in linux enviroment.

    commandArray = {}
    if (devicechanged['NameOfYourSwitch'] == 'On') then
      os.execute('/usr/bin/curl -X PUT -d STATE=true 192.168.0.22:4455/devices/{udn}')
    else if(devicechanged['NameOfYourSwitch'] == 'Off') then
      os.execute('/usr/bin/curl -X PUT -d STATE=false 192.168.0.22:4455/devices/{udn}')
    end
    return commandArray
    

    And give it a name with prefix: script_device_xxxxxxx.lua where xxxxxxx is name for your script. Then domoticz will launch it everytime some device state changes. Location for it is script/lua under your domoticz folder.


Log in to reply
 

Suggested Topics

  • 5
  • 2
  • 1
  • 2
  • 5
  • 4

8
Online

11.2k
Users

11.1k
Topics

112.5k
Posts