Sonoff Pow

@keithh666

When a Sonoff Pow threshold like PowerLow has been met a message tele/sonoff/POWER_LOW ON will be sent. When the error is corrected a message tele/sonoff/POWER_LOW OFF will be sent.

While most MQTT commands will result in a message in JSON format the power status feedback will always be returned like stat/sonoff/POWER ON too.

Telemetry data will be sent by prefix tele like tele/sonoff/SENSOR {“Time”:“2017-02-16T10:13:52”, “DS18B20”:{“Temperature”:20.6}}

The reason it’s not working now is it’s nested json…

Notice the {} they indicate it’s nested json {“Time”:“2018-01-25T02:16:38”,“ENERGY”:{“Total”:0.149,“Yesterday”:0.079,“Today”:0.070,“Period”:0,“Power”:22,“Factor”:0.52,“Voltage”:228,“Current”:0.183}}

Nested JSON in a response is supported as well

{
  "sensor": {
    "type": "air",
    "id": "12345"
  },
  "values": {
    "temp": 26.09,
    "hum": 56.73,
  }
}
Just use the “Square bracket notation” to get the value.

'{{ value_json["values"]["temp"] }}'

so you would need -

{{ value_json[“ENERGY”][“Yesterday”] }} for example.

Log:

Failed config
sensor.mqtt:
platform: mqtt
name: Sonoff Pow Yesterday Energy
state_topic: tele/sonoff_pow_1/ENERGY
unit_of_measurement: kWh
value_template: {{ value_json[“ENERGY”][“Yesterday”] }}

2018-01-25 02:13:16 ERROR (Thread-2) [homeassistant.util.yaml] while parsing a block mapping
in “/home/homeassistant/.homeassistant/sensors.yaml”, line 31, column 5
expected , but found ‘’
in “/home/homeassistant/.homeassistant/sensors.yaml”, line 35, column 38
2018-01-25 02:13:16 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
in “/home/homeassistant/.homeassistant/sensors.yaml”, line 31, column 5
expected , but found ‘’
in “/home/homeassistant/.homeassistant/sensors.yaml”, line 35, column 38

Try putting single quotes round it like it shows in the example!

will try to explan

as the MQTT is a Json Message

02:16:38 MQT: tele/sonoff_pow_1/SENSOR = {“Time”:“2018-01-25T02:16:38”,“ENERGY”:{“Total”:0.149,“Yesterday”:0.079,“Today”:0.070,“Period”:0,“Power”:22,“Factor”:0.52,“Voltage”:228,“Current”:0.183}}

think of each { as start of a object and the next { is the child of it

so want to read the
MQTT of the tele/sonoff_pow_1/SENSOR

state_topic: "tele/sonoff_pow_1/SENSOR"

as we want to Read the Yesterday value which is in side the ENERGY { } which is its child

so

value_template: "{{value_json['ENERGY'].Yesterday }}"

so putting it all together

- platform: mqtt
  name: Sonoff Pow Yesterday Energy
  unit_of_measurement: "kWh"
  state_topic: "tele/sonoff_pow_1/SENSOR"
  value_template: "{{value_json['ENERGY'].Yesterday }}"

This is mine

  - platform: mqtt
    name: "Washing Power"
    state_topic: "tele/SONOFF-POW1/SENSOR"
    value_template: "{{value_json['ENERGY'].Power }}"
    qos: 1
    unit_of_measurement : "W"

image

See clear as mud

7 Likes

Thanks @myle i will try later… :slight_smile:

I can confirm the syntax from @keithh666 works too. This is my setup:

sensor:
  - platform: mqtt
    name: "SP1_Yesterday"
    state_topic: "tele/sonoffpow-1/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Yesterday"] }}'
    unit_of_measurement: "kWh" 
1 Like

forgot about the 2rd [ ] you use them if you are going to change the data in side the [] with some code to read the data

hope that cents
see clear as mud

hey guys, i’m new to the sonoff pow and need help with calibrating it.
can someone tell me how to calibrate tasmota so it measures the correct values?

1 Like

@myle You are the man…WORKS!!! THANKS!!!

See https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-Pow#calibration

Wire it up to a ,60 w light and see what what u get

You need an incandescent bulb (traditional or halogen) to avoid influences from the power factor.

Any idea on how to get Power Factor to show up in Hassio, This doesn’t seem to work

  • platform: mqtt
    name: “Power Factor”
    state_topic: “stat/pow1/STATUS8”
    value_template: “{{ value_json[‘StatusPWR’].Factor }}”

This is my configuration:

- platform: mqtt
    name: "Sonoff_PowerFactor"
    state_topic: "tele/sonoffpow/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Factor"] }}'
1 Like

Thanks! That did the trick!

For those who wanted the mqtt sensor attribute to display correctly. You can use this.

Basically, it read the SENSOR ENERGY and republish as SENSOR_DATA so the mqtt sensor can reach from SENSOR_DATA with all the attribute.

sensor:
  - platform: mqtt
    name: "SonOffPow1"
    state_topic: "tele/sonoffpow1/SENSOR_DATA"
    value_template: '{{ value_json.Power }}'
    unit_of_measurement: "Watts" 
    json_attributes:
      - Current
      - Today
      - Yesterday
      - Voltage
      - Total

Automation:
    - alias: 'AutoSonoffPowAtribute'
      initial_state: true
      #hide_entity: True
      trigger:
        - platform: mqtt
          topic: 'tele/sonoffpow1/SENSOR'
      action:
        - service: mqtt.publish
          data_template:
            topic: 'tele/sonoffpow1/SENSOR_DATA'
            payload: '{{ trigger.payload_json.ENERGY | tojson }}'
2 Likes

YES here is mine

  • platform: mqtt
    name: “POW Current”
    state_topic: “tele/sonoff_pool_pump/SENSOR”
    value_template: “{{ value_json[‘ENERGY’].Current }}”
    unit_of_measurement: ‘amps’
  • platform: mqtt
    name: “POW Power”
    state_topic: “tele/sonoff_pool_pump/SENSOR”
    value_template: “{{ value_json[‘ENERGY’].Power }}”
    unit_of_measurement: ‘watts’
  • platform: mqtt
    name: “POW Voltage”
    state_topic: “tele/sonoff_pool_pump/SENSOR”
    value_template: “{{ value_json[‘ENERGY’].Voltage }}”
    unit_of_measurement: ‘volts’

Hay bro Can you format it its easyer to read