Ewelink / Sonoff Binding - New binding without flashing

New Version:

Sorry @tizen completely missed this…hmm so seems ive overlooked lan mode when changing to the cache method. So discovery isnt going to work (atm)
Could you add in normal mode via the app first create the cache file. then change your device to lan mode and add it manually.
Let me know the result, and if it works can you send me some trace logs so i can see the lan responses.

@DimitriR ive just fixed battery channel, will post up shortly

here you go @DimitriR (youll probably have to remove the device and re-add as the channel is now called battery not batteryVoltage).
2.5: SonoffJars/org.openhab.binding.sonoff-2.5.13-SNAPSHOT_v2.1r15.jar at main · delid4ve/SonoffJars · GitHub
3.x: SonoffJars/org.openhab.binding.sonoff-3.1.0-SNAPSHOT_v2.1r15.jar at main · delid4ve/SonoffJars · GitHub

Hi @delid4ve, In “Things” window, Channels tab, when expanding Humidity (item linked already), I see “Err” and the log shows this:

18:40:06.609 [WARN ] [se.internal.SseItemStatesEventBuilder] - Exception while formatting value '37' of item KidsSensor_Humidity with format '%.1f %RH': Conversion = 'R' 

And temperature reads -244.9 degrees centigrade.

and the Switch is still giving an error as it seems it’s trying the LAN mode rather than Cloud mode:

18:42:54.432 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'KidsSensor_Switch' received command ON
18:42:54.434 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'KidsSensor_Switch' predicted to become ON                                              
18:42:54.439 [DEBUG] [noff.internal.handler.HandlerBaseDual] - Sonoff - Command Payload:{"switch":"on"}
18:42:54.441 [DEBUG] [ff.internal.messaging.MessageProvider] - Message Type added: 1616164974441 - switch
18:42:54.442 [DEBUG] [onoff.internal.handler.HandlerAccount] - Sending message via LAN
18:42:54.440 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'KidsSensor_Switch' changed from OFF to ON
18:42:54.443 [DEBUG] [nding.sonoff.internal.connections.Lan] - Send LAN Update to http://192.168.1.106:8081/zeroconf/switch with unencrypted payload:{"switch":"on"}
18:42:54.630 [DEBUG] [nding.sonoff.internal.connections.Lan] - Lan response received: {"seq":1421,"sequence":"1616164974441","error":422}

2.5.x:SonoffJars/org.openhab.binding.sonoff-2.5.13-SNAPSHOT_v2.1r17.jar at main · delid4ve/SonoffJars · GitHub
3.x:SonoffJars/org.openhab.binding.sonoff-3.1.0-SNAPSHOT_v2.1r17.jar at main · delid4ve/SonoffJars · GitHub

above updated to r17

Dave and Emre hi. First for Dave my DW2 works very well.
A last question (I hope) I try to display the battery voltage info which I see in the **log 2.813 but I selelct in the channel link **
JSONPATH:$.DoorTrap1.battery and format %.3f and as you see in the log below it cannot transform. I tried all sorts of device names DoorTrap1 , DeviceID , even the channel-linik name with no success.
I know I am distracting you from the main subject but probably someone or you can advise on how to format . Thank
Dimitri

