IoT_lover
Published © LGPL

DIY HomeKit-Enabled Devices

This shows how to make smart home devices, which can be controlled/monitored via Siri or Home app.

BeginnerFull instructions provided23,907
DIY HomeKit-Enabled Devices

Things used in this project

Story

Read more

Code

Sample config file

JSON
This files should be saved in .homebridge folder of raspberry pi with name config.json
{
	"bridge":{
		"name":"Homebridge",
		"username":"CC:22:3D:E3:CE:31",
		"port":51826,
		"pin":"031-45-154"
	},
	"accessories":[
		{
			"accessory": "PHPoC",
			"name": "Living Room Lamp",
			"service": "Lightbulb",
			"characteristics": [
				"On"
			],
			"url": "http://192.168.0.189/lightbulb_livingroom.php",
			"update_interval": 1000100
		},
		{
			"accessory": "PHPoC", 
			"name": "Bedrom Room Lamp",
			"service": "Lightbulb",
			"characteristics": [
				"On",
				"Brightness"
			],
			"url": "http://192.168.0.189/lightbulb_bedroom.php",
			"update_interval": 1000200
		},
		{
			"accessory": "PHPoC",
			"name": "Carbon Monoxide",
			"service": "Carbon Monoxide Sensor",
			"characteristics": [
				"Carbon Monoxide Level",
				"Carbon Monoxide Detected",
				"Carbon Monoxide Peak Level"
			],
			"url": "http://192.168.0.189/carbon.php",
			"update_interval": 1000
		},
		{
			"accessory": "PHPoC",
			"name": "temperature",
			"service": "Temperature Sensor",
			"characteristics": "Current Temperature",
			"url": "http://192.168.0.189/temperature.php",
			"update_interval": 1050
		}
	]
}

Example of PHPoC code for carbon monoxide sensor

PHP
This file should be uploaded to PHPoC board with name carbon.php
<?php
/* example value. write the code to read the read value from sensor here */
$is_detected = 1;
$level = 26;
$peak_level = 32;
?>
{
	"CarbonMonoxideDetected" :  <?php echo $is_detected ?>,
	"CarbonMonoxidePeakLevel":  <?php echo $peak_level ?>,
	"CarbonMonoxideLevel":  <?php echo $level ?>
}

Example of PHPoC code for temperature sensor

PHP
This file should be uploaded to PHPoC board with name temperature.php
<?php
	$temp = 31; // change code to read the real temperature value from sensor here
?>
{
	"CurrentTemperature": <?php echo $temp?>
}

Example of PHPoC code for lightbulb in bedroom

PHP
This file should be uploaded to PHPoC board with name lightbulb_bedroom.php
<?php

include_once "/lib/sd_340.php";

define("OUT_PIN", 31);

uio_setup(0, OUT_PIN, "out");

if(($led0 =  _GET("On")))
{
	if($led0 ===  "true")
		uio_out(0, OUT_PIN, LOW);
	else
		uio_out(0, OUT_PIN, HIGH);
}

if(uio_in(0, OUT_PIN) == LOW)
	$on = 1;
else
	$on = 0;

/* do Similar for brightness */

$brightness = 80; // example value


?>
{
	"On" : <?php echo $on ?>,
	"Brightness" : <?php echo $brightness ?>
}

Example of PHPoC code for lightbulb in livingroom

PHP
This file should be uploaded to PHPoC board with name lightbulb_livingroom.php
<?php

include_once "/lib/sd_340.php";

define("OUT_PIN", 30);

uio_setup(0, OUT_PIN, "out");

if(($led0 = _GET("On")))
{
	if($led0 ===  "true")
		uio_out(0, OUT_PIN, LOW);
	else
		uio_out(0, OUT_PIN, HIGH);
}

if(uio_in(0, OUT_PIN) == LOW)
	echo '{"On" : true}';
else
	echo '{"On" : false}';

?>

Credits

IoT_lover

IoT_lover

10 projects • 162 followers

Comments