Thinking of using OpenHAB but would like some advice first


(Simon Crump) #1

Hello everyone,
This is my first time posting after registering so go easy on me if I have not done anything I should or looked somewhere else first.
My reason in looking at OpenHAB is to be able to customise my smart home devices and have more flexibility.

Can anyone answer me this question please? Using openHAB on a Raspberry Pi3 can I do the following-:

Use Alexa to control reflashed Sonoff devices for two way lighting circuits using the 4 channel pro unit? The problem with using alexa for this is that if say the manual wall switch is changed, Alexa can not tell if the light is on or off! So sometimes I say ‘Alexa, turn the kitchen lights ON’, shes says ok and does nothing. I have to ask her to turn them off when they are already off, so she turns the ON. Confused? Yeah annoying eh.

I have been on at Sonoff and Ewelink and am getting nowhere.

Any advice would be greatly received. If this can be done I would like to have OpenHAB at the centre of a full home automation system. I am sick of adding more so called smart devices only to find they arnt that smart or dont like talking to each other, or make things harder than without automation.

See attached picture for my wiring, if I can figure out how to post pictures!

All the best

Crumpy


(Markus Storm) #2

openHAB is essentially tracking all device states, and you can fully program it what command to send where and when. So while your specific setup might or might not work out of the box, OH certainly can be setup to do what you want it to. Quite a number of users have successfully integrated Alexa.
Be prepared to put in some work first. though. Read the base documentation carefully to understand the basics first (OH is complex !) and follow the instructions to setup your server (recommendation: use the openHABian image for your Pi3). Check the beginners tutorial next how to setup a basic configuration and get your Sonoff and further actuators connected to OH.
No sooner than that, check out articles on Alexa and appropriate binding in the OH docs and on the forum here before you try getting it to work.


(Simon Crump) #3

Thanks for your advice, I know its going to be a vertical learning curve but hopefully worth the time invested.
As long as it is possible thats all I wanted to know. I am an experienced electrician and electronics engineer but am certainly not a software engineer or programmer. I have done a little Arduino coding, so I am hoping to be able to work through things one at a time.
I would probably setup a test bed first with a 4 channel pro and the OpenHAB on the pi, get that working properly and then integrate it in the home.

Regards

Crumpy


(Jürgen Baginski) #4

That would be the “normal” behaviour, switching something ON if it is already ON does nothing. You would have to use a rule taking the command send (from Alexa or from wherever) as the Trigger, checking the state of the switch/channel and sending the opposite state to the switch/channel,


(Simon Crump) #5

Hi Thanks for your reply,
I understand the first sentence but the rest does not mean much to me yet. I see what you mean but would not know how to start. I think once I get the Pi3 and start playing it may be more logical, we shall see.


(Simon Crump) #6

Well, I have had a vertical learning curve of the past few weeks but have managed to do the following.

Install openhab2 on the Pi3
Flash a Sonoff TH16 and a Pro 4 chan with Tasmota
Get both of them visible and working through the basic UI and the mobile App(IOS)
Install Alexa, the skill and have her fully control the Sonoffs.

Now I am stuck on where to start with making OH2 just toggle the relevant relay when Alexa sends the commands.

Ultimately, what I would like to be able to do is say ‘Alexa, Kitchen lights’ and whatever the relay state OH2 toggles the relay. Its not like we would ask for the lights to be turned on, if they are already…

I know its limiting certain functionality, say being able to have a switch on OH2 that swithes all lights off at bedtime etc but I cant think of another way, until they make a Sonoff 4 chan Pro POW that is!

Any advice where I could start learning?

Is there not a simple ‘Toggle’ somewhere? or is it not that easy.

Cheers

Crumpy


(Vincent Regaud) #7

Can you command the sonoff with openhab?
Can you publish your item definition, please?


(Vincent Regaud) #8

Unfortunately you have to say Light ON or Lights OFF at the moment
You could use a proxy item to achieve this function


(Simon Crump) #9

Hi Vincent,

yes it works well through both the mobile App and the basic UI. Items file below-:

