Ewelink / Sonoff Binding - New binding without flashing

I think it may be your rule - I’m not up to speed in OH3 but…

If your using ‘changed’ then it’s going to be infinite as where there is an order of processing button 1 changes state twice before the rule has executed, so then rule executes and button 2 changes state so then the rule for the other button executes again.

I’m assuming OH3 has ‘receivedCommand’ which you could use instead so the rule only reacts when there is a physical change

What is it you want to accomplish? Do both switches control the same device? May be better ways to do what you want such as groups or 1 switch linked to 2 channels.

@delid4ve
Hi Dave
The two physical wall switches (positioned each end of room) control 3 lights between them, 1 light is hardwired to the first switch at position 0 and 2 lights to the second switch at positions 1 and 2.

I want to mirror the buttons so if you press the touch switch on 1 it mirrors that change on the other.
The touch switches glow when on, so I am trying to mirror that basically, so from either end of the room you can see the touch switch glowing no matter witch wall switch you look at.
Hope that makes sense.
looking into receivedCommand as suggested, suspect it is not in OH3.
Sounds like it’s my rule then so happy to go back into the forums and hunt down a solution.
Appreciate the response Dave!

Just checked, if you using rules dsl it’s defo there - event based triggers

rule "sync lights chalet 0 OFF"
when
Item Chalet1_Switch0 received command OFF
then
Chalet2_Switch0.sendCommand(OFF) 
end

rule "sync lights chalet 0 ON"
when
Item Chalet1_Switch0 received command ON
then
Chalet2_Switch0.sendCommand(ON) 
end

rule "sync lights chalet 1 OFF"
when
Item Chalet2_Switch0 received command OFF
then
Chalet1_Switch0.sendCommand(OFF) 
end

rule "sync lights chalet 1 ON"
when
Item Chalet2_Switch0 received command ON
then
Chalet1_Switch0.sendCommand(ON) 
end

I normally do mine like this (separate for ON/OFF/Brightness etc)… you can then add extra bits in to each logic - say for instance if you turn it on - does x and if you turn it off does y and you can add to it easily… just be careful with your ON/OFF - some things report as 0 and 100.

you can also use this logic:

Hi
there is a delay due to the message bus - dependency on just switched you may have to put a delay in
switch 1 action wait 1-5 sec check switch 1 status - switch 2 dependent on switch 1
M

Dave

I think this is just overcomplicating it though.

A switch is never going to ‘change’ by itself (unless from a rule ‘updateState’), so its simpler and cleaner to use receivedCommand here. Or just have one switch item linked to both channels (think this works with a physical switch too)

Dave
just a quick question mode mixed cloud local - As I have an often failing internet connection am I correct in asuming cloud is only needed for discovery after that local should just work…
On mixed I do get comms errors …
Cheers
Martin

cloud isn’t even required for discovery anymore :slight_smile: if the mode is set to local when discovery is run it will automatically create a http connection, do the discovery, then destroy the http connection. Just got to make sure your not blocking at a hardware level and that all devices support local mode

hoping to get some time today to take a look at the bugs.

Hi Dave
Your script looks good and logical but it is not working for me on OH3.
I will go away and have a look with fresh eyes later and see if I can figure it out.
Appreciate the help you have giving me, will also have a close look at the link you gave me also.
cheers
Regards Aaron

Dear Colleagues,

I’ve been using OH + sonoff binding for a sonoff mini and it work, then now I’ve added a new TH10 + ds18b20 and it’s collecting (reading) data from sonoff but it’s not working switch send command. Even switch are being updating when I switch from ewelink app. Does anyone has expiriences the same issue? i’m using OH 3.2.0.M1 - Milestone Build and sonoff binding org.openhab.binding.sonoff-3.2.0-SNAPSHOT_2.5r6…

@delid4ve just figure out something. If I change my bridge account to only cloud it works… Device has marked the option “Lan control” flag enable. May you know something here?

SInce binding is not working for me in different openhab installations. So my problem is that when i create account thing i get error " HANDLER_INITIALIZING_ERROR"" as i described on post above.
What i want to ask is: is there a way to create things without adding sonoff account since devices have LAN control enabled?

(i dont want to use rest api since i have to open all socets and put devices in AP mode and stuff like that)

Thanks

What version are you using…(sorry missed you said above) I fixed this in the latest version but there is another bug I found which I’m still trying to find time to fix. Can you try the latest version and make sure the th10 works

I’m hoping to have some time to bug fix very soon, bear with me as I’ve not had any time of late.

@fisker what openhab version? There are currently 3 jar versions to accommodate changes in the core system. If your using 3.1M4 or below then you need the 3.1 jar, above that 3.0.3/3.2 jar
Your error relates to javax getting changed in M5 release.

