Sure you don’t need the destructions, but... spool up a vhost in apache listening on port 8080 (or whatever you fancy, just remember to point config.json at whatever port)... edit your virtualhost.conf file (or just stick it in .htaccess) and add:
...into the relevant <VirtualHost *:8080></VirtualHost> container. Restart apache.
Then - json.htm in the web root...
Code: Select all
<?php
if (isset($_GET['type'])){ $types=true; }
if (isset($_GET['rid'])){ $idx=$_GET['rid']; } else { $idx=false; }
function transjson($json){
if (!isset($_GET['callback'])){
header('Content-Type: application/json; charset=utf8');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header('Access-Control-Allow-Origin: *');
exit($json);
} elseif (is_valid_callback($_GET['callback'])){
header('Content-Type: application/javascript; charset=utf8');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
exit("{$_GET['callback']}($json)");
} else {
header('status: 400 Bad Request', true, 400);
}
}
if (($types==true) && ($idx==false)) {
$pre = '{ "ActTime" : 1454957927, "ServerTime" : "2016-02-08 18:58:47", "Sunrise" : "07:27", "Sunset" : "16:59", "result" : [';
$post = '], "status" : "OK", "title" : "Devices" };';
$output = '{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "Off", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "004DDA2", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 17:46:14", "Level" : 100, "LevelInt" : 15, "MaxDimLevel" : 15, "Name" : "Ruby\'s Ceiling Light", "Notifications" : "false", "PlanID" : "8", "PlanIDs" : [ 8, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 5, "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "Dimmer", "SwitchTypeVal" : 7, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "dimmer", "Unit" : 12, "Used" : 1, "UsedByCamera" : false, "XOffset" : "860", "YOffset" : "556", "idx" : "1" },{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "Off", "Description" : "", "Favorite" : 1, "HardwareID" : 4, "HardwareName" : "RFX", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : false, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "65", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-09 18:59:45", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 0, "Name" : "My light", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 7, "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "COCO GDR2", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 1", "TypeImg" : "lightbulb", "Unit" : 4, "Used" : 1, "UsedByCamera" : false, "XOffset" : "0", "YOffset" : "0", "idx" : "2" },{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 125, "Data" : "On", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "0005B77", "Image" : "OutsideLantern", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 16:59:00", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 15, "Name" : "Outside Front Door", "Notifications" : "false", "PlanID" : "10", "PlanIDs" : [ 10, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "true", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 1, "Used" : 1, "UsedByCamera" : false, "XOffset" : "929", "YOffset" : "519", "idx" : "3" },{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "F298E1", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-06 13:50:45", "Level" : 100, "LevelInt" : 32, "MaxDimLevel" : 32, "Name" : "Scarlett\'s Ceiling Light", "Notifications" : "false", "PlanID" : "9", "PlanIDs" : [ 9, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "LightwaveRF", "SwitchType" : "Dimmer", "SwitchTypeVal" : 7, "Timers" : "false", "Type" : "Lighting 5", "TypeImg" : "dimmer", "Unit" : 16, "Used" : 1, "UsedByCamera" : false, "XOffset" : "155", "YOffset" : "193", "idx" : "4" },{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On, Level: 100 %", "Description" : "", "Favorite" : 0, "HardwareID" : 7, "HardwareName" : "RFXCom", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "00F6742", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 17:40:51", "Level" : 100, "LevelInt" : 15, "MaxDimLevel" : 15, "Name" : "Bug String", "Notifications" : "false", "PlanID" : "7", "PlanIDs" : [ 7, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 4, "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 14, "Used" : 1, "UsedByCamera" : false, "XOffset" : "24", "YOffset" : "664", "idx" : "5" },{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On", "Description" : "", "Favorite" : 0, "HardwareID" : 7, "HardwareName" : "RFXCom", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "00F6742", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 20:41:34", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 15, "Name" : "Twinkle 1", "Notifications" : "false", "PlanID" : "5", "PlanIDs" : [ 5, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 1, "Used" : 1, "UsedByCamera" : false, "XOffset" : "261", "YOffset" : "703", "idx" : "6" };
$json = ($pre.$output.$post);
transjson($json);
}
if (($types==true)&&($idx)){
$pre = '{ "ActTime" : 1454957927, "ServerTime" : "2016-02-08 18:58:47", "Sunrise" : "07:27", "Sunset" : "16:59", "result" : [';
$post = '], "status" : "OK", "title" : "Devices" };';
if($idx==1){
$output = '{ "ActTime" : 1454957927, "ServerTime" : "2016-02-08 18:58:47", "Sunrise" : "07:27", "Sunset" : "16:59", "result" : [{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "Off", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "004DDA2", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 17:46:14", "Level" : 100, "LevelInt" : 15, "MaxDimLevel" : 15, "Name" : "Ruby\'s Ceiling Light", "Notifications" : "false", "PlanID" : "8", "PlanIDs" : [ 8, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 5, "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "Dimmer", "SwitchTypeVal" : 7, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "dimmer", "Unit" : 12, "Used" : 1, "UsedByCamera" : false, "XOffset" : "860", "YOffset" : "556", "idx" : "1" }';
} else if ($idx==2){
$output = '{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "Off", "Description" : "", "Favorite" : 1, "HardwareID" : 4, "HardwareName" : "RFX", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : false, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "65", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-09 18:59:45", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 0, "Name" : "My light", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 7, "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "COCO GDR2", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 1", "TypeImg" : "lightbulb", "Unit" : 4, "Used" : 1, "UsedByCamera" : false, "XOffset" : "0", "YOffset" : "0", "idx" : "2" }';
} else if ($idx==3){
$output = '{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 125, "Data" : "On", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "0005B77", "Image" : "OutsideLantern", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 16:59:00", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 15, "Name" : "Outside Front Door", "Notifications" : "false", "PlanID" : "10", "PlanIDs" : [ 10, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "true", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 1, "Used" : 1, "UsedByCamera" : false, "XOffset" : "929", "YOffset" : "519", "idx" : "3" }';
} else if ($idx==4){
$output='{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On", "Description" : "", "Favorite" : 1, "HardwareID" : 2, "HardwareName" : "RFXCOM", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "F298E1", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-06 13:50:45", "Level" : 100, "LevelInt" : 32, "MaxDimLevel" : 32, "Name" : "Scarlett\'s Ceiling Light", "Notifications" : "false", "PlanID" : "9", "PlanIDs" : [ 9, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "LightwaveRF", "SwitchType" : "Dimmer", "SwitchTypeVal" : 7, "Timers" : "false", "Type" : "Lighting 5", "TypeImg" : "dimmer", "Unit" : 16, "Used" : 1, "UsedByCamera" : false, "XOffset" : "155", "YOffset" : "193", "idx" : "4" }';
} else if($idx==5){
$output = ' "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On, Level: 100 %", "Description" : "", "Favorite" : 0, "HardwareID" : 7, "HardwareName" : "RFXCom", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "00F6742", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 17:40:51", "Level" : 100, "LevelInt" : 15, "MaxDimLevel" : 15, "Name" : "Bug String", "Notifications" : "false", "PlanID" : "7", "PlanIDs" : [ 7, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : 4, "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 14, "Used" : 1, "UsedByCamera" : false, "XOffset" : "24", "YOffset" : "664", "idx" : "5" }';
} else if($idx==6){
$output = '{ "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 0, "Data" : "On", "Description" : "", "Favorite" : 0, "HardwareID" : 7, "HardwareName" : "RFXCom", "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver", "HardwareTypeVal" : 1, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "00F6742", "Image" : "Light", "IsSubDevice" : false, "LastUpdate" : "2016-02-08 20:41:34", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 15, "Name" : "Twinkle 1", "Notifications" : "false", "PlanID" : "5", "PlanIDs" : [ 5, 11 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "On", "StrParam1" : "", "StrParam2" : "", "SubType" : "AC", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Lighting 2", "TypeImg" : "lightbulb", "Unit" : 1, "Used" : 1, "UsedByCamera" : false, "XOffset" : "261", "YOffset" : "703", "idx" : "6" }';
}
$json = ($pre.$output.$post);
transjson($json);
}
?>
In the above, I’ve taken each of deejc & jem101’s JSON output as submitted to the GitRepo, stripped line breaks altho not really necessary, one per if(idx=={int}) statement... and also concatenated them all and put the lot into $output in if (($types==true) && ($idx==false)) {}
Voila. Done. Domesticz accessory emulator. Point your config.json at your web server IP and port, and fire up Homebridge.
So, I have my ‘main’ homebridge which runs from RaspPi. I also have homebridge and homebridge-edomoticz installed on my MacbookPro, which is hosting the above at localhost:8080.
In my home kit apps, I have two homes... my actual home, paired to the rasppi homebridge, and my dev-home, paired to my Macbook homebridge install. I can mess around with user’s setups to my heart’s content without messing up my own home’s setup. I can replicate the output of their sensors precisely with a quick copy & paste.
Or, create a room in your real Domoticz... manually add switches, one of every type... hit up json.htm?type=devices&plan={room idx} to get an output of just those sensors. Copy and paste into $output above, and into the if / else if statements for the individual sensors in if (($types==true)&&($idx)){}