Controlling a 3-way power switch with relays and Odroid

Share here your ideas for new projects

Moderators: meveric, mdrjr, odroid

Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Jul 12, 2016 1:30 am

Well, I have to come clean - I'm a noob when it comes to applied electronics despite my "Electronics and Telecommunication" background. So, I need your help with some ideas.

I want to be able to close and open a window blind with the help of an odroid. The window blind is already "mechanized" and has a motor which can go forward or reverse based on input from a three-way switch. The motor is encased and away from my prying eyes, but I could take a look at the three-way switch. The switch looks like in the diagram below:

Image

When the switch is in the K2 position nothing happens, but when switched to K1 the motor raises the blinds, when switched to K3, the motor lowers the blinds. The switch locks into position (does not return automatically to K2 when no longer pressed), but the motors stop when they reach the end of their run.

I was planning on getting a SainSmart 2 channel relay (https://www.amazon.com/SainSmart-101-70 ... B0057OC6D8) and connect it in parallel with the existing switch using a wiring diagram like this:
Image

But I do face the following problems/questions:

1. From what I've read even if the relay is rated 5V, I should be able to trigger it from a 3.3V GPIO pin from a C1/C2. Can anyone confirm or deny this? Otherwise I'd need a transistor (and some resistors), but I want to keep the wiring as simple and clean as possible...

2. The relay seems to have optocouplers embedded inside - do I need anything else to protect the GPIO pin? Colleagues of mine said about adding diodes into the mix to prevent return current - shouldn't the optocoupler do that already?

3. My main concern is what happens then both the physical switch and the relay are used... If they trigger the same motor direction, then I guess it's ok, but if the trigger is in position K3 and relay 2 is triggered at the same time - I'm guessing the magic white smoke might come out of my motor... Is there a way to prevent this? Or maybe use the relays to "read" what the line state is? (I'm guessing not). I think I could replace the switch with one that returns to "0" when not pressed to prevent the accidental case when the switch is forgotten on in K1 or K3, but I still could have some corner cases when both motors are powered at the same time... Ideas?
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby LordadmiralDrake » Thu Jul 14, 2016 4:40 pm

For starters, I'd wire up the 2 relays differently. One relay connects to mains with the input and to the other relay's input with one of it's outputs. The outputs of the second relay then connect to K1 and K2.
That way, one controls power on/off and the other controls the direction. If you wire the relays as per your graphic, you'd risk having both lines to the motor switched on at the same time if there is an error in the relay control.

blinds.png
(6.41 KiB) Downloaded 520 times


As for the problematic of wiring the relays in parallel with the existing switch I think that any solution would not be that simple (since it's an AC system, so you can't just drop a few diodes in there)
LordadmiralDrake
 
Posts: 82
Joined: Wed Mar 30, 2016 6:24 pm
languages_spoken: english
ODROIDs: Odroid C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Jul 14, 2016 7:41 pm

mad_ady wrote:Well, I have to come clean - I'm a noob when it comes to applied electronics despite my "Electronics and Telecommunication" background. So, I need your help with some ideas.

Hi,

no offense, but maybe you could start with something less dangerouse than 230Vac. Just an advice ;) .

Generally I think your idea should work. I personally would have done it the same way. Of course @LordadmiralDrake's way is a little bit more safe, but also a little bit more invasive. And in addition it requires a relay that has two "switching contacts", that toggle when switching. Your (@mad_ady) way will work with most "just closing" relays.

Anyway...

mad_ady wrote: 1. From what I've read even if the relay is rated 5V, I should be able to trigger it from a 3.3V GPIO pin from a C1/C2. Can anyone confirm or deny this? Otherwise I'd need a transistor (and some resistors), but I want to keep the wiring as simple and clean as possible...

If you are using the relays you refered to, it should be no problem: the optocouplers are already some kind of 3,3V-to-5V converters. The only thing you need to check is if the ODROID GPIOs are strong enough to power the optocouplers.

mad_ady wrote:2. The relay seems to have optocouplers embedded inside - do I need anything else to protect the GPIO pin? Colleagues of mine said about adding diodes into the mix to prevent return current - shouldn't the optocoupler do that already?

No. Maybe a series resistor. Same constellation as if you'd drive a normal LED with GPIO. But in this case the "normal" LED is enclosed in the optocouplers. The freewheeling-diode is already mounted on the relay board (anti-parallel to the relay coil).

mad_ady wrote:3. My main concern is what happens then both the physical switch and the relay are used... If they trigger the same motor direction, then I guess it's ok, but if the trigger is in position K3 and relay 2 is triggered at the same time - I'm guessing the magic white smoke might come out of my motor... Is there a way to prevent this? Or maybe use the relays to "read" what the line state is? (I'm guessing not). I think I could replace the switch with one that returns to "0" when not pressed to prevent the accidental case when the switch is forgotten on in K1 or K3, but I still could have some corner cases when both motors are powered at the same time... Ideas?

What happens then depends mainly on the exact driving-circuit of the motor. In good case: nothing happens. In bad case: magic smoke.
If course it is possible to prevent it, and of course it is possible to "read" the actual line state. But this requires much more additional electronics (and knowledge). Maybe a simple fuse would be the easiest solution :roll:
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Jul 14, 2016 7:50 pm

One more thought:
maybe it would be enought to just check if the main switch is in any of its two driving-positions. It does not matter in detail in which position it is, because is is forbidden/useless to bypass it in that case anyway. So you could add some kind of circuit, that cuts the power from your "Odroid-relay-circuit" in case when the motor is powered. This could b a way to make it "safer"...
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Thu Jul 14, 2016 9:46 pm

A friend of mine suggested this circuit instead, where the first relay toggles the power line between the physical switch and the second relay which controls the direction. Would this work better than the first proposal? I would say that by cutting the input power to the physical switch I could avoid the complication where the physical switch is set differently than the relay... (https://imgur.com/qlxK9bL.png)

Image

Thank you both for your inputs. And yes, I should start with something simpler. I will play with a few leds before setting this up :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Jul 14, 2016 11:47 pm

mad_ady wrote:A friend of mine suggested this circuit instead, where the first relay toggles the power line between the physical switch and the second relay which controls the direction. Would this work better than the first proposal? I would say that by cutting the input power to the physical switch I could avoid the complication where the physical switch is set differently than the relay... (https://imgur.com/qlxK9bL.png)
Thank you both for your inputs. And yes, I should start with something simpler. I will play with a few leds before setting this up :)


Well,... I think this is basically what @LordadmiralDrake suggested ;) .

I thought you like to have it as least invasiv as possible. But now it seems you are generally open for a bigger operation ;) .
If I understand the relay addon from above correct, this should be able to cover your requirements regarding cutting the power and toggeling the direction.
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Fri Jul 15, 2016 1:35 am

Thank you - I'll keep you posted once I get the relays.

One more thing though - since this will use 220V what can I use as a case for the relay? Suggestions?
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Fri Jul 15, 2016 4:37 am

mad_ady wrote:Thank you - I'll keep you posted once I get the relays.

One more thing though - since this will use 220V what can I use as a case for the relay? Suggestions?


Sure:
270620121570_1.jpg
(146.17 KiB) Downloaded 505 times


These cases are easy to open/close, good to modify like drill holes etc, cheap and available everywhere in various dimensions :mrgreen: .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Fri Jul 15, 2016 1:37 pm

Excellent, thanks! :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Fri Jul 07, 2017 7:03 pm

I don't even feel bad for reviving this thread after a year :) It took me an year to get the time to implement it :)

So, this is the schematic I used:

Image

And this is the relay wired up:
Image

Here is the original switch (didn't take a photo of it with the new wires):
Image

I wired the relay control into GPIO pins #102 and #104, and wrote an MQTT client that would toggle the pins to cause the relay to go up or down. Here is the code:
https://github.com/mad-ady/home-assista ... t-agent.py

This agent script is controlled via MQTT from a Home Assistant instance, with the following config:
Code: Select all
cover:
  - platform: mqtt
    name: "Blinds"
    state_topic: "ha/blind_cover/get"
    command_topic: "ha/blind_cover/set"
    payload_open: 'OPEN'
    payload_close: 'CLOSE'
    payload_stop: 'STOP'
    state_open: 'open'
    state_close: 'closed'


Here it is in glorious action :
https://youtu.be/MIhuELv1244


So, I tested it out in various scenarios. With the physical switch on "neutral", I can control the window blind and can raise or lower it. If the physical switch is on the "up" position, the script causes the blind to go in "automatic mode" and I can raise or lower it, and once it's done, it switches back to manual mode - which causes the blind to go up. This is expected. When the physical switch is in the "down" position, the script tries to switch to "automatic mode", but something happened, and I managed to burn the relay module which handles manual/automatic mode selection. The C1 is fine, the motor on the blind is fine, but the relay will not "click" anymore. So, only manual mode works. I changed the relay board and got it working again, but this time I was afraid to test it again with the physical switch in the "down" position. I'm not really sure what happened and why it didn't work. Any ideas?
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby odroid » Sat Jul 08, 2017 9:43 am

Finally~ you implemented it.

Do you have any specification of the AC motor?
You might need to check the maximum current.

Or the opto-coupler on the relay board could be damaged.
Remove all the AC connections and check the opto-coupler input/output signal with a scope.
User avatar
odroid
Site Admin
 
Posts: 25345
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Sat Jul 08, 2017 1:17 pm

Yes, better later than never :)

I don't have the specification of the AC motor, so I don't know the maximum current, and it's too difficult to take the blind apart to have a look.

I will test the broken relay board with an ohmmeter, but the led indicates it gets the command to trigger, but the mechanical relay doesn't click. It could be a faulty relay module or it could be my faulty wiring.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby vorbis » Mon Jul 10, 2017 10:47 pm

Hello mad_ady,
what happened is that you welded the relay contacts together.

I know this because I used the same setup to drive a motorized video projector screen, and that's what happened to my relay board. :-)

The motors you are driving are inductive loads, and even if the current they draw during normal operation falls within the tolerances of your relays, if either relay opens while the motor is running, you get a large current surge across the relay contacts. This current is enough to weld them shut.

(This explains why the led on the relay board turns on or off as per commands, but you don't hear the "click" from the relay)

There are several ways to deal with this, but I used two RC snubber circuits in parallel with the motor (one for Up, the other for Down).
https://en.wikipedia.org/wiki/Snubber#RC_snubbers

You *could* put them in parallel with the relay contacts, but there are at least two reasons to avoid this setup: 1) you'd waste some current even when the motors aren't running, and 2) the circuit would be dangerously "live" even when the contacts are open.

