Sonoff POW - How to read Voltage, Current, Power,

There are several things to check (to make sure everything matches):

  1. Check with a MQTT client (I use " MQTT.fx" on an iMac) that you can connect to your broker and are able to subscribe to your topic to see that the data is being published by the sonoff device.
    In my setup the broker name is openhab2 and the topic I subscribed to is sonoff_1/# (the /# allows me to see all the topics for this device).
    In my setup I see the following:

If this does not work, there are two things that might be wrong:
a.) You don’t have the right information for your broker setup (name, user, password,…) or your broker is not running/installed, so check your broker setup (see MQTT Binding (v1.11) Getting Started 101)
b.) Your sonoff MQTT configuration is wrong/missing. Check that by using a browser and log into you sonoff device. Mine is setup like this:

Note, that your “User” and “Password” entry need to match your definition of the broker (see a.) above)
Also write down the “Topic” and the “Full Topic” you entered in this setup, you’ll need that later for your Openhab mqtt.cfg file.

  1. You need to solve 1. above, otherwise do NOT proceed.
  2. Configure your mqtt.cfg file. Mine looks like this:
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
#broker.url=tcp://192.168.1.10:1883
broker.url=tcp://openhabianpi.local:1883
# broker.url=ssl://192.168.1.10:8883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>
broker.clientId=openhab

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
broker.user=openhabian

# Optional. Password to authenticate with the broker.
broker.pwd=*******

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
broker.qos=0

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
broker.retain=false

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
broker.async=true

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

Please note, that I blanked out my password (broker.pwd=*******), you’ll have to enter your real password instead of the *******
4. As you can see in the first screen shot, the sonoff publishes the voltage information to a topic named: “sonoff_1/tele/sonoff/SENSOR” and the topic actually looks like this:

{"Time":"2018-10-13T10:05:55","ENERGY":{"Total":38.104,"Yesterday":3.220,"Today":0.707,"Period":0,"Power":169,"Factor":1.00,"Voltage":118,"Current":1.431}}

To get the voltage out of this topic I have defined my item as follows:

Number Sonoff_1_V	"S1_V [%.0f V]"
	{ mqtt="	<[broker:sonoff_1/tele/sonoff/SENSOR:state:JSONPATH($.ENERGY.Voltage)],
				<[broker:sonoff_1/stat/sonoff/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage)]" }

You will see several things here:

  • ignore the second line that contains “Status8”, I use another method in addition to tele to get data from the sonoff device.
  • “broker” matches the name I defined in the mqtt.cfg file
  • “sonoff_1” matches the first item in the “Full Topic” definition that I entered in the Sonoff setup (accessed through login into the sonoff device as admin, and of course saving it).
  • “tele” matches what the sonoff devices uses to publish its data (assuming you have “logging” in the sonoff device active with a reasonable " Telemetry period")
  • “sonoff” matches “Topic” entry in the sonoff device setup
  • “Sensor” matches what the sonoff device transmits
  • “$.ENERGY.VOLTAGE” matches what the sonoff device transmits.

Hope that helps…

1 Like