Raspi3 + OH2 + Sonoff + ESP Easy

Hello,

I’m installed ESP Easy to Sonoff switch and try to make simple logic with relay and led. But MQTT not work for me :frowning:

When I pressing F5 at OH2 basicui I get error in OH2 log:

19:50:02.299 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'sonoff'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'sonoff' could not be found in the item registry
        at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:148)[96:org.eclipse.smarthome.core:0.9.0.201612171108]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem(ItemUIRegistryImpl.java:609)[134:org.eclipse.smarthome.ui:0.9.0.201612171108                              ]
        at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget(SwitchRenderer.java:57)[179:org.eclipse.smarthome.ui.basic:0.9.0.201                              612171108]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:166)[179:org.eclipse.smarthome.ui.basic:0.9.0.201612                              171108]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:128)[179:org.eclipse.smarthome.ui.basic:0.9.0.201                              612171108]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:149)[179:org.eclipse.smarthome.ui.basic:0.9.0.201                              612171108]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:92)[179:org.eclipse.smarthome.ui.basic:0.9.0.20161217                              1108]
        at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:150)[179:org.eclipse.smarthome.ui.basic:0.9.0.20161217                              1108]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[79:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[79:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)[170:org.ops4j.pax.web.pax-web-je                              tty:4.2.4]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[77:org.eclipse.jetty.security:9.2.14.v20151106]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:271)[170:org.ops4j.pax.web.pax-web-jetty:4.2.4]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[79:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[170:org.ops4j.pax.web.pax-we                              b-jetty:4.2.4]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.Server.handle(Server.java:499)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[78:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[70:org.eclipse.jetty.io:9.2.14.v20151106]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[81:org.eclipse.jetty.util:9.2.14.v20151106]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[81:org.eclipse.jetty.util:9.2.14.v20151106]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]
19:50:02.306 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff' for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.307 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.311 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.312 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.313 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff' for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.320 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff' for widget org.eclipse.smarthome.model.sitemap.Switch
19:50:02.321 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff' for widget org.eclipse.smarthome.model.sitemap.Switch
String sonoffUptime "sonoffUptime [%s]"{mqtt="<[mosquitto:/sonoff/Uptime:state:default]"}
Swith sonoff "sonoff [%s]" {mqtt=">[mosquitto:/sonoff/gpio/13:command:ON:1],>[mosquitto:/sonoff/gpio/13:command:OFF:0]"}
Frame label="Sonoff MQTT" {
	Switch item=sonoff
	Text item=sonoffUptime
}

all is installed and configured, can’t figure out where is the problem. Can someone help?

should be Switch (typo)

@sihui thanks for your help!

I’m just start with MQTT, and have one more question:

this work:

Switch sonoffF009 "sonoffF009 [%s]" {mqtt=">[mosquitto:/sonoffF009/gpio/12:command:ON:0],>[mosquitto:/sonoffF009/gpio/12:command:OFF:1]"}

and this

String sonoffF009Uptime "sonoffF009Uptime [%s]"{mqtt="<[mosquitto:/sonoffF009/SystemInfo/Uptime:state:default]"}

BUT THIS NOT WORK:

Switch sonoffF009 "sonoffF009 [%s]" {mqtt=">[mosquitto:/sonoffF009/Button/Switch:command:ON:0],>[mosquitto:/sonoffF009/Button/Switch:command:OFF:1]"}

why?

Actually, I’m trying to implement some logic with green led, and then move this logic to relay

Because ESPEasy uses the topic (in your case)
/sonoffF009/gpio/12

and not /sonoffF009/Button/Switch

In ESPEasy go to “Tools” “Advanced” and take a look at “Subscribe Template” and “Publish Template”. At that place you may change the topic (but I would not mess around with it when it’s working like in your case).

Hm… I’ve watched this video


and thought, that I can customise the/topic, and do the next:

String sonoffF009Uptime "Uptime [%s]" {mqtt="<[mosquitto:/sonoffF009/system/uptime:state:default]"}
Switch sonoffF009Led "LED" {mqtt=">[mosquitto:/sonoffF009/led/switch:command:ON:0],>[mosquitto:/sonoffF009/led/switch:command:OFF:1]"}
Switch sonoffF009Relay "Relay" {mqtt=">[mosquitto:/sonoffF009/relay/switch:command:ON:0],>[mosquitto:/sonoffF009/relay/switch:command:OFF:1]"}

here is my ESP Easy devices:

Also wanna mention, that system/uptime work correctly. Maybe you could assume some another problem?

That is a system topic and handled differently as far as I know.

The publish template /%sysname%/%tskname%/%valname%
comes from

  1. %sysname%: Tab “Config”, “Name”
  2. %tskname%: Tab “Devices”, “Name”
  3. %valname%: Tab “Devices”, “Value Name 1”

/%sysname%/%tskname%/%valname% == /sonoffF009/relay/switch
seems, all is correct - but not work :confused:

One more question:

  1. I turn relay ON at iOS app
  2. Then power OFF the relay (remove plug from electricity)
  3. Still see at iOS app that relay is ON

how to solve this issue?

That cannot work at all! openHAB will only be able to see if you turn the relay on and off via the switch. If you remove the power nothing will happen in openHAB …

Check if your broker is working at all. What broker are you using? Most people here are using mosquitto, installed on the same computer (Raspberry Pi?) as openHAB.
If you are using mosquitto and have your MQTT binding installed correctly you should see

2016-12-28 21:07:50.825 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-12-28 21:07:53.792 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

in your openhab.log.

Edit: if you don’t see anything in your log here is a install guide:

2nd Edit: and if you need help on configuring your MQTT binding take a look here:

This is worked for me

Switch sonoffF009Relay "Relay" {mqtt="<[mosquitto:/sonoffF009/relay/switch:state:MAP(toInt.map)],>[mosquitto:/sonoffF009/gpio/12:command:*:MAP(toInt.map)]", autoupdate="false"}

EspEasy rules

on relay#switch do
  if [relay#switch]=1
    gpio,13,0
  else
    gpio,13,1
  endif
endon

on button#switch do
  if [button#switch]=1
    gpio,12,1
  else
    gpio,12,0
  endif
endon

Right now I have almost the same behaviour as default Sonoff firmware.
Button pressed -> led is toggled AND relay is toggled too
And all this good work with OH2! Changes that was made with button sync with OH2 UI

@sihui thank you for your help! :+1:
I think I got a good behaviour!

2 Likes

Thanks for the post. I was able to get my Sonoff running with mqtt and the item and sitemap syntax you provided. One question I have is that I can’t get the button on sonoff to turn on manually. I can see that gpio 0 changes state but it is not tied back to the relay. How did you get it working?

@tdlr hm… I wrote all settings from ESP Easy above. To switch the relay via button I use device “button” + some code in the rules

Thanks for replying. So to confirm, you created a rule where you detect a change in the button state and then publish a message to the relay. I reviewed the settings above but on some previous examples I saw, either a “Push button Active low” or “Push Button Active High.” was selected for the switch input. What were your settings? Finally, the only way I was able to trigger the relay was publishing to /gpio/12. Is this a bug on the ESP Easy side?

Okay, I answered part of my own question. In ESP Easy, there is way to implement rules. However, it is not visible by default. You must go into advanced and check the box for Rules. Once this is submitted, a menu item Rules is visible. This is helpful since it can manually be switched via the button. So it works but sometimes, you need to press the button several times or give it a long press to make it work.

Yes, it’s because of delay - for example, you can’t press button 2 times in 1 second.
You can decrease this delay Tools -> Advanced -> Message Delay (ms): 1000

I just wanted to share that I got better predictable performance using the firmware from https://github.com/arendst/Sonoff-Tasmota. Pressing the button on the SONOFF is much more responsive. Also, Theo Arends has been doing a phenomenal work on software updates.

1 Like