The easiest way to determine the R and C values (there are several suggestions in the 'net) is to grab a relay with a clear plastic chassis (one that lets you see the contacts) and experiment with various resistors and capacitors until you don't see anymore the spark on the relay contacts when you open them.

When this happens, you can replace the test relay with your relay board of choice.
vorbis
 
Posts: 1
Joined: Mon Jul 10, 2017 10:06 pm
languages_spoken: english

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Mon Jul 10, 2017 10:58 pm

Thank you @vorbis. I had no idea about this issue. Truth is - I never worked with motors before. So, the problem can happen in either direction, provided that the relay switches on or off while the motor is running, right?
I'm not sure how big these snubber circuits are, but maybe I can fit them inside the mechanical switch case? Can you recommend any relay boards that are fit for motors (e.g. have these snubbers included)? Or is a snubber something you need to design and tweak according to the load of the motor?

I'll need to do a lot more reading on this subject. Thank you for pointing me in the right direction.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Tue Jul 11, 2017 6:25 am

Hi mad_ady,

nice, that you finished your project :) . I am planning something very similar for my house, but I have no concept, yet :oops: ...

About the snubber:
I think the exact value is not so critical. As you can see on the wikipedia-page, the snubbers there have an R of 50-150 ohms and a c of 33-100 nF. So you could just buy something around 100 ohms and 100 nF and you'll be fine.