//First Sonoff TH16
Switch SonoffTH "sonoff TH" <poweroutlet_au> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoffTH/POWER:command:*:default],<[broker:stat/sonoffTH/POWER:state:default]" }
  Number SonoffTemp "Sonoff Temperature [%.1f °C]" <temperature> {mqtt="<[broker:tele/sonoffTH/SENSOR:state:JSONPATH($.AM2301.Temperature)]"}
  Number SonoffHumidity "Sonoff Humidity [%d %%]" <humidity> {mqtt="<[broker:tele/sonoffTH/SENSOR:state:JSONPATH($.AM2301.Humidity)]"}
  
 //First 4 Channel Pro Sonoff for 2 way lighting
Switch Sonoff4ch_1Channel1 "Kitchen Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER1:command:*:default],<[broker:stat/sonoff4chan_1/POWER1:state:default]" }
Switch Sonoff4ch_1Channel2 "Family Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER2:command:*:default],<[broker:stat/sonoff4chan_1/POWER2:state:default]" }
Switch Sonoff4ch_1Channel3 "Dining Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER3:command:*:default],<[broker:stat/sonoff4chan_1/POWER3:state:default]" }
Switch Sonoff4ch_1Channel4 "Office Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER4:command:*:default],<[broker:stat/sonoff4chan_1/POWER4:state:default]" }

(Simon Crump) #10

OK, I am guessing the restriction of having to say lights ON or OFF is down to the Alexa skill integration?

So if we go with saying Turn the lights ON or OFF, could I make a rule to say whatever the state of the relay, just swap the state? ie if its On turn it Off and vice versa.

Not that I know anything about rules and it looks really forbidding at the moment. Any suggestions of a path to start walking? I am reading about rules at the moment but its going in one ear and out the other at the moment.

Cheers

Crumpy


(Vincent Regaud) #11

You could but it would be very counter intuitive. Do you see yourself asking alexa to turn the lights ON when you actually want them OFF?


(Simon Crump) #12

Ah I may not have explained myself correctly. That is exactly the situation that I have with the original Sonoff 4 chan pro units with Ewelink. Hence why I started down the Openhab route. Because I have used the pro units with relay contacts in 2 and 3 way lighting circuits, Alexa can not tell if the lights are on or off…

I am trying to figure out how to post a picture of my wiring diagram…


(Simon Crump) #13

Here we go.


(Vincent Regaud) #14

That’s off? right?


(Vincent Regaud) #15

Yes just not alexa driven though


(Simon Crump) #16

Correct it is shown in the off state


(Vincent Regaud) #17

Sorry @crumpy10
I am not very clear on what you are trying to achieve…


(Simon Crump) #18

Yes, its a hard one to explain but easy to demonstrate.:confused:

OK, A normal 2 way lighting circuit has the ability to switch the light on and off at both switches.

The way I have used the Sonoff pro is as one of those light switches, for example in my office that has one normal light switch. Great so far.

The problem I have is that Alexa, knows if one of the relays is energised or not. So lets say its getting dark in my office and I lazily(as you do with home automation!) ask Alexa to turn the office lights on. Before she does anything the circuit is as shown above Off. She then turns the relay on and the lights come on, all good. I finish the day and hit the light on the way out the door, light turns off. Now the problem occurs tomorrow when I try and ask Alexa to turn the lights on again later in the day. She thinks they are still On, because the relay is still energised. So I have to ask her to turn them Off to get them On. The same situation you described above.

Does that make sense?

Do you think there is any way around this?

Thanks for your time and patience…

Crumpy


(Vincent Regaud) #19

You need to find a way to tell OH that you turned off the light.
There are two wires going from your wall switch to your sonoff.
change the wiring.
Only the sonoff relay to drive the light
The two wires from your wall switch go to the GND and SDA on the sonoff headers
Configure the tasmota to feed bach the switch position to OH and toggle the relaly


(Simon Crump) #20

Yeah thats my obstacle at the moment.

Thats one way of doing it but due to restrictions of wiring and also if the system is down I want anyone else to be able to use the normal light switch to turn lights on. I am trying to keep the wiring standard with the addition of a relay, that way the home automation can always be updated or removed if required.

Is this possible or is it going to be very slow or not work in my situation? Is there a way I could intercept the Alexa command to openhab and do this?

Sorry I am a real novice at this but trying to learn.

Cheers

Crumpy