[SOLVED] Sonoff POW openhab2 integration

Hello there,
I bought a sonoff POW R2 with Tasmota Flashed from ebay and try to integrate it into my openhab2 running on my Raspi to monitore the power production of my Solar Panels.
Sonoff is running and available in my network.
The configuration looks like this:


I intalled the MQTT Binding 2.4 in paper UI of openhab.
I made a bridge like this in the things:

Bridge mqtt:broker:MqttBroker "MqttBroker" [ host="localhost", port=1883, secure=false /* username="", password="", clientID="openHAB2"/*/ ]
{  
    Thing topic sonoffpow "Sonoff POW" @ "Photovoltaik" {
    Channels:
        Type string : reachable "Reachable"              [ stateTopic="tele/sonoff-pow/LWT" ]
        Type switch : power     "Power"                  [ stateTopic="stat/sonoff-pow/POWER", commandTopic="cmnd/sonoff-pow/POWER" ]
        Type number : powerload "Power load"             [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
        Type number : voltage   "Line voltage"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
        Type number : current   "Line current"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]
        Type number : total     "Total energy today"     [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
        Type number : totalyest "Total energy yesterday" [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Yesterday"]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/sonoff-pow/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
}

The following items are defined:

//-> Sonoff
Group  FF_Sonoff_POW           "Sonoff POW"                        <sonoff_pow>    (Sonoff_POW)
String FF_Sonoff_POW_Reachable "Reachable: [%s]"                   <contactable>   (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:reachable" }
Switch FF_Sonoff_POW_Power     "Power []"                          <sonoff_pow>    (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:power" }
Number FF_Sonoff_POW_Load      "Power load [%.1f W]"               <voltage>       (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:powerload" }
Number FF_Sonoff_POW_Voltage   "Line voltage [%.1f V]"             <voltage>       (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:voltage" }
Number FF_Sonoff_POW_Current   "Line current [%.3f A]"             <current>       (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:current" }
Number FF_Sonoff_POW_Today     "Total energy today [%.3f kWh]"     <total_energy>  (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:total" }
Number FF_Sonoff_POW_Yesterday "Total energy yesterday [%.3f kWh]" <total_energy>  (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:totalyest" }
Number FF_Sonoff_POW_RSSI      "WiFi Signal Strength [%d %%]"      <wifi>          (FF_Sonoff_POW) { channel="mqtt:topic:MqttBroker:sonoffpow:rssi" }

But I can not get any value in the paper UI or switch it on or off

Can someone please help me to understand?
NOOB Learning :sweat_smile:

Another NOOB here.
And the logs told you what?

2019-06-28 00:50:41.529 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid paho91504783931 and file store '/var/lib/openhab2/mqtt/localhost'
2019-06-28 00:50:41.596 [WARN ] [ternal.TopicSubscribeMultiConnection] - Failed to MQTT subscribe for mqtt:broker:MqttBroker on topic homeassistant/#
2019-06-28 00:50:41.609 [INFO ] [ansport.mqtt.internal.ClientCallback] - MQTT connection to 'localhost' was lost
org.eclipse.paho.client.mqttv3.MqttException: MqttException
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:220) [227:org.eclipse.paho.client.mqttv3:1.2.0]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.util.ConcurrentModificationException
	at java.util.HashMap.forEach(HashMap.java:1292) ~[?:?]
	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection$ConnectionCallback.onSuccess(MqttBrokerConnection.java:134) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.ConnectActionListener.onSuccess(ConnectActionListener.java:99) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.fireActionEvent(CommsCallback.java:321) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleActionComplete(CommsCallback.java:260) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:190) ~[?:?]
	... 7 more

Why is this client ID? I have not set it?

I have not used mqtt but I am sure the logs can help others direct you.

OK, is there an other solution to get this running?
Sonoff is running as it looks like…

I changed the client ID like this:


Bridge mqtt:broker:MqttBroker "MqttBroker" [ host="localhost", port=1883, secure=false /* username="", password=""/*/, clientID="openhab2" ]
{
   
    Thing topic sonoffpow "Sonoff POW" @ "Photovoltaik" {
    Channels:
        Type string : reachable "Reachable"              [ stateTopic="tele/sonoff-pow/LWT" ]
        Type switch : power     "Power"                  [ stateTopic="stat/sonoff-pow/POWER", commandTopic="cmnd/sonoff-pow/POWER" ]
        Type number : powerload "Power load"             [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
        Type number : voltage   "Line voltage"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
        Type number : current   "Line current"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]
        Type number : total     "Total energy today"     [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
        Type number : totalyest "Total energy yesterday" [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Yesterday"]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/sonoff-pow/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

  
}

But still the error in the log:

2019-06-28 01:05:06.012 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'localhost'. Next attempt in 10000ms
2019-06-28 01:05:06.023 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid openhab2 and file store '/var/lib/openhab2/mqtt/localhost'
2019-06-28 01:05:07.008 [INFO ] [ansport.mqtt.internal.ClientCallback] - MQTT connection to 'localhost' was lost
org.eclipse.paho.client.mqttv3.MqttException: Verbindung wurde getrennt
	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:181) [227:org.eclipse.paho.client.mqttv3:1.2.0]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.EOFException
	at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:133) ~[?:?]
	... 7 more

As the clientID is mandatory and must be unique (at this broker), openHAB will create a random ClientID (paho is the library used to connect to mqtt)

Please try to use the real ip of your mqtt broker.

Err… just to be sure… You did install a mqtt broker? (e.g. mosquitto, moquette, the embedded broker builtin in openHAB2 since v2.4)

1 Like

Hello,
I installed Mosquitto Mttq Broker in the openhab config optional components. I did not set a password there but it sais, the username is “openhabian”.
So I used the username openhabian in the *.things file of the bridge.
It loooks like this now:

Bridge mqtt:broker:mosquitto "Mosquitto" [ host="192.168.178.42", port=1883, secure=false, username="openhabian", password="", clientID="openhab2" ]
{   
    Thing topic sonoffpow "Sonoff POW" @ "Photovoltaik" {
    Channels:
        Type string : reachable "Reachable"              [ stateTopic="tele/sonoff-pow/LWT" ]
        Type switch : power     "Power"                  [ stateTopic="stat/sonoff-pow/POWER", commandTopic="cmnd/sonoff-pow/POWER" ]
        Type number : powerload "Power load"             [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
        Type number : voltage   "Line voltage"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
        Type number : current   "Line current"           [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]
        Type number : total     "Total energy today"     [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
        Type number : totalyest "Total energy yesterday" [ stateTopic="tele/sonoff-pow/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Yesterday"]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/sonoff-pow/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    } 
}

The Items are as follows:

//-> Sonoff
Group  FF_Sonoff_POW           "Sonoff POW"                        <sonoff_pow>    (Sonoff_POW)
String FF_Sonoff_POW_Reachable "Reachable: [%s]"                   <contactable>   (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:reachable" }
Switch FF_Sonoff_POW_Power     "Power []"                          <sonoff_pow>    (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:power" }
Number FF_Sonoff_POW_Load      "Power load [%.1f W]"               <voltage>       (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:powerload" }
Number FF_Sonoff_POW_Voltage   "Line voltage [%.1f V]"             <voltage>       (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:voltage" }
Number FF_Sonoff_POW_Current   "Line current [%.3f A]"             <current>       (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:current" }
Number FF_Sonoff_POW_Today     "Total energy today [%.3f kWh]"     <total_energy>  (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:total" }
Number FF_Sonoff_POW_Yesterday "Total energy yesterday [%.3f kWh]" <total_energy>  (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:totalyest" }
Number FF_Sonoff_POW_RSSI      "WiFi Signal Strength [%d %%]"      <wifi>          (FF_Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow:rssi" }

In Paper UI it shows the things online:
Sonoff%20POW%202
But still no values available:

The log gives no errors any more:

2019-06-28 07:49:36.455 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'meine.things'
2019-06-28 07:49:36.927 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '192.168.178.42' with clientid openhab2 and file store '/var/lib/openhab2/mqtt/192.168.178.42'

Sonoff configuration is like this:

What is wrong? Please help

Did you install the JSONPath Transformation?

yes, it is installed
Sonoff%20POW%205

Don’t you get any log-entries when switching the sonoff directly on the device?
Additionally, what does the console of the sonoff Show when trying to switch from openHAB?

The sonoff conssole looks like this after swiching sonoff on:

But openhab log does not show anything:

2019-06-28 08:08:53.283 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to '192.168.178.42'. Next attempt in 10000ms
2019-06-28 08:08:53.297 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '192.168.178.42' with clientid openhab2 and file store '/var/lib/openhab2/mqtt/192.168.178.42'
2019-06-28 08:08:58.477 [INFO ] [.eclipse.smarthome.model.script.Test] - Running Window openNEW Rule: EG_Vi_hkpump == OFF
2019-06-28 08:08:59.172 [INFO ] [.eclipse.smarthome.model.script.Test] - Running Window openNEW Rule: EG_Vi_hkpump == OFF
2019-06-28 08:10:32.115 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 4 Min.
2019-06-28 08:15:32.133 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 4 Min.
2019-06-28 08:20:32.121 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 14 Min.
2019-06-28 08:25:32.111 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 19 Min.

According the last two lines on the console your sonoff got switched to POWER ON via MQTT, iow by openHAB. Doesn’t the openHAB power switch reflect this power state of the device?
The log lines from openHAB are from a timeframe 08:08 ff, on the sonoff console they are from an hour earlier???

I swiched to “on” directly in sonoff using “toggle” button.

Swiching in openhab paper ui has no effect - and no error log:
Events log:

2019-06-28 08:36:15.827 [ome.event.ItemCommandEvent] - Item 'FF_Sonoff_POW_Power' received command ON
2019-06-28 08:36:15.837 [nt.ItemStatePredictedEvent] - FF_Sonoff_POW_Power predicted to become ON
2019-06-28 08:36:15.843 [vent.ItemStateChangedEvent] - FF_Sonoff_POW_Power changed from OFF to ON

openhab log:

2019-06-28 08:30:32.069 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 19 Min.
2019-06-28 08:35:32.073 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 29 Min.
2019-06-28 08:38:20.312 [INFO ] [.eclipse.smarthome.model.script.Test] - Running Window openNEW Rule: EG_Vi_hkpump == OFF

No effect in POW

No effect in paper UI

Since yesterday the time is wrong in POW…need to find out where to adjust it…

That sounds as if you have no connection to the mqtt broker.

Where does it say the username is….?

During the installation of mosquitto using “sudo openhabian-config”


Mosquitto2

Does this help somehow?

OK. That sounds correct (I didn’t install Mosquitto that way).
Do you have an external MQTT Viewer like MQTTfx in order to check if messages are are running at all?

No, I don’t have it yet. I will install it as soon as I am back at home.
What is strange for me - in Sonoff overview it sais “MQTT Client DEV_15C2BB”.
The Client ID in *.Things is “openhab2”.
But when I change it to “openhab2” in Sonoff, the binding goes offline.

Each device has to have its own ClientID! One for the sonoff and another one for openHAB. So this behaviour is correct.

I think Ihave spotted the real problem: You did setup the mqtt topic as “sonoff” or “sonoffpow” on the sonoff device. The topics you subscribed in openHAB for are using “sonoff-pow”!

1 Like