Another thing could be improved: you could take a so called "solid-state-relay" (SSR). These are "relays" made of semiconductors, so the don't have any wear.

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Jul 11, 2017 3:42 pm

I've done a bit of reading (https://www.elprocus.com/rc-snubber-circuits/) on the induction problem and RC snubbers and I think I understand what causes it. Also - the issue should also happen even if I don't use the physical switch and only control the relay, right?

So, for components, I could use a 100 ohm resistor @ 2W and a 100nF @600V capacitor. I'll need to see where I can source the parts and how I can integrate them in my circuit in a safe way. In the mean time I'll need to avoid using the relay.

Regarding solid-state relays - I guess they still suffer from the overcurrent problem. Also, I'm not sure if internally they are decoupled optically from the control circuit. Also, the ones I found that can drive 250V AC are a bit expensive: http://www.tme.eu/en/katalog/soild-stat ... A354523%3B

I see there are pre-built snubbers on sale, but they have weird contacts: http://www.tme.eu/en/katalog/?id_catego ... 916&page=1

I'll let you know when I work something out...
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Tue Jul 11, 2017 7:46 pm

mad_ady wrote:I've done a bit of reading (https://www.elprocus.com/rc-snubber-circuits/) on the induction problem and RC snubbers and I think I understand what causes it. Also - the issue should also happen even if I don't use the physical switch and only control the relay, right?

Right.
Off-topic: And it's getting even worse/more complicated: it is another story for a mechanical switch, if it switche the load on, or if it switches the load off! The off-switching-capability is often much smaller, then the on-switching-capability. And the higher the voltage, the bigger the problem! There are switches out there, that can be switched on manually, but to switch them off, they have some kind of high-tension spring, that is charged by a motor. These switches do "Click." when you switch them on, and do "BANG!" when you switch them off ;) .

mad_ady wrote:So, for components, I could use a 100 ohm resistor @ 2W and a 100nF @600V capacitor. I'll need to see where I can source the parts and how I can integrate them in my circuit in a safe way. In the mean time I'll need to avoid using the relay.

You could go for something like this: LINK


mad_ady wrote:Regarding solid-state relays - I guess they still suffer from the overcurrent problem.

Yes, over-voltage and over-current should still be avoided.

mad_ady wrote:Also, I'm not sure if internally they are decoupled optically from the control circuit.

They are usually decoupled (in case of doubts, have a look into the datasheet).

mad_ady wrote:Also, the ones I found that can drive 250V AC are a bit expensive: http://www.tme.eu/en/katalog/soild-stat ... A354523%3B

What about this: HERE . Not expensive, or?

mad_ady wrote:I see there are pre-built snubbers on sale, but they have weird contacts: http://www.tme.eu/en/katalog/?id_catego ... 916&page=1
I'll let you know when I work something out...


Looking into the datasheet of the SSR above makes me think, that they have a snubber integrated, but I can't find the specifications... I would give it a try :)
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Jul 11, 2017 8:08 pm

Thank you Jojo for the links. They are not off-topic at all. I think I will go with the AliExpress prebuilt snubber, but the relay looks good as well :)

We'll see when they arrive.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Aug 08, 2017 6:44 pm

The snubbers have arrived! :) They're rather small and compact and I'm left with figuring out where to connect them.

So, here's the current schematic:
Image

I was thinking of adding them in paralel to the motors like this (didn't find a snubber module in Fritzing, so I drew them with a breadboard):
Image

Are there better ways of doing it?
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Aug 10, 2017 6:16 pm

Hi,

yes, putting the snubber in parallel to the motor is fine (as long as the RC-combination is in series -> most common). You should try to put the snubbers physically close to the motor, because it is desirable to kill the voltage transients close to their source: the motor winding.

And please... draw a new schematic ;) ! This schematic is... well... horrible :P . At least for me its a little bit hard to understand.
I ask, because I am not sure, that I've understood it correctly:
Code: Select all
You want to control the blinds EITHER manually OR by the ODROID

Manual control:
- bottom relay is "off"-state (like in the graphic)
- 3-way-switch can switch between both motors (motor directions)
- upper relay has nothing to do

ODROID control:
- bottom relay is in "on"-state
- upper relay can switch the voltage between both motors (motor directions)
- 3-way-switch can switch has nothing to do


If this is correct, I am wondering, why you don't want to control your blinds manually AND be the ODROID. Of course, in this case you'd have to define, this signal shall be dominant and you'd need a real 3-way manual switch with three momentary positions. But this is the way I personally would do it, because I want to be able to overwrite the automated signal manually in any case!

Think about the following real-life-usecase:
you've set the system to "automatic control" and the blinds are rolling down. Now you see, that there is a white minuature unicorn foal sitting on you window board, that will be crushed by the blinds. You want to switch back to "manual mode", but you see, that your ODROID is unresponsive. While rebooting the ODROID, the unicorn becomes... well... you know what I mean.
Your "manual mode" is controlled by software, which is really not optimal IMHO.

Greeting!
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Thu Aug 10, 2017 6:52 pm

The manual switch overrides the Odroid, not the other way around. When it's in the neutral (middle) position then the odroid takes over. In case the unicorn is observed in time I can flip the switch and override the window to rise. When I flip it back to neutral, the odroid will take over and do whatever it did before, but I don't have to flip it back.

It's like this:
You want to control the blinds EITHER manually OR by the ODROID

Manual control:
- bottom relay is "off"-state (like in the graphic)
- 3-way-switch can switch between both motors (motor directions)
- upper relay has nothing to do