openhab> log:tail
23:30:48.439 [DEBUG] [onoff.internal.handler.HandlerAccount] - Sonoff Connection Check Running
23:30:51.574 [DEBUG] [sonoff.internal.connections.Websocket] - Websocket Sending Message:ping
23:30:51.581 [DEBUG] [nding.sonoff.internal.connections.Api] - Api Discovery Request:{"appid":"oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq","nonce":"zmsJ4ApQ","ts":1616189451581,"version":8}
23:30:51.658 [DEBUG] [sonoff.internal.connections.Websocket] - Pong Response received
23:30:51.805 [DEBUG] [nding.sonoff.internal.connections.Api] - Api Devices response:{"error":0,"msg":"","data":{"thingList":[{"itemType":1,"itemData":{"name":"DoorTrap1","deviceid":"1001038d41","apikey":"92cdd98d-13a3-4578-8e01-839a747dfc95","extra":{"uiid":102,"description":"20201022001","brandId":"5c4c1aee3a7d24c7100be054","apmac":"d0:27:02:07:17:d3","mac":"d0:27:02:07:17:d2","ui":"WiFi门磁","modelInfo":"5e1541388ceaa2dd27be4af4","model":"OPL-DMA-GL","manufacturer":"深圳松诺技术有限公司"},"brandName":"SONOFF","brandLogo":"https://eu-ota.coolkit.cc/logo/q62PevoglDNmwUJ9oPE7kRrpt1nL1CoA.png","showBrand":true,"productModel":"DW2-Wi-Fi","devConfig":{"lowVolAlarm":2.6},"settings":{"opsNotify":0,"opsHistory":1,"alarmNotify":1,"wxAlarmNotify":0,"wxOpsNotify":0,"wxDoorbellNotify":0,"appDoorbellNotify":1,"doorOnNotify":1,"doorOffNotify":1},"devGroups":[],"family":{"familyid":"603aa822a2965000071f8c52","index":0,"roomid":"603aa822a2965000071f8c4f"},"shareTo":[],"devicekey":"bb148e58-4ca6-43c1-82ae-730ee32fc75d","online":false,"params":{"bindInfos":{},"switch":"off","battery":2.813,"fwVersion":"1000.2.924","type":4,"chipID":"d027020717d2","mac":"d027020717d2","rssi":-92,"lastUpdateTime":"2021-03-19T21:20:36.191Z","actionTime":"2021-03-19T20:36:07.779Z"},"denyFeatures":["sceneClick"]},"index":0}],"total":1}}
23:30:51.826 [DEBUG] [ff.internal.messaging.MessageProvider] - Forwarding state to 1001038d41
23:30:51.844 [WARN ] [rofiles.JSonPathTransformationProfile] - Could not transform state '2 V' with function '$.MainEntranceDoorTrap1_Voltage.battery' and format '%.3f Volts'

Where are you trying to transform it?
The battery voltage is as follows:

QuantityType<ElectricPotential>

with unit type as VOLT

See here for conversion help:

Without any transformation or custom unit does your 2.813 display correctly? I may not have put enough decimal places so will check tomorrow

2.5: SonoffJars/org.openhab.binding.sonoff-2.5.13-SNAPSHOT_v2.1r18.jar at main · delid4ve/SonoffJars · GitHub
3.1: SonoffJars/org.openhab.binding.sonoff-3.1.0-SNAPSHOT_2.1r18.jar at main · delid4ve/SonoffJars · GitHub

battery fix

Updated the latest r18 bindings, S26 works fine but 1ch basic got the following error:

2021-03-20 15:06:12.428 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'sonoff:1:f25abd857d:8ef70e99da': class org.openhab.binding.sonoff.internal.states.StateUnknown cannot be cast to class org.openhab.binding.sonoff.internal.states.State1 (org.openhab.binding.sonoff.internal.states.StateUnknown and org.openhab.binding.sonoff.internal.states.State1 are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1198b01)

java.lang.ClassCastException: class org.openhab.binding.sonoff.internal.states.StateUnknown cannot be cast to class org.openhab.binding.sonoff.internal.states.State1 (org.openhab.binding.sonoff.internal.states.StateUnknown and org.openhab.binding.sonoff.internal.states.State1 are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1198b01)

	at org.openhab.binding.sonoff.internal.handler.Handler1.updateDevice(Handler1.java:1) ~[?:?]

	at org.openhab.binding.sonoff.internal.handler.HandlerBaseDual.initialize(HandlerBaseDual.java:82) ~[?:?]

	at jdk.internal.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) ~[?:?]

	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:834) [?:?]

@phui can you try deleting your thing and the file that relates to it under userdata/Sonoff , running discovery and then re-adding. Just want to check it’s not a hangover before I dive in

Dave hi,
1.I created thing named : DoorTrap1
2. Went to channels of this thing …it shows all channels i.e. switch , Battery Level (which is a number…) …etc etc,…
3.Selected Battery Level channel because I want to display battery voltage
and created the link , but it displays 2 for the Battery Level instead of 2.813 Volts (which I see in the log)
4.In order to see the voltage (number) with 3 decimals , under profile ,I selected JSONPATH instead of no profile
5. I enter in JSONPATH formatter the following : $.DoorTrap1.battery …as it appears on the log above. i.e. device = DoorTrap1, battery and in State formatter = %.3f Volts
6. I save the link , but it seems the format is not working. In the attached jpg

shows 2 instead 2.813 Volts
I must be missing something elementary !!!
Thanks
Dimitri

@DimitriR Can you try deleting the thing and then clearing the cache.
The channel was changed from Number to Number:ElectricPotential
There was an error in that it was fetching the value as an integer but that’s changed now to a double so should work

Try delete all things including the account things. then delete the 2 txt file in userdata/sonoff
re-add the a/c things, then scan… S26 discovered successfully but not the 1 ch basic
Try manual add the 1 ch basic and got the following error again:

