In terms of openHAB, controlling a relay by GPIO is pretty much the same as controlling a light bulb or LED by GPIO. Have you looked at more generic examples of controlling a relay by GPIO from your Raspberry Pi? That’s probably the best place to start with this.
@trokkie Thank you for the link.
From my understanding controlling a relay from gpio is relatively easy. But what my concern is , what if I turn on the light manually from the switch in my room. Will that affect the relay? And will raspberry pi be notified regarding that? If not then how should I deal with that situation
@danielwalters86 Thank you for the information.
Yes I just looked into some examples of controlling the realy from gpio. But how to deal with situations in which light is turned on from the mains. That ways relay and gpio won’t know about it.
Could you provide me with some live in examples of this if possible?
I’m not an electrician nor an electrical engineer but I imagine designing that circuit isn’t trivial for a beginner (which I assume you are based on your question). The challenge I see here is getting some sort of feedback from your HIGH voltage side to your LOW voltage side (back into your Raspberry Pi/openHAB), in the absence of power on your HIGH side.
Have you looked at any off the shelf alternatives which may suit your needs without you doing it yourself?
There is no way for the relay to report that the light was turned on some other way. You will need something other sensor set up to report its status. There are a range of options depending on your situation and what it is you are controlling. For example, I have a relay that controls my garage door openers. I use a reed switch to report whether the garage door is open or closed. If you are controlling a light you can use a Photoresistor and a capacitor to detect when the light is on. You could use a current sensor to detect when a device is drawing power.
However, I will second @danielwalters86’s suggestion. If your main goal is to do home automation, it would be worth while to look into off the shelf solution. It will cost more but save tons of time, work, and frustration. But if you want to learn DIY electronics I can’t think of a better first project.
@rlkoshak@danielwalters86@trokkie That is quite a good amount of information for me to start with. and its true that home automation is totally about having off the shelf solutions. However, i am a newbie in electronics and seeking for some advice on how to approach towards solving common problems which are feasible enough.
Thank you so much for the valuable information.