ODROID control:
- bottom relay is in "on"-state and 3-way switch is in the middle position (not connected)
- upper relay can switch the voltage between both motors (motor directions)
- If I toggle the 3-way switch up or down, it will control the motor (manual override). As soon as the switch is back in the middle position, the Odroid takes over



Sorry the diagrams are messy, I tried to replicate the physical build :)

The snubbers have a capacitor in paralel to the input and a resistor and inductor in paralel with the capacitor. Is it ok to use that way?
Not sure if there will be issues with power consumption/heat if I leave the physical switch on a motor (and the circuit will be live/on for a long time)


Here's a better diagram (note the tildas make up the inductor coil)
Code: Select all

---|-----~~~~~~~~---|
   =                    |
---|--------#######--|
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Aug 10, 2017 9:25 pm

mad_ady wrote:The manual switch overrides the Odroid, not the other way around. When it's in the neutral (middle) position then the odroid takes over. In case the unicorn is observed in time I can flip the switch and override the window to rise. When I flip it back to neutral, the odroid will take over and do whatever it did before, but I don't have to flip it back.


Ok, the basic functionality is clear. But: it is still not safe. Lets talk in "colors": the manual switch is only functional, as long as the lower relay is in the state, where it connects the red line (foot contact, middle) to the green/white line. In this case, the switch can connect the green/white line either to black, or to brown (manual operation).
If the lower relay connects red-middle and red-top, the upper relay can connect red (middle) to white (and then black) or red to blue (and then brown). In this case, the switch can't do anything but "reverse-supplying" the green/white line. And THIS is the problem, at least if you want it safe.
Only the lower relay decides if you have manual control or not. And the relay is controlled by the ODROID -> relay connects middle and top contact (red and red) -> upper relay connects middle and top contact (red nd blue) -> ODROID freeze -> unicorn pancake :cry: .

mad_ady wrote:The snubbers have a capacitor in paralel to the input and a resistor and inductor in paralel with the capacitor. Is it ok to use that way?

If this is true, then it is NOT ok. There will be a constant current through the RL, as long as the motor is switched on. If you have one of those snubbers from Aliexpress, I think the fat red component is not an inductor, but another capacitor. In that case, it would be fine. Could you post a photo from the backside of the snubber PCB and a photo where we can see the printing on the fat red component?
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Thu Aug 10, 2017 10:45 pm

Sigh....
Yes, you are right. I don't know why, but I got confused. The relay works as you mention - so the Odroid overrides the switch. My bad. I don't know what I was thinking of...
So the risk is accidentally crushing somebody with the blind with no manual way to stop it. I see the problem. Do you have any recommended solution with the given parts? Maybe I could wire it differently?

Regarding the snubber, yes, they are the part you mentioned from Aliexpress. And I found some markings on one of the big red "inductors". It says "CBB21" "630V224J". And yes, it's not an inductor, but a capacitor. Right again! You must know your stuff :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Sat Aug 12, 2017 3:32 am

@Jojo: I've just installed the snubber and tested all switch/relay combinations and everything worked as desired. I haven't burned the relay this time, so hooray!
A big thanks to everyone for holding my hand through this. I learned a few good lessons (like stay away from 220V for my next projects) :)
@Jojo: Can you show me a better schematic example? Maybe there are some best practices I don't know about.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Mon Aug 14, 2017 6:30 pm

Hi and sorry for the late response. I was not at home during the weekend.

mad_ady wrote:@Jojo: I've just installed the snubber and tested all switch/relay combinations and everything worked as desired. I haven't burned the relay this time, so hooray!
A big thanks to everyone for holding my hand through this. I learned a few good lessons (like stay away from 220V for my next projects) :)
@Jojo: Can you show me a better schematic example? Maybe there are some best practices I don't know about.

You are welcome :) ! At least this is something I know a little bit about, on the other hand I have no clue about Kernel stuff or website programming. Can anyone tell me what an Apache server is ;) ?!

About the "safe way" to wire it up: well, I have a few ideas, but these are a little bit more complex than you actual solution.

First it would be good to know, how the motor works. Does is a.1) run as long as you switch on supply voltage or does it a.2) run only for a defined time/defined number of turns after switching on the supply voltage?
If a.1)
kind of tricky, because its kind of unsusual. The motor could overheat of one tries to drive it when it is already at its end position. But as I said, this is unusual for a window blind motor.
If a.2)
This is the usual case for a window blind motor. The only "tricky" part is, that the control signal must be present at least as long as it takes for the blinds to roll all way up/down. So lets say the blinds need 10 seconds to roll up (just example times) and you want to stop the automatic ride at the middle (after 5 seconds) by pressing the manual switch for lets say 1 second, then the the automatic signal will still be there for 4 more seconds. This means, that the manual signal needs to override and cancel the automated signal.

Secondly we would need to know, how your manual switch works. Is is b.1) "button style", that flips back into its neutral position when not pressed continously, or is it a b.2) momentary switch, that stays in its position once pressed?
If b.1)
This is a little bit less usual, because it is less comfortable for the user, as he needs to hold the button as long as he wants to move the blinds. On the other hand, it will (should) stop immediately at the actual position, when the user releases the button. Kind of tricky, because you'll only have "temporary manual control", because once you release the button switch, the ODROID again takes control immediately. So there won't be a constant "override signal". This means that the manual control signal needs to override and cancel the automated signal (mentioned above).
If b.2)
A little bit more usual, because the user can flip the switch to the desired direction and the switch will stay there by itself and move the blind until it reaches the end position. In this case the motor MUST stop automatically. This control scheme is like a "fire and forget" signal.
Special case: the manual switch is a button, and once pressed, the blinds roll to their end position, even if the button has been released. This case usually required a higher-level control unit that powers the motor, even of there is no button signal anymore. This is how modern digital blind control units work.

