Momentary On Using Pi GPIO To Control Garage Door

9 years 2 weeks ago #2496 by EasyIoT

lennysh wrote: I made a RPiGPIO module that controls the Pin, and a virtual switch to turn that pin on and off, but did I even need to create the RPiGPIO module at all? Is there anyway to control the Pin without having a module added for it? I guess it wouldn't be a big deal if you could hide the module (would be a nice feature in the next version) from the main screen. I'd hate for the relay to get turned on and left on by accident.


Just add module, but do not add module to the group. If you do not add module to group, then it will not be visible in main screen.
The following user(s) said Thank You: lennysh

Please Log in or Create an account to join the conversation.

9 years 1 week ago #2497 by Boaz101
Here's what I ended up doing. I have a reed switch hooked up to my garage door and coming back to GPIO Pin 7 on the Raspberry Pi (input, pullup resistor enabled). On my garage door wall switch I jumped the micro switch on either side and connected it to the outputs of a relay. I have the inputs to the relay hooked up to GPIO Pin 3 on the Raspberry Pi (output). Then I added a virtual switch to the interface and use that to control the automation program below. It activates the relay for a little while and then turns it off to open or close the door depending upon the state of the garage door. It also is self healing if someone uses the wall switch to open or close the door. If Sensor.DigitalValue is null then you have to set the parameter value to 0 in the groups and modules. I also have a relay hooked up to the lock button so I can control that too.

private const string GarageSwitchAddr = "Pin_P1_03";
private const string GarageDoorStatusAddr = "Pin_P1_07";
private const string GarageDoorLockAddr = "Pin_P1_11";
private const string GarageDoorVirtualSwitchAddr = "N5S0";
private const string GarageDoorVirtualLockAddr = "N4S0";

/*
This code is running one time when program is enabled
*/
public void Setup()
{
Console.WriteLine("Setting up garage door automation");
// Event handler runs for every event from any driver
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id " + Program.ProgramId.ToString() + " property " + p.Property + " value " + p.Value + ", Domain: " + m.Domain.ToString());

if (m.Domain == Domains.RPIGPIO && m.Address == GarageSwitchAddr && p.Property == "Sensor.DigitalValue")
{
Console.WriteLine("inside block for Garage Door Switch Relay");
}
// Garage door switch
else if (m.Domain == Domains.VIRTUAL && m.Address == GarageDoorVirtualSwitchAddr && p.Property == "Sensor.DigitalValue")
{
Console.WriteLine("inside block for virtual switch " + GarageDoorVirtualSwitchAddr + " garage door switch");
ModuleParameter garageDoor = ModuleHelper.GetProperty(Domains.RPIGPIO, GarageDoorStatusAddr, "Sensor.DigitalValue");
Console.WriteLine("check if null");
if (garageDoor != null)
{
Console.WriteLine("not null");
if (garageDoor.Value == "0" && p.Value == "1")
{
Console.WriteLine("Garage door is closed, openning...");
OpenCloseGarageDoor();
}
else if (garageDoor.Value == "1" && p.Value == "0")
{
Console.WriteLine("Garage door is open, closing...");
OpenCloseGarageDoor();
}
// otherwise the garage door is already in the correct position, nothing to do
else
{
Console.WriteLine("Garage door value {0}, p.Value {1}", garageDoor.Value, p.Value);
}
}
else
{
Console.WriteLine("garageDoor was null");
}
}
else if (m.Domain == Domains.RPIGPIO && m.Address == GarageDoorStatusAddr && p.Property == "Sensor.DoorWindow")
{
Console.WriteLine("Garage door sensor: door is now {0}, fixing virtual switch", p.Value == "0" ? "closed" : "open");
DriverHelper.ProcessCommad(Domains.VIRTUAL, GarageDoorVirtualSwitchAddr, p.Value == "0" ? "ControlOff" : "ControlOn", "");
}
// Garage door lock
else if (m.Domain == Domains.VIRTUAL && m.Address == GarageDoorVirtualLockAddr && p.Property == "Sensor.DigitalValue")
{
Console.WriteLine("Locking/Unlocking garage door");
LockUnlockGarageDoor();
}
return true;
});
}

// Turn on relay momentarily to trigger garage door
public void OpenCloseGarageDoor()
{
DriverHelper.ProcessCommad(Domains.RPIGPIO, GarageSwitchAddr, "ControlOn", "");
System.Threading.Thread.Sleep(1000);
DriverHelper.ProcessCommad(Domains.RPIGPIO, GarageSwitchAddr, "ControlOff", "");
}


// Turn on relay for 7s+ to unlock or lock garage door
public void LockUnlockGarageDoor()
{
DriverHelper.ProcessCommad(Domains.RPIGPIO, GarageDoorLockAddr, "ControlOn", "");
System.Threading.Thread.Sleep(7500);
DriverHelper.ProcessCommad(Domains.RPIGPIO, GarageDoorLockAddr, "ControlOff", "");
}

/*
This code is running periodicaly when program is enabled.
Cron job determine running period.
*/
public void Run()
{
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.239 seconds

Forum latest

  • No posts to display.