Shelly Binding

Hi, thank you for your feedback. For now I will just stick to the current solution and try OpenHab with Alexa when I have some time for it. I will of course follow the topic here as well.

Hi Patrik,
any progress with your binding?

Currently there is nothing new. I’ve done so much work that I can not keep working on it. I hope to have some more time by the end of the year.

Could you share the code for the current status? Maybe we could work together. I hVe it running with mqtt, but looking for a PaperUi based approach and auto discovery. Already did some bindings so that‘s not the problem. @hmerk already has the auto discovery running.

2 Likes

fyi: @hmerk and I started working on a native binding and making good progress. I think next week we have something to test

3 Likes

I‘m making good progress already covering most of the features for Shelly1/2/2.5, @hmerk will add the HT., 1PM should work if 1 is dine.

Who could do some testing for the other device types?

1 Like

I’ll be happy to test when possible.

/t

sounds good, which devices do you have?

I can also help with testing. After I have set up the development environment I can also help with debugging especially for devices that you can’t test.

I have got the following devices:

  • Shelly Plug S
  • Shelly Sense
  • Shelly Buld
1 Like

good to know

I checked in my current status, it’s work in progress, just as a snapshot for debugging purposes! Do not use this status when you expect a working binding.

Still 2 issues on the list I need to fix before I could share an alpha release:

  • The setShellyHandlerFactory is not called in the Callback/Servlet class - this is required to be able passing the event callback to the ClassFactory and dispatching to the things. The callback event is triggered by the device when the status of S1/O1 or S2/O2 changes (for the Shelly 1/2/2.5) or a sensor update is available (HT). Events are already working in general, that’s the last missing piece. Event handling might be replaced by Coap events when we get this working. Otherwise the handling has to be optimized for battery driven devices to avoid draining the battery.
  • The ESH-XML has a syntax problem (which is displayed in the debugger). Things are created and get online, but the channel updates fails, mostly because of the malformed XML - need to look into details
  • for now I didn’t found to read the status of S1/O1+S2/O2 when the thing initializes. The doc describes “show and set the status”, but the call doesn’t return the current status - no the baddest thing, just creates some inconvenience on OH restarts

Support for the Shelly relays and rollers is almost done. There are some more attributes, which might be useful, but those could be added at a later stage.

Support for Plug/PlugS and the Bulb should be easy to integrate. The json structures are usually the same across devices. I want to have explicit handling for each device type so we could also utilize additional/new features.

Shelly Sense is very specific and requires a lot of typing. In addition I need to understand how it works = what is required to support it in a proper way (there are tons of config options).

In general I have to say that the documentation is useful, but not bugfree and sometimes incomplete (e.g. the event urls are not described, I found them while debugging the return JSON).
@MHerbst Maybe you could contribute the GSON mapping for the Sense (internal.api/ShellyApiJSon.java).

Please make sure to send the log level to TRACE. Especially the startup sequence to unsupported devices are interesting. Please post the log here or send me a PM.

http authentication is not yet support, so you need to turn that off for now
One note: Shelly does NOT encrypt or hash the http user credentials in the return JSON so you may want to remove them before posting a log. For me this is a security issues, which should be changed by Shell.

I added a first .jar build to the repo - this is work in progress - just as a snapshot for debugging purposes! Do not use this status when you expect a working binding.
https://github.com/markus7017/org.openhab.binding.shelly/blob/alpha1-wip/target/org.openhab.binding.shelly-2.4.0-SNAPSHOT.jar

Please make sure to send the log level to TRACE. Especially the startup sequence to unsupported devices are interesting. Please post the log here or send me a PM.

http authentication is not yet support, so you need to turn that off for now
One note: Shelly does NOT encrypt or hash the http user credentials in the return JSON so you may want to remove them before posting a log. For me this is a security issues, which should be changed by Shell.

I have a couple of shelly 1 V.3 lying around doing nothing at the moment.

/t

1 Like

Here are my first test results: I have copied the jar file to the addons folder of my openHAB 2.4 installation. The binding did not load because it was missing the Californium bundle. So I installed the Tradfri binding which also uses this bundle.

Auto discovery did not find any of my devices.