I guess from your video, you have
1. a button style manual switch, that flips pack into its neutral position when released
2. a motor that stops automatically at its end positions (your blinds look quite new, so the motor will be as well ;) )

So to control it "the safe way", your manual buttons need to override and cancel the ODROID signal in any case and no matter which button is pressed. Now the bad news: I think with your actual components, it won't be possible to control it "the safe way". And in addition, the automated control signal must be edge- and not level-triggered.
It is not, that there is no way, but it won't be that easy, because you need to handle two signal sources and levels, that are completely separated.
So we need to merge and prioritize them somehow. Either you merge them in the 230Vac domain, or in the 5Vdc domain. 230Vac is obviously much more difficult.
Actually, there is the problem, that your manual switches are switching the power for the motor directly. It would be better, if they would act like the signal trigger for some kind of "main relay". Then you could handle all signals in the 5Vdc domain, where everything will become quite easy: you could take a presatable JK-latch (like the 4027B). This thing will only forward the automated signal on every rising edge (the signal itself). If one manual switch is pressed at any time, this command will go to the "Reset" input of the JK-latch, which will kill the automated signal immediately, until the next automated command arrives. If the manual switch stays pressed, a rising edge of the automated signal will have no effect.

As I said, this won't be as easy as your actual solution, but on the other hand it will be truely no rocket science! If you dare to do some rewiring, I will help you to get things going. This will surely end up in an ODROID mag article ;) .

Greetings!
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Mon Aug 14, 2017 7:38 pm

The correct answers are:
1.b - The motor stops automatically (even if the switch is still pressed). It doesn't seem timer-based, but load-based (e.g. it spends about the same amount of time spinning the motor needlessly even if roll the blind from 0 or 90%.
2. b - The switch does not return to neutral automatically (and it's a switch, doesn't have buttons).

You don't have to go overboard with a redesign - though I'm looking for new ways to improve things I'm not looking forward to redo the wiring - I have about 6-8 wires crammed inside the original switch casing already :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Mon Aug 14, 2017 10:02 pm

Hi,

please have a look at my quick-and-dirty schematic. It might look more complicated, as it is.
Window_Blinds.png
Window_Blinds.png (15.1 KiB) Viewed 1871 times

Lets get through this in short:
S1 and S2 are your original switches. As you can see, I have changed their function. Now they give a 5V signal, when they are pressed. If not pressed, both signals are pulled low by R4 and R3.
IC3A decouples S1 and S2 and makes that both signals can overwrite/reset the ODROID signal at IC1.
IC1 is a edge-triggered JK-latch with asynchronous set/reset. The set-input is unused and pulled low, as well as the k-input by R5 and R6. If the ODROID sets one output (lets say "UP"), the signal is present at the J-input, and a little bit later there will be the clock pulse. I have delayed the clock pulse be R1/2 and C1/2, to ensure, that the logic level on the J-input is surely there before the clock pulse. If S1 OR is pressed, this signal is fed to the asynchronous reset pin and overwrites the ODROID signal.
IC3B and IC3C are for decoupling the ODROID and the switch signal.
IC1A and IC1B are just to ensure that only one signal is fed to the motor. If both switches were pressed (if it would be possible) or if the ODROID sets both signals, nothing will happen.

The final signal is now fed to your relay board where one relay drives the motor up (K1), the other down (K2). You'll still have a neutral position (both off), so you can stop the blinds in any desired position.

As you can see, only a few more components (these are really cheap and easy to solder) and some rewiring. What do you think?

Greetings

EDIT:
with my wiring style, there will be less cables going in and out of your original switch box: 3 for the 230Vac stuff (one to your relay board and two from your relay board) and 3 for the switches (one for +5Vdc and two from the switches to the logic PCB. Wiring inside the cable box will be easy, as most connections are externally/on other PCBs.
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Aug 15, 2017 12:04 am

Wow, quite a redesign! The only problem I see with this is that if anything happens to the Odroid (is stuck or not powered), I can't control the relay with just the switch. Or, I could control it, provided that the components you proposed are powered and the relay is powered as well. So a stuck Odroid could still work with manual control, but an unpowered Odroid (presuming that the relay gets 5V from the Odroid) would make the blinds stuck.

Anyway, it's a great design, and I will probably implement it once I get to the level of adding ICs to a stripboard (had to google to find out what they're called). But it will probably take a few years to get there - until my boys are old enough to know not to play with my toys and I can leave my soldering iron around :D

Edit: Also, I need to revisit some of the courses in digital circuits that I took in college more than 10 years ago, because I need to re-learn how a JK Latch works. :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Tue Aug 15, 2017 12:57 am

mad_ady wrote:Wow, quite a redesign! The only problem I see with this is that if anything happens to the Odroid (is stuck or not powered), I can't control the relay with just the switch. Or, I could control it, provided that the components you proposed are powered and the relay is powered as well. So a stuck Odroid could still work with manual control, but an unpowered Odroid (presuming that the relay gets 5V from the Odroid) would make the blinds stuck.

My design expects a constant 5V power supply, that is always on. This PSU can of course supply the ODROID as well. So if the ODROID gets stuck, it will not have any effect to the logic circuit. You still can control it with the switches. This design is NOT meant to be powerd by the ODROID :) !

mad_ady wrote:Anyway, it's a great design, and I will probably implement it once I get to the level of adding ICs to a stripboard (had to google to find out what they're called). But it will probably take a few years to get there - until my boys are old enough to know not to play with my toys and I can leave my soldering iron around :D

Edit: Also, I need to revisit some of the courses in digital circuits that I took in college more than 10 years ago, because I need to re-learn how a JK Latch works. :)

Well, I am not a pro in this logic stuff at all. I just remembered, that there was some kind of IC, where the input can be overwritten. Then I started googling ;) .
If you order the components, it should take <1 week after receipt to get it going :) . I could help you, as I said, this is not rocket science ;) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Tue Aug 15, 2017 9:54 pm

Hey,

