Hello everyone, I want to make the circuit attached but I’m a beginner of OpenHub.
I use Raspberry Pi 3 model B+ with openHAB 2.3.0-1 image
I have already connected openHAb to Google Home.
The main features are:
The lamp can be switched on and off with a normal button that trigger a double step by step relay.
The lamp can also be used when the Raspberry or Google Home are offline.
I set up an open hub with an example (without much understanding) and at the moment I can set or reset a pins of the Raspberry Pi and read the status of anothers pin. What I have in part is OK, but I have to understand how to implement the logic that I need.
I need that logic state of the lamp is read by a input pin and an output pin must trigger the step by step relay for short time (ex.750ms)
Where can I start?
// home.items
// Relays for lamps
// I need that the state of lamp is read by another pin for ex. StepRelay pin 24
Switch LED "LED" ["Lighting"] { gpio="pin:21 activelow:yes initialValue:high"}
Switch LED2 "LED2" ["Lighting"] { gpio="pin:12 activelow:yes initialValue:high"}
//Generic output
Switch channel3 "Channel 3" { gpio="pin:26 activelow:yes initialValue:high" }
Switch channel4 "Channel 4" { gpio="pin:19 activelow:yes initialValue:high" }
Switch channel5 "Channel 5" { gpio="pin:13 activelow:yes initialValue:high" }
Switch channel6 "Channel 6" { gpio="pin:6 activelow:no"}
// Input
Contact DoorSensor "Door Sensor [%s]" { gpio="pin:16 debounce:10 activelow:yes" }
Contact Button "StepRelay [%s]" { gpio="pin:24 activelow:yes" }
Yes I found the relay Finder with two contact, part number in my attachment 26.02.8.230.0000.MMM.
I do not know how to program OpenHub to use this circuit, as I wrote in the post.
The circuit certainly works but what must be the script to work as described?
Thank You
Thank rossko57, it seems to me the right way, but I tried and something does not work, in fact it does not work even what previously worked. The LED no longer activates the output and the inputs no longer have the right icon in the sitemap. The three files I edited are:
// home.rules
rule "Master light control"
when
Item myLight received command // from a Rule or the UI
then
if(receivedCommand == ON && mylight.state == OFF) {
myPulse.sendCommand(ON)
} else if (receivedCommand == OFF && mylight.state == ON) {
myPulse.sendCommand(ON)
} // else already in requested state
end
rule "light feedback monitor"
when
Item myLight received update // from hardware monitor
then
if(myPulse.state == ON) { // this was an automated change
myPulse.sendCommand(OFF) // we don't time the pulse, simply stop when it has worked
logInfo("lights", "auto change complete")
} else {
// this was a manual change by wallswitch, we can do something else
logInfo("lights", "user pressing buttons")
}
end
// home.sitemaps
sitemap home label="casa"
{
Switch item=LED
Switch item=LED2
Switch item=channel3
Switch item=channel4
Switch item=channel5
Switch item=channel6
Switch item=myLight
Text item=Button
Text item=DoorSensor
}
I have a question, where and how should I define the myPulse.sendCommand (ON) myPulse.sendCommand (OFF) functions to specify the output an imput pin?
Now with your suggestion the behavior has changed. Something in the rule does not work: in fact if I set or reset the input pin the switch icon is always green (on enabled). in addition The output never activates the relay. The switch selector moves to on but if I update the browser page it returns to the left (inactive) it seems that only the second rule and not the first one work.
As I said, I don’t know GPIO. Neither of your channels look like an input channel though.
Using my example’s names, myLight is supposed to be bound to the input channel that tells openHAB if the relay is on or off.
myPulse is supposed to be bound to the output channel that controls the relay that pretends to be a pushbutton.
I really appreciate your help.
In the scenario that I described in my last post I connected a wire between the input to be used by openhub as sense and a third pin, so I can test the rules. I would expect the pin connected to the relay to follow the rule but this does not happen.
At the moment the file items are as follows:
Switch LED "LED" ["Lighting"] { gpio="pin:21 activelow:yes initialValue:high"} // Ok
// Relays
Switch channel3 "Channel 3" { gpio="pin:26 activelow:yes initialValue:high" } //Ok
Switch channel4 "Channel 4" { gpio="pin:19 activelow:yes initialValue:high" } //Ok
Switch channel5 "Channel 5" { gpio="pin:13 activelow:yes initialValue:high" } //Ok
Switch channel6 "Channel 6" { gpio="pin:6 activelow:no"} //ok
// Input
Contact DoorSensor1 "Door Sensor [%s]" { gpio="pin:16 debounce:10 activelow:yes" } // ok it follow pin 6
Switch myLight "Lighting" { gpio="pin:16 activelow:yes" , autoupdate="false" } // This pin is connected to pin 6 (Channel 6) to test the rule
Switch myPulse "Pulse output" { gpio="pin:12 activelow:yes initialValue:high" }
What I expect is that:
if the pin 6 is low and I click to switch on myLight the relay must switch on than switch off after pin 6 go low;
if the pin 6 is high and I click to switch on myLight nothing must change
if the pin 6 is low and I click to switch off myLight nothing must change
if the pin 6 is high and I click to switch off myLight the relay must switch on than switch off after pin 6 go high
rule "Master light control"
when
Item myLight received command // from a Rule or the UI
then
if(receivedCommand == ON && Sensor1.getStateAs(OpenClosedType) == OPEN)
{
myPulse.sendCommand(ON)
}
else
{
if (receivedCommand == OFF && (Sensor1.getStateAs(OpenClosedType) == CLOSED ))
{
myPulse.sendCommand(ON)
}
}
end
rule "light fb"
when
Item Sensor1 changed
then
myPulse.sendCommand(OFF)
if(Sensor1.getStateAs(OpenClosedType) == OPEN)
{
myLight.postUpdate(OFF)
}
else
{
myLight.postUpdate(ON)
}
end
sitemap home label="casa"
{
Switch item=myLight icon="light"
}
Thank You roossko57 for help.
P.S. It is necessary add a pull-up resistor between vcc and sensor pin 16 because it is not possible use Raspberry internal pull-up with open hub (I think).
I built a cheap PCB myself and bought an mains-approved case (will upload photos later).
Seems to work pretty well and I think it’s safer because it’s full of insulation, fuses, etc