2021-03-20 17:55:28.506 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'sonoff:1:41110fc1cf': class org.openhab.binding.sonoff.internal.states.StateUnknown cannot be cast to class org.openhab.binding.sonoff.internal.states.State1 (org.openhab.binding.sonoff.internal.states.StateUnknown and org.openhab.binding.sonoff.internal.states.State1 are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1198b01)

java.lang.ClassCastException: class org.openhab.binding.sonoff.internal.states.StateUnknown cannot be cast to class org.openhab.binding.sonoff.internal.states.State1 (org.openhab.binding.sonoff.internal.states.StateUnknown and org.openhab.binding.sonoff.internal.states.State1 are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1198b01)

	at org.openhab.binding.sonoff.internal.handler.Handler1.updateDevice(Handler1.java:1) ~[?:?]

	at org.openhab.binding.sonoff.internal.handler.HandlerBaseDual.initialize(HandlerBaseDual.java:82) ~[?:?]

	at jdk.internal.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) ~[?:?]

	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:834) [?:?]

Thanks in advance.

@phui Can you send me debug log from when you add the binding and also the cache file. Strange… it should be uiid1 but it’s not picking up the correct state for some reason and using a default of unknown. Could also try a cache clear

Dave hi
I upgraded to r17, deleted cache , thing etc , restarted OH3, recreated DoorTrap1 Thing . I kept the account thing. Still Voltage is truncated.
Question ; Do I have to use No profile to see the voltage with 3 decimals ?
or do I have to use JSONPATH profile which I have tried too but I am not sure if the info I enter in the JSONPATH expression and state formatter to %.3f Volts
As you can see in the log below the battery voltage is now 2.8.instead 2.813
and the warning message shows it cannot transform state.
What function do I need to use ? What am I doing wrong ? Thanks
Dimitri

{},"switch":"on","battery":2.8,"fwVersion":"1000.2.924","type":2,"chipID":"d027020717d2","mac":"d027020717d2","rssi":-89,"lastUpdateTime":"2021-03-20T13:10:39.804Z","actionTime":"2021-03-20T13:10:39.804Z"},"denyFeatures":["sceneClick"]},"index":0}],"total":1}}
15:11:11.223 [DEBUG] [ff.internal.messaging.MessageProvider] - Forwarding state to 1001038d41
15:11:11.229 [WARN ] [rofiles.JSonPathTransformationProfile] - Could not transform state '2 V' with function '$.battery' and format '%.3f Volts'

Where are you trying to transform it?
In the UI , where I link item to channel see below image
Thanks

Well that’s why as it’s r18 that has the fix in above

I’m on 2.5.13 r18, the account thing is online but during discovery nothing is found.
this is the log:

2021-03-20 17:09:55.644 [INFO ] [inding.sonoff.internal.MainDiscovery] - Discovered device 10002a293f
2021-03-20 17:09:55.647 [ERROR] [inding.sonoff.internal.MainDiscovery] - Unable to add 10002a293f as its not supported, please forward the cache file to the developer
2021-03-20 17:10:19.889 [ERROR] [f.internal.messaging.MessageProvider] - Error Running queue:null
2021-03-20 17:11:09.972 [ERROR] [f.internal.messaging.MessageProvider] - The device 10002a293f doesnt exist, unable to set state
2021-03-20 17:11:23.401 [INFO ] [inding.sonoff.internal.MainDiscovery] - Discovered device 10002a293f
2021-03-20 17:11:23.403 [ERROR] [inding.sonoff.internal.MainDiscovery] - Unable to add 10002a293f as its not supported, please forward the cache file to the developer

Send me the file under userdata/sonoff

Dave hi
Upgraded to r18 , there is progress. As you see in the picture it shows voltage 2.800 V


Now the problem is shifted in the log , where battery voltage in the past appeared with 3 decimals i.e. 2.813, now appears truncated 2.8 as you can see in the log below and it only adds two zeros in UI formatting. We are getting there , Thanks , Dimitri.

730ee32fc75d","online":false,"params":{"bindInfos":{},"switch":"off","battery":2.8,"fwVersion":"1000.2.924","type":3,"chipID":"d027020717d2","mac":"d027020717d2","rssi":-88,"lastUpdateTime":"2021-03-20T16:57:53.112Z","actionTime":"2021-03-20T16:57:53.112Z"},"denyFeatures":["sceneClick"]},"index":0}],"total":1}}

That’s correct.
The current value is 2.8 in the log (that’s the data straight from the device unchanged) so the .3 decimal places adds 2 zeros
If it were 2.813 then it would show 2.813