I've just had a closer look at the truth table of the 4027B datasheet. I think it should be possible to control it that way, that you can even stop the blinds at any desired position with your ODROID :) . This means, that you have a lot more options how to use it. For example: "Lift it up 10 cm in the morning to wake you up -> lift it completely 15 minutes later -> roll them down to 50% between 11 and 15 o'clock -> lift it completely until 19 o'clock -> roll them down completely".
I think we would need to wire the Q-output to the K-input and use a separate "clock" line from the ODROID.
If you like to go that way, I can assist you by setting up a curcuit like that and test it here, if you don't have the equipment (I do).
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Wed Aug 16, 2017 3:26 pm

I thought you could already do that with your original design by controlling how long the odroid signals would last.
Anyway, for the time being I will not change the current implementation, because, frankly, it works. But as soon as I get the time and drive to play with discreete ICs, I will revisit this and do it your way. Of course, I'll build it on a breadboard first and test it thoroughly before tearing down the existing build.

Anyway, thank you for your help, but I don't want to waste anymore of your time - unless it's something you plan on building as well.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Wed Aug 16, 2017 9:13 pm

mad_ady wrote:I thought you could already do that with your original design by controlling how long the odroid signals would last.

No, because the circuit above is rising-edge-triggered. So taking away the signal (falling-edge) would have no effekt. Anyway, the change to start/stop the blinds is pretty small

mad_ady wrote:Anyway, thank you for your help, but I don't want to waste anymore of your time - unless it's something you plan on building as well.

"Don't care about me, rescue yourself!" ;) .
I am quite interested in this projec, because I am planning something very similar. The only problem is, that there is actually no motor in my window blinds at all. So starting this project will transfer my home in a construction site, thats why I am doing all this "theoretical" stuff in advance :) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Wed Aug 16, 2017 9:53 pm

Oh, I see. Then, by all means - carry on!
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Sat Oct 07, 2017 12:44 am

Hi mad_ady,

short update from my side (maybe a little bit off-topic regarding your original post):
actually I am learning a lot with Home Assistant. I have set it up on an ODROID C2 and I have added my Geiger Counter as a MQTT sensor and all my blinds/covers as MQTT covers.
For my case, this means, that the ODROID acts only as the platform for Home Assistant, and all slaves are connected via WiFi.
Every window blind (in my case 10) and every sensor (in my case only one, yet) has its own ESP8266 module, which does the WiFi-MQTT communication and translates that into the physical hardware signals.
This opens up nearly uncountable possibilities an flexibility.

I have to say, that this is not really ODROID specific stuff, as the main work is in setting um Home Assistant and programming the ESP8266 modules. But all this has bin massively inspired by your project, so I wanted to share that :) .

Actually, this basically works pretty fine... on my desk :P . Next step will be to order a "tube motor" and the manual switches to upgrade the first window blind. But I live in that house only since 4 month, so I have a bunch other things to do. I will finish one window after another. That might take some time, but I am on it.

I can keep you updated, if you want. Let me know, if I can help you somehow!

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Sat Oct 07, 2017 3:54 am

I'm glad to hear you are progressing along. I'd like to see your hardware design and you could publish your esp code for the community.
I've been recently cleaning up my code and I've added threaded execution so that you can stop the blind midway. I'm also adding support to arbitrarly position the blind (untested:https://github.com/mad-ady/home-assistant-customizations/blob/master/external-scripts/blind-cover-mqtt-agent.py). I will document it and push it toward Odroid Magazine probably next month.
There are still HA tricks and helper apps (like a wall-mounted dashboard for easy access) that I want to cover.
I'm guesssing that you'll start adding lots of new things to HA as time goes by. :)
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Mon Oct 09, 2017 11:47 pm

mad_ady wrote:I'm glad to hear you are progressing along. I'd like to see your hardware design and you could publish your esp code for the community.

Yes, I'll surely do. Although it is really not very special. It is mainly copy-paste/combination of other projects with a few adjustments for my usecase. So actually my code supports tree MQTT camands for "up", "down" and "stop", which are translated into electrical signals on the I/Os for the relays.
Also I will use "my" schematic from above with the modufication I have noted here(additional clock-signal). Otherwise, it won't work :oops: . I will create a "base board", that will carry the logic-ICs and sockets for supply, external buttons and the ESP8266 module. Sadly all this is not ODROID-specific. Thats why this is a little bit "misplaced" in this forum :( .
mad_ady wrote:I've been recently cleaning up my code and I've added threaded execution so that you can stop the blind midway. I'm also adding support to arbitrarly position the blind (untested:https://github.com/mad-ady/home-assistant-customizations/blob/master/external-scripts/blind-cover-mqtt-agent.py). I will document it and push it toward Odroid Magazine probably next month.

How do you determine the position? I mean how do you know, that the blinds are "midway"? I think that this functionality is already implementedin HA MQTT cover and so it is up to the MQTT slave/blinds controller to interpret that positioning command. Or am I wrong?

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Tue Oct 10, 2017 3:51 pm

Jojo wrote:Although it is really not very special. It is mainly copy-paste/combination of other projects with a few adjustments for my usecase.

Aren't all software projects a remix of older code? :)
So actually my code supports tree MQTT camands for "up", "down" and "stop", which are translated into electrical signals on the I/Os for the relays.

My newer code supports stop as well, but I have to rewrite everything with timer threads so that processing a mqtt message wouldn't be blocking. I suppose you have access to timers on your platform as well.
I will create a "base board", that will carry the logic-ICs and sockets for supply, external buttons and the ESP8266 module.

I'd love to see that when it's done. The reason why I stuck with just relays was to avoid having to make boards and solder components to it. I'm not ready yet :)
How do you determine the position? I mean how do you know, that the blinds are "midway"? I think that this functionality is already implementedin HA MQTT cover and so it is up to the MQTT slave/blinds controller to interpret that positioning command. Or am I wrong?

