Connected FAAC gate to Domoticz (control with Telegram)
Posted: Monday 13 July 2015 11:34
Mod edit: Post splitted into new topic. Original topoic: http://domoticz.com/forum/viewtopic.php?f=17&t=5509
---------------------------------------
Yes! I've found/made a solution
and call it #open or in Dutch 'hekje open'.
Only two thing to fix:
- Telegram seems to spawn Zombie processes. I found this out because I added my home server to a Opsview/Nagios monitor. After a day of running (and receiving Telegram messages) it wil create up to 10 zombie/<defunct> 'sh' processes. Don't know which step creates them, but they are gone after restarting the Telegram daemon. I can't find any other telegram/domoticz user that has this problem.
- Finding a way to automatically send #open to myself when I start the car within the fence. Tried it with IFTTT, but the rule of 'when connecting to a bluetooth device' does not let you specify a device. It would work if I could make a rule that looks at my carkit + GPS location and then sends the #open.
I'm controlling the gate through telegram->domoticz->libusb/digispark->digiusb->remote.
I found out that the FAAC remote has a OOK rolling 868 code that is not easy to receive/transmit with standard cheap prints, because you need a fast clock (or a modified RFM12B print).
A spare remote costs a litle bit more, but is easier to implement. A small ATTiny85 print 'pushes' the putton for me and the remote print is powered by the usb in stead of the 2 CR2032u batteries.
I modded the original tg/scripts/generic/receive.lua slightly because I do not use a separate phone number for the Telegram server. So now I receive all #open calls my self so I know which friends open my gate. Then all texts sent to me would be checked for commands and people would receive 'INVALID COMMAND' notices. But I changed it so that commands have to start with a '#'.
Costed € 46,- in total and has:
- FAAC remote (€40,-) to copy the code to from the one I already had.
- Digispark ATTiny85 usb print (€ 6,0)
- CNY17-3 optocoupler for pushing the button (<€1)
- A 100-200Ohm resistor for controlling the current through the optocoupler
The original front of the remote still fits on the print, because everything is soldered on the back. Only the two yellow wires go to the front to short the push button.


tg/scripts/user/open.sh
hekjeopen.ino Arduino file
changed HandleCommand function in tg/scripts/generic/receive.lua
---------------------------------------
Yes! I've found/made a solution

Only two thing to fix:
- Telegram seems to spawn Zombie processes. I found this out because I added my home server to a Opsview/Nagios monitor. After a day of running (and receiving Telegram messages) it wil create up to 10 zombie/<defunct> 'sh' processes. Don't know which step creates them, but they are gone after restarting the Telegram daemon. I can't find any other telegram/domoticz user that has this problem.
- Finding a way to automatically send #open to myself when I start the car within the fence. Tried it with IFTTT, but the rule of 'when connecting to a bluetooth device' does not let you specify a device. It would work if I could make a rule that looks at my carkit + GPS location and then sends the #open.
I'm controlling the gate through telegram->domoticz->libusb/digispark->digiusb->remote.
I found out that the FAAC remote has a OOK rolling 868 code that is not easy to receive/transmit with standard cheap prints, because you need a fast clock (or a modified RFM12B print).
A spare remote costs a litle bit more, but is easier to implement. A small ATTiny85 print 'pushes' the putton for me and the remote print is powered by the usb in stead of the 2 CR2032u batteries.
I modded the original tg/scripts/generic/receive.lua slightly because I do not use a separate phone number for the Telegram server. So now I receive all #open calls my self so I know which friends open my gate. Then all texts sent to me would be checked for commands and people would receive 'INVALID COMMAND' notices. But I changed it so that commands have to start with a '#'.
Costed € 46,- in total and has:
- FAAC remote (€40,-) to copy the code to from the one I already had.
- Digispark ATTiny85 usb print (€ 6,0)
- CNY17-3 optocoupler for pushing the button (<€1)
- A 100-200Ohm resistor for controlling the current through the optocoupler
The original front of the remote still fits on the print, because everything is soldered on the back. Only the two yellow wires go to the front to short the push button.


tg/scripts/user/open.sh
Code: Select all
#!/bin/bash
# Sends text to lib-usb Digistump device
#Settings
SendMsgTo=$1
#Send sensor values with telegram
$TelegramScript msg $SendMsgTo "Please wait, pushing button..."
##############################################################################
sent=`sudo /home/albert/progs/digiusb/send 01 --debug | tail -n 1`
if [[ "$sent" == "Error -22 releasing Interface 0" ]] ; then
ResultString="Gate should be opening!\n"
elif [[ "$sent" == "Error -1 releasing Interface 0" ]] ; then
ResultString="Sorry, something went wrong. Better luck next time!\n"
elif [[ "$sent" =~ "No Digispark" ]] ; then
ResultString="Remote not connected!\n"
else
ResultString="WHAAAAAAAA!\n"
fi
##############################################################################
$TelegramScript msg $SendMsgTo $ResultString
Code: Select all
// #open by <[email protected]>
// Switch outputs through usb and turn them off after a delay.
// This way the remote does not stay on if something goes wrong with tg/domoticz
#include <DigiUSB.h>
int delayms = 1500;
int inputNr = 0;
void setup() {
DigiUSB.begin();
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}
void get_input() {
inputNr = 0;
int value;
while (true) { // loop forever
if (DigiUSB.available()) {
// something to read
value = DigiUSB.read();
if (value == '\n' ) {
// Breaking on newline
break;
}
if(value == '0') {
// Turning %d OFF
digitalWrite(inputNr,LOW);
}
else if(value == '1') {
// Turning %d ON
digitalWrite(inputNr,HIGH);
}
inputNr++;
if(inputNr > 2) {
// Breaking on input count
break;
}
}
// refresh the usb port for 10 milliseconds
DigiUSB.delay(1);
}
}
void loop() {
int i = 0;
// DigiUSB.println("Turn input 0-2 ON/OFF");
// DigiUSB.println("For example: 100 (0 ON, 1 OFF, 2 OFF)");
// DigiUSB.println("Waiting for input... ");
get_input();
// Turn all inputs to low
DigiUSB.delay(delayms);
digitalWrite(0,LOW);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
DigiUSB.println("OK");
}
Code: Select all
function HandleCommand(cmd, SendTo)
print("Handle command function started with " .. cmd .. " and " .. SendTo)
local found=0
local f = io.popen("ls " .. ScriptPath)
SpacePos=string.find(cmd, "% ")
HashPos=string.find(cmd, "#")
if(HashPos ~= 1) then
return found
end
if(SpacePos==nil) then
cmda = string.sub(cmd,2,string.len(cmd))
stuff = ''
else
cmda = string.sub(cmd,2,SpacePos-1)
stuff = string.sub(cmd,SpacePos+1,string.len(cmd))
end
if(Commands[cmda] ~= nil)then
loadstring('return '..cmda..'(...)')(SendTo,cmda,stuff)
found = 1
else
cmda = string.lower(cmda)
for line in f:lines() do
print("checking line ".. line)
if(line:match(cmda)) then
print(line)
os.execute(ScriptPath .. line .. ' ' .. SendTo .. ' ' .. stuff)
found=1
end
end
end
return found
end