I will send you the trace as PM.

Unfortunately I don’t have a running development environment for openHAB 2.4 resp. a Tycho-based environment. I will install the latest development environment and try to convert the structure of the add-in to the new bndtools-based environment.

That’s correct, the Tradfri binding brings californium so no need to install the dependencies manually. I’ll find out, which components to install (feature:install) and add that to the readme.

“Auto discovery did not find any of my devices”. The binding uses mDNS, did you tried a runtime environment or IDE? I had/have the same problem in the IDE whereas it found the devices in the runtime environment on the same system.

I’ll stay on 2.4 as long as I have the feeling that 2.5 is stable. So also my dev & test environment is 2.4.

I added detection of shellyplug and shellyplug-s and avoid an Exception when a json config parameter is not available.
https://github.com/markus7017/org.openhab.binding.shelly/blob/alpha1-wip/target/org.openhab.binding.shelly-2.4.0-SNAPSHOT.jar

Running a manual scan also helps when the device is not discoverd or a restart in the IDE.

@MHerbst please try again

The feature that has to be installed on the OH console is openhab-transport-coa

feature:install openhab-transport-coap

this makes installation of the Tradfri binding obsolete

1 Like

Doing a
mvn clean install karaf:kar
should build a kar file with the needed dependencies. That kar file can be copied into addons folder.

I checked in a new build (alpha1)
https://github.com/markus7017/org.openhab.binding.shelly/blob/alpha1-wip/target/org.openhab.binding.shelly-2.4.0-SNAPSHOT.jar

Changes:

  • xml definitions fixed
  • channels are now updating
  • more channels for the Plug S (LED control)
  • channels for roller fixed
  • thing definitions share a generic config definition

This is the first build, which provides regular functions

  • Shelly 1
    not tested, but should work as the Shelly 2 limited to 1 relay
  • Shelly 1PM
    not tested
  • Shelly 2 - relay mode
    turn the output
    meter reading
    read overpower flag
    open: send relay events to a trigger channel
    open: need to check the auto timer, sees like incorrect documentation
  • Shelly 2 - roller mode
    turn the roller
    set roller position
    meter reading
    read overpower flag
    get stop state (incl. obstacle detection)
    open: send relay events to a trigger channel
    open: there are some channels, which doesn’t get updated properly
    open: need to check the timer, sees like incorrect documentation
  • Shelly HT
    discovery should work
    currently no channels, will be added soon
  • Shelly Bulb, Sense, RGW2
    not yet supported

Please make sure to delete ALL things before installing the new version (thing definitions have changed). If the things get not discovery immediately be patient, wait some time and retry a manual scan - this might have to be done several times.

Next build will be alpha2 (please make sure to use the current release in the repo / correct download link)

alpha2 is online
https://github.com/markus7017/org.openhab.binding.shelly/blob/alpha2/target/org.openhab.binding.shelly-2.4.0-SNAPSHOT.jar

  • Channels for Shelly HT added
  • Shelly Smoke added
  • Shelly Bulb added
  • relay “output” channel fixed: get correct ON/OFF status
  • channels for battery devices added

Shelly HT, Shelly Bulb, Shelly Smoke are not verified - please help testing. @MHerbst

Does someone has a Shelly Smoke. The documentation seems to be incorrect, it includes only temperature sensor data, but no smoke alarm. I expect a smoke sensor to report a smoke alarm.

1 Like

I have performed the first tests (alpha1) with a Shelly Plug S.
The discovery did not work:

2019-07-15 20:13:22.068 [WARN ] [discovery.ShellyDiscoveryParticipant] - Discovered Shelly device doesn't have an IP address: [ServiceInfoImpl@10810566 name: 'shellyplug-s-376D1F._http._tcp.local.' address: '(null):0' status: 'DNS: JmDNS-/192.168.2.80 [/192.168.2.80] state: probing 1 task: null', has NO data
        shellyplug-s-376D1F._http._tcp.local.: ]
