### JSON API Commands

Information about the powerful Domoticz Feature to send commands via API calls.
This can be used by B4X Applications.
References
Home Automation Domoticz
http://www.domoticz.com
Domoticz offers a JSON API to call commands.
http://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
Concept
The concept is to sent an HTTP get request to the Domoticz server. The reply will be a JSON string.
Then parse the received JSON string accordingly.
A JSON API Call is defined as
http://domoticz-ip<:port>/json.htm?api-call
= the username And password To access Domoticz, this Is optional.
domoticz-ip = the ip address Or hostname of your domoticz installation.
<:port> = the port number of your domoticz installation, this Is optional.
B4X Pseudo Code used:
• HTTPJob.Initialize
• HTTPJob.Download(URLwithAPICommand)
• HTTPJobDone
• HTTPJob.Success Then ParseResultCommand(Job.GetString)
B4J Example 1
HTML Command:
http://192.168.0.20:8080/json.htm?type=command¶m=switchlight&idx=6&switchcmd=On&level=0
Result JSON String:
{
"status" : "OK",
"title" : "SwitchLight"
}
Result Code ( to replace with the JSON String:
Dim parser As JSONParser
parser.Initialize()
Dim root As Map = parser.NextObject
Dim title As String = root.Get("title")
Dim status As String = root.Get("status")
B4J Example 2
HTML Command:
http://192.168.0.20:8080/json.htm?type=command¶m=switchlight&idx=6&switchcmd=ON&level=0
Result JSON String:
{
"status" : "ERR"
}
Result Code ( to replace with the JSON String:
Dim parser As JSONParser
parser.Initialize()
Dim root As Map = parser.NextObject
Dim status As String = root.Get("status")
B4J Example 3
HTML Command:
http://192.168.0.20:8080/json.htm?type=command¶m=getlightswitches
Result JSON String:
{
"result" : [ { "IsDimmer" : false, "Name" : "LED GPIO18", "SubType" : "Impuls", "Type" : "Lighting 1", "idx" : "6" } ],
"status" : "OK",
"title" : "GetLightSwitches"
}
Result Code ( to replace with the JSON String:
Dim parser As JSONParser
parser.Initialize()
Dim root As Map = parser.NextObject
Dim result As List = root.Get("result")
For Each colresult As Map In result
Dim Name As String = colresult.Get("Name")
Dim idx As String = colresult.Get("idx")
Dim Type As String = colresult.Get("Type")
Dim IsDimmer As String = colresult.Get("IsDimmer")
Dim SubType As String = colresult.Get("SubType")
Next
Dim title As String = root.Get("title")
Dim status As String = root.Get("status")
B4J Example 4
HTML Command:
http://192.168.0.20:8080/json.htm?type=devices&rid=6
Result JSON String:
{
"5MinuteHistoryDays" : 1,
"ActTime" : 1433833155,
"AllowWidgetOrdering" : true,
"DashboardType" : 0,
"MobileType" : 0,
"TempScale" : 1.0,
"TempSign" : "C",
"WindScale" : 1.0,
"WindSign" : "m/s",
"dontcachehtml" : true,
"result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "Off", "Favorite" : 0, "HardwareID" : 2, "HardwareName" : "GPIO Port", "HaveDimmer" : false, "HaveGroupCmd" : false, "HaveTimeout" : false, "ID" : "0", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2015-06-09 07:38:08", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 0, "Name" : "LED GPIO18", "Notifications" : "false", "PlanID" : "0", "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 7, "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "Impuls", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 1", "TypeImg" : "lightbulb", "Unit" : 18, "Used" : 1, "UsedByCamera" : false, "XOffset" : "0", "YOffset" : "0", "idx" : "6" } ],
"status" : "OK",
"title" : "Devices"
}
Result Code ( to replace with the JSON String:
Dim parser As JSONParser
parser.Initialize()
Dim root As Map = parser.NextObject
Dim result As List = root.Get("result")
For Each colresult As Map In result
Dim YOffset As String = colresult.Get("YOffset")
Dim SignalLevel As Int = colresult.Get("SignalLevel")
Dim PlanID As String = colresult.Get("PlanID")
Dim Type As String = colresult.Get("Type")
Dim HaveTimeout As String = colresult.Get("HaveTimeout")
Dim XOffset As String = colresult.Get("XOffset")
Dim AddjValue2 As Double = colresult.Get("AddjValue2")
Dim Notifications As String = colresult.Get("Notifications")
Dim IsSubDevice As String = colresult.Get("IsSubDevice")
Dim Protected As String = colresult.Get("Protected")
Dim Unit As Int = colresult.Get("Unit")
Dim HardwareName As String = colresult.Get("HardwareName")
Dim StrParam1 As String = colresult.Get("StrParam1")
Dim Data As String = colresult.Get("Data")
Dim StrParam2 As String = colresult.Get("StrParam2")
Dim LastUpdate As String = colresult.Get("LastUpdate")
Dim AddjMulti As Double = colresult.Get("AddjMulti")
Dim Image As String = colresult.Get("Image")
Dim ID As String = colresult.Get("ID")
Dim SwitchTypeVal As Int = colresult.Get("SwitchTypeVal")
Dim HardwareID As Int = colresult.Get("HardwareID")
Dim Timers As String = colresult.Get("Timers")
Dim Favorite As Int = colresult.Get("Favorite")
Dim SwitchType As String = colresult.Get("SwitchType")
Dim idx As String = colresult.Get("idx")
Dim MaxDimLevel As Int = colresult.Get("MaxDimLevel")
Dim AddjMulti2 As Double = colresult.Get("AddjMulti2")
Dim LevelInt As Int = colresult.Get("LevelInt")
Dim CustomImage As Int = colresult.Get("CustomImage")
Dim HaveDimmer As String = colresult.Get("HaveDimmer")
Dim BatteryLevel As Int = colresult.Get("BatteryLevel")
Dim UsedByCamera As String = colresult.Get("UsedByCamera")
Dim ShowNotifications As String = colresult.Get("ShowNotifications")
Dim TypeImg As String = colresult.Get("TypeImg")
Dim Name As String = colresult.Get("Name")
Dim Status As String = colresult.Get("Status")
Dim AddjValue As Double = colresult.Get("AddjValue")
Dim Used As Int = colresult.Get("Used")
Dim HaveGroupCmd As String = colresult.Get("HaveGroupCmd")
Dim Level As Int = colresult.Get("Level")
Dim SubType As String = colresult.Get("SubType")
Next
Dim title As String = root.Get("title")
Dim WindScale As Double = root.Get("WindScale")
Dim AllowWidgetOrdering As String = root.Get("AllowWidgetOrdering")
Dim status As String = root.Get("status")
Dim 5MinuteHistoryDays As Int = root.Get("5MinuteHistoryDays")
Dim TempSign As String = root.Get("TempSign")
Dim WindSign As String = root.Get("WindSign")
Dim ActTime As Int = root.Get("ActTime")
Dim TempScale As Double = root.Get("TempScale")
Dim DashboardType As Int = root.Get("DashboardType")
Dim MobileType As Int = root.Get("MobileType")
Dim dontcachehtml As String = root.Get("dontcachehtml")

Changed: , Category: Domoticz Home Automation, File: T6C186M1350.htm, ID: 1350