I don't read the position in any way. I use the cover.set_cover_position service call and use the internal position state in the blind mqtt agent to decide in which direction I should run the motor and for how long. I updated the code on github and it works reasonably well, but it has two caveats:
1. I'm using time as integer so I have a 1s resolution, meaning the position is not that accurate
2. If the blind is fully rolled-up and I instruct it to lower until it reaches 50% the motor will start, but the first ~3s the blind will not physically move and then it starts to move. So, the script thinks it reached 50% but it's more like 75% when it stops. The same thing happens when it's down and raises. I need to find an elegant way to account for this.
By the way you can play with the blind code and see the debug messages without a blind attached.
Regarding setting the position, there's a gui customization available here:https://github.com/andrey-git/home-assistant-custom-ui which gives you a slider next to the cover entity. Haven't tested it yet, but it's on my todo list.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Wed Oct 11, 2017 9:23 pm

mad_ady wrote:I don't read the position in any way. I use the cover.set_cover_position service call and use the internal position state in the blind mqtt agent to decide in which direction I should run the motor and for how long. I updated the code on github and it works reasonably well, but it has two caveats:

Can you explain this a little bit more in detail? Is there already a function, that determines the position of the blinds by the on-times of the motor somehow? I ask this, because I was right before writing an own function for this, but for my ESP8266, because this is the component, that knows about move commands from both HA AND the manual switches. So I wanted to set my program in some kind of "learn mode", where it counts the time from rolling from 0% to 100% and report this information back to HA.
BUT: if there IS already a function like this in HA, I'd have no need to do that. So can you explain, if this "position estimation" is already implemented in HA and how it works?
Thanks a lot!

mad_ady wrote:1. I'm using time as integer so I have a 1s resolution, meaning the position is not that accurate

Well, you could stick to integers (I always do) but use another unit, like milliseconds.

mad_ady wrote:2. If the blind is fully rolled-up and I instruct it to lower until it reaches 50% the motor will start, but the first ~3s the blind will not physically move and then it starts to move. So, the script thinks it reached 50% but it's more like 75% when it stops. The same thing happens when it's down and raises. I need to find an elegant way to account for this.

Understood. Because the position is only estimated by the motor runtime, you could define some kind if "offset"-time. In your case ~3 seconds. So lets say the blinds need 13 seconds in total to run from 0% to 100%, you could either convert the "offset"-seconds into %, so you blinds would run from -30% to 100%, but you only report the position, if it is >=0%.
OR you just report the position constantly as 0%, as long as the "offset"-time has not passed (running down). For running up, you could report the position from 0 to 10 seconds (100% to 0%) and the just let it run longer, until you "offset"-time has passed.

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Wed Oct 11, 2017 9:45 pm

Is there already a function, that determines the position of the blinds by the on-times of the motor somehow?
BUT: if there IS already a function like this in HA, I'd have no need to do that. So can you explain, if this "position estimation" is already implemented in HA and how it works?