2019-07-15 20:13:22.080 [INFO ] [discovery.ShellyDiscoveryParticipant] - Shelly device discovered: IP-Adress=192.168.2.73, name=shellyplug-s-376d1f
2019-07-15 20:13:22.266 [DEBUG] [helly.internal.handler.ShellyHandler] - Shelly settings info : {"device":{"type":"SHPLG-S","mac":"CC50E3376D1F","hostname":"shellyplug-s-376D1F","num_outputs":1,"num_meters":1},"wifi_ap":{"enabled":false,"ssid":"shellyplug-s-376D1F","key":""},"wifi_sta":{"enabled":true,"ssid":"Ankh-Morpork","ipv4_method":"static","ip":"192.168.2.73","gw":"192.168.2.1","mask":"255.255.255.0","dns":"192.168.2.1"},"wifi_sta1":{"enabled":false,"ssid":null,"ipv4_method":"dhcp","ip":null,"gw":null,"mask":null,"dns":null},"mqtt": {"enable":false,"server":"192.168.33.3:1883","user":"","reconnect_timeout_max":60.000000,"reconnect_timeout_min":2.000000,"clean_session":true,"keep_alive":60,"will_topic":"shellies/shellyplug-s-376D1F/online","will_message":"false","max_qos":0,"retain":false,"update_period":30},"sntp": {"server":"time.google.com"},"login":{"enabled":false,"unprotected":false,"username":"xxxx","password":"xxxx"},"pin_code":"xxx","coiot_execute_enable":true,"name":"","fw":"20190711-084501/v1.5.0-hotfix4@3b4f7414","build_info":{"build_id":"20190711-084501/v1.5.0-hotfix4@3b4f7414","build_timestamp":"2019-07-11T08:45:01Z","build_version":"1.0"},"cloud":{"enabled":true,"connected":true},"timezone":"Europe/Berlin","lat":50.110901,"lng":8.682130,"tzautodetect":true,"time":"20:13","hwinfo":{"hw_revision":"prod-190325-test","batch_id":1},"max_power":2500,"led_status_disable":true,"led_power_disable":false,"relays":[{"ison":true,"has_timer":false,"overpower":false,"default_state":"off","auto_on":0.00,"auto_off":0.00,"btn_on_url":null,"out_on_url":null,"out_off_url":null,"schedule":true,"schedule_rules":["1730-0123-on","2350-0123456-off","0800-456-on"]}],"meters":[{"power":3.68,"is_valid":true,"timestamp":1563221602,"counters":[3.690, 3.693, 3.677],"total":11145}]}
2019-07-15 20:13:22.296 [ERROR] [discovery.ShellyDiscoveryParticipant] - Device discovery failed: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1550 path $.relays[0].schedule_rules[0]
2019-07-15 20:13:23.912 [WARN ] [discovery.ShellyDiscoveryParticipant] - Discovered Shelly device doesn't have an IP address: [ServiceInfoImpl@6255384 name: 'shellyplug-s-376E9E._http._tcp.local.' address: '(null):0' status: 'DNS: JmDNS-/192.168.2.80 [/192.168.2.80] state: probing 1 task: null', has NO data
        shellyplug-s-376E9E._http._tcp.local.: ]

Adding the device manually worked.

I have create one switch item for power on and off and another number item to display the current watts.

Switching the plug on and off works. The display of the power does not work (shows only “NaN”). This is the trace output:

Shelly status info : {"wifi_sta":{"connected":true,"ssid":"Ankh-Morpork","ip":"192.168.2.72","rssi":-49},"cloud":{"enabled":true,"connected":true},"mqtt":{"connected":false},"time":"20:03","serial":1627,"has_update":false,"mac":"CC50E3376EAF","relays":[{"ison":true,"has_timer":false,"overpower":false}],"meters":[{"power":5.50,"is_valid":true,"timestamp":1563221014,"counters":[5.384, 6.031, 6.089],"total":8076}],"temperature":31.71,"overtemperature":false,"update":{"status":"idle","has_update":false,"new_version":"20190711-084501/v1.5.0-hotfix4@3b4f7414","old_version":"20190711-084501/v1.5.0-hotfix4@3b4f7414"},"ram_total":50832,"ram_free":37512,"fs_size":233681,"fs_free":176202,"uptime":336312}

Will now install alpha2.