etwmc / Personal-HomeKit-HAP

This project will provide source code to build a HomeKit support accessories.
MIT License
235 stars 85 forks source link

create multiple lights and execute shell scripts #8

Closed dermarder closed 9 years ago

dermarder commented 9 years ago

hey guys! as my programming skills are very basic i need some help.

I would like to create multiple lights and execute a shell script when a lamp is turned on or off.

for example "if lamp1 is turned on execute /home/pi/lamp1_on.sh" "if lamp1 is turned on execute /home/pi/lamp1_off.sh" "if lamp2 is turned on execute /home/pi/lamp2_on.sh" "if lamp2 is turned on execute /home/pi/lamp2_off.sh and so on..

How could i achieve this? Where do i need to edit the code? I looked inside the accessory.cpp and PHKArduinoInterface files an tried to modify the inline void turnOnLight() { setLightStrength(255); } inline void turnOffLight() { setLightStrength(0); }

with adding System(Home/pi/test.sh); But that didn't worked.

Can anyone help me? Thank you very much! You're doing great work here

etwmc commented 9 years ago

test.sh point to what?

the line should be system("/home/pi/lamp1_on.sh") for lamp 1 on system("/home/pi/lamp1_off.sh") for lamp 1 off and so on.

gb160 commented 9 years ago

@dermarder achieving switching of one light is very simple...anymore than one device requires a fair bit of programming knowledge, HAP-NodeJS is much easier to customise in that respect, but its a bit too processor hungry to use on a pi. If CPU isn't an issue for you then thats probably the way to go, unless someone with adequate programming skills decides to put something together and share their work. The goal of this project was to control one light, which it achieves really well.

etwmc commented 9 years ago

I just rebuild the structure of the code and include a sample for multiple accessories. Have fun.

gb160 commented 9 years ago

@etwmc many thanks for this and your time, I'm away for a few days but will try this asap.

gb160 commented 9 years ago

@etwmc How do i set the configuration for the second device...or have i misunderstood something? Surely to control two devices simultaneously i would need two separate Configuration.h files?

etwmc commented 9 years ago

HomeKit has something call bridge. So multiple accessory (light, fan, whatever) only need one setup. If you don't care about the accessory name, the current structure should be enough. Otherwise, you just need to copy the infoService, give it a new name, and change the accessory name (and manufacture, and stuff).

etwmc commented 9 years ago

Just don't change the serial number. From what I got, one bridge->one serial number.

gb160 commented 9 years ago

Ahhhh!! That makes sense now, this is going to be extremely useful.Thanks.