Hi @delid4ve,

Currently I am using openHAB 3.1.0 Release Build, for first time i installed 3.2.0 latest jar binding and it worked until i rebooted my raspberry pi. After that i got that error above. I have tried everything, new openhab 3.2.0 installation, all jar-s. i even installed openhabian package since i thought it might be some java problem. It is not working still :smiley: .

Here are the logs i just tried again with openhab 3.2.0 snapshot Build #2470 and jar “https://github.com/delid4ve/openhab-sonoff-compiled/raw/main/org.openhab.binding.sonoff-3.2.0-SNAPSHOT_2.5r6.jar

These errors are showing up after i try to create sonoff account thing.

Log below

2021-08-18 13:54:12.159 [INFO ] [org.apache.felix.fileinstall        ] - Installing bundle org.openhab.binding.sonoff / 3.2.0.202107250658
2021-08-18 13:54:12.798 [INFO ] [org.apache.felix.fileinstall        ] - Started bundle: file:/usr/share/openhab/addons/org.openhab.binding.sonoff-3.2.0-SNAPSHOT_2.5r6.jar



2021-08-18 13:55:20.718 [INFO ] [nternal.handler.SonoffAccountHandler] - Sonoff Access Mode set to: mixed
2021-08-18 13:55:20.787 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler@10f2ed9': Index 2 out of bounds for length 2
java.lang.IndexOutOfBoundsException: Index 2 out of bounds for length 2
	at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
	at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
	at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?]
	at java.util.Objects.checkIndex(Objects.java:372) ~[?:?]
	at java.util.ArrayList.get(ArrayList.java:459) ~[?:?]
	at com.google.gson.JsonArray.get(JsonArray.java:194) ~[bundleFile:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.setParameters(SonoffDeviceState.java:109) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.updateState(SonoffDeviceState.java:77) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.<init>(SonoffDeviceState.java:61) ~[?:?]
	at org.openhab.binding.sonoff.internal.SonoffCacheProvider.getStates(SonoffCacheProvider.java:157) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.restoreStates(SonoffAccountHandler.java:293) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.initialize(SonoffAccountHandler.java:100) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2021-08-18 13:55:20.857 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'sonoff:account:aa08e0c1b53': Index 2 out of bounds for length 2
java.lang.IndexOutOfBoundsException: Index 2 out of bounds for length 2
	at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
	at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
	at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?]
	at java.util.Objects.checkIndex(Objects.java:372) ~[?:?]
	at java.util.ArrayList.get(ArrayList.java:459) ~[?:?]
	at com.google.gson.JsonArray.get(JsonArray.java:194) ~[bundleFile:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.setParameters(SonoffDeviceState.java:109) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.updateState(SonoffDeviceState.java:77) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.<init>(SonoffDeviceState.java:61) ~[?:?]
	at org.openhab.binding.sonoff.internal.SonoffCacheProvider.getStates(SonoffCacheProvider.java:157) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.restoreStates(SonoffAccountHandler.java:293) ~[?:?]
	at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.initialize(SonoffAccountHandler.java:100) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
==> /var/log/openhab/events.log <==
2021-08-18 13:55:20.700 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'sonoff:account:aa08e0c1b53' changed from UNINITIALIZED to INITIALIZING
2021-08-18 13:55:20.859 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'sonoff:account:aa08e0c1b53' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Index 2 out of bounds for length 2

Hi DAve,

I’ve tried different versions as well latest one and didn’t work. It only works if I choose “Cloud Only”. Is there a way to collect logs or something for you? I can provide as much information you can, but I need direction how to get.

I should have time tomorrow to get on and take a look. :+1:

@mvo your openhab install is on the same network subnet as your Sonoff devices yeah? And multicast isn’t disabled? You can enable trace logging for the binding and then set it to local mode and send me them logs

Hi Dave,

I’m on 3.1.0 - Release Build. Copying the org.openhab.binding.sonoff-3.1.0-SNAPSHOT.jar binding into /usr/share/openhab/addons/ gives me the following in the log:

2021-08-19 22:42:36.039 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.sonoff-3.1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sonoff [289]
  Unresolved requirement: Import-Package: javax.measure; version="[1.0.0,2.0.0)"

	at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.16.200.jar:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:440) ~[org.eclipse.osgi-3.16.200.jar:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.8]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.8]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [bundleFile:3.6.8]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.8]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.8]

When i remove the jar file, wait a while and then try the same with org.openhab.binding.sonoff-3.1.0-SNAPSHOT_2.5r6.jar, no messages appear in the log file at all.

Suggesting this works… have you tried adding devices now?

not sure where this is from or what version… probably why it doesnt work.

I tried. Unfortunately, the binding does not show up when i try to add Things