As far as I know, HA cover entities only model the state (open/closed/unknown) and don't have (yet) an attribute that would hold the position. So it doesn't know the position, and even if you were to report it back through MQTT it wouldn't have where to store it. You could have an MQTT sensor that listens to position updates from your ESP (subscribes to the topic where you publish position changes) and remembers the state in HA, but it's decoupled from the cover entity.
The set_position call takes an arbitrary position as input. In order to know how to react to it, your ESP code needs to know the current position internally and calculate based on it.
In my code I have a currentposition int variable (https://github.com/mad-ady/home-assista ... ent.py#L57) which I update when stopping the blinds (https://github.com/mad-ady/home-assista ... #L201-L213). I also keep the last direction for the motor (up or down), so that I know how to calculate this position on stop (add or substract). Check out the implementation of runtime2position function: https://github.com/mad-ady/home-assista ... #L119-L129 for details

I'll think about your suggestion regarding offsets. I only need to apply them when the blinds are closed or open, not in-between.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Oct 12, 2017 12:56 am

Oh man... HA has a really steep learning curve :roll: .
ATM I am struggling to configure my presence detection for me and my wife. Otherwise: low WAF, low fun :lol: .

So if I get you right, then the set_position command of HA is like a fire-and-forget message, that doesn't really care, if the blinds are really reaching that position or not (state unknown)? Honestly, that does not make much sense to me. But ok, that open-source, so it's up to me to fix that - if i had the skills...

I regret that I can not test your code efficiently as my system architecture is quite different. But on the first glace (basically I don't know anything about python) it looks similar to what I am going to do.
I have added a "learning" mode, when the server sends a message with the payload "LEARN". The purpose of this mode will be to measure the time that it takes for the cover to roll all way down. In this mode I will wait for the CLOSE-message to arrive. If this happens, I start counting until the STOP-message arrives. For this function to work, it is up to the user to define the start- and end-positions as there is no feedback about the real position. Means, that I fire the CLOSE-message when the blinds are completely open, and fire the STOP-message as soon as the blinds are closed completely.
At first, this looks complicated, but it gives me the possibility to define the needed runtime individually for each blind, while keeping all other commands work as before.

Thats the theory, lets see, if it will really work ;) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Thu Oct 12, 2017 1:21 pm

Yes, HA is a bit of a beast. It doesn't have a very complicated design, but with ~1k different components you do end up spending a lot of time reading documentation.
Regarding learning functionality - it should work as you described. The only complication is you need some extra mqtt component (mqtt switch?) to signal the blind it should go in learning mode.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Thu Oct 12, 2017 10:49 pm

mad_ady wrote:Regarding learning functionality - it should work as you described. The only complication is you need some extra mqtt component (mqtt switch?) to signal the blind it should go in learning mode.

Yes, that would be the nicest way. But for now, it kind of works, when I send the command "manually" over the UI's "Developer Tools -> MQTT" function (topic: "cover/set/living_room", payload "LEARN"). Not really "best practice", but hopefully it will only be needed once per blind.
At least, that already worked on my desk (message arrived correctly). So the main work will be to actually implement the Learning-mode into the ESP. This won't be too hard, but even easy stuff needs an amount of time to be done. That's what I have not that much atm :( .

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Wed Oct 18, 2017 7:13 pm

Hi @mad_ady

alright, I have reworked the schemetic from above. If you ever had any intentions to use it, don't do it. It has major bugs :/ . For example, that it could never switch on only one relay (d'oh) :roll: .

Attached you find the reworked version:
Cover_Logic_schematic.png
Cover_Logic_schematic.png (44.62 KiB) Viewed 1155 times


As you can see, I had to add one IC: an AND-gate (IC4).

Now the logic is as follows:
- IC3A, OR-gate, merges the two signals from the manual switches to provide the reset signal for the JK-flopflop (cancel the ESP-signal)
- IC1 is a dual JK-flipflop, one for each direction (up/down). On each rising edge on the clock-input, it changes the Q/Q' output states depending on the logic level on the inputs J/K
- IC3B and IC3D, OR-gates, merge the signals from the switches and the JK-flipflop for each direction separately
- IC2A, XOR-gate makes sure, that only one signal will be fed to the final output stage. If both signals are logical high, this is some kind of forbidden/undesirable state. So this is mainly to catch software errors (usually you can not activate both manual switches at the same time).
- IC4A and IC4B, AND-gates, work together with IC2A. They only forward the signal, if ONLY one signal is present.
- IC2B and IC2C, XOR-gates, form a NOT-gate. One of both two inputs is held high, so it will negate the signal on the other input pin. These have been inserted, to be able to drive both active-high and active low relay-modules while using the same logic in software. The cool thing is, that I didn't need to add another IC, because I already had the quad-XOR anyway :) .

Here, you can have a look at the simulation of the circuit:
Cover_Logic.png
Cover_Logic.png (54.7 KiB) Viewed 1155 times


- the two channels on top are the signals of the manual switches.
- the three channels in the top-middle are from the ESP-module ("Up", "Down" and clock)
- the two signals in the bottom-middle are the final output signals
- the two signals at the bottom are the final inverted output signals

I have simulated six cases:
1. "Up"-signal from ESP-module
2. "Down"-signal from ESP-module (direct transistion from "Up")
3. "Stop"-signal from ESP-module, all four outputs go to their "inactive" state
4. Forbidden state, both signals form ESP-module are high, all outputs remain inactive
5. an ESP-signal ("Up") occurs, while the "Down"-button is pushed. The ESP-signal is ignored
6. the "Up" button is pushed, while an ESP-signal ("Down") is active. The ESP-signal gets overwritten.

Note: the pull-down-resistors are missing in the simulation circuit!

The logic circuit will even work, if I decide to just not use the ESP-module, because the signals from the switches and the ESP-module are OR-ed (tested in my desk). So removing the "Smart"-feature will be easy without any rewiring.

I have also finished the layout:
Cover_Logic_board.png
Cover_Logic_board.png (173.07 KiB) Viewed 1155 times


I have designed it that way, that one could "relatively easy" manufacture it at home. Thats why I have only a few bridges on the top layer, while the rest is on the bottom layer (it is relatively complicated to manufacture a double-/multilayer PCB at home). The top-GND-plane is not needed to be a solid plane, bacause there are vias to make connections for orphaned bottom-GND-planes. I just added it as a solid plane as well, because this will be better for the etching process in case that one is able to produce a double-sided PCB.
Please keep in mind, that I am not a hardware engineer, so there might surely be room for improvements ;) .

Here is how a breadboard setup could look like:
IMG_20171017_215441b.jpg
IMG_20171017_215441b.jpg (203.82 KiB) Viewed 1155 times


I'll trigger the manufacturing of a prototype. If it is ok for you (@mad_ady), I'll keep hijacking this thread for my stuff, as it has been fundamentally inspired by your project.

Greetings!
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby mad_ady » Wed Oct 18, 2017 7:49 pm

That's quite a breadboard you have there! I understand your design choices (and feel free to keep posting - I'm sure it's inspirational for others as well), but I'm left wondering wether it could have been done with fewer logic gates/wires. Meaning - hook up the digital switch through some resistors directly to the esp pins so you can always read its state and hook up the relays to the esp output pins so the esp controls it every time. This would violate the principle of being able to operate the blind without the esp, but it would be a simpler setup, without any custom boards. I guess I could have done the same with the odroid if I had used the switch at low voltage.
User avatar
mad_ady
 
Posts: 2890
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Controlling a 3-way power switch with relays and Odroid

Unread postby Jojo » Wed Oct 18, 2017 8:45 pm

mad_ady wrote: but I'm left wondering wether it could have been done with fewer logic gates/wires. Meaning - hook up the digital switch through some resistors directly to the esp pins so you can always read its state and hook up the relays to the esp output pins so the esp controls it every time. This would violate the principle of being able to operate the blind without the esp, but it would be a simpler setup, without any custom boards. I guess I could have done the same with the odroid if I had used the switch at low voltage.

Of course, this is totally true. But is has one downside: this princple will fail, if the software hangs. Don't get me wrong, I am kind of programmer, so I usually know how to do it. But on the other hand, I know, that it is more likely to have a software bug, then an error in the hardware design.
I wanted to be independent from software, when it comes to "safety things" (think about the unicorn on your window board), that's something I learned in my working life. Example: I know, that there are grid inverters, that have all the critical protection stuff (overcurrent, overvoltage, etc.) handled in hardware and only the actual state of the hardware is monitored by the software. Their design motto was "Hardware needs to protect itself" and from my point of view, this is a really good approach.
Thats the only reason why I invested so much silicon ;) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 449
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2


Return to The Ideas

Who is online

Users browsing this forum: No registered users and 1 guest