Sonoff Pow

my sensors.yaml have this code

  • platform: mqtt
    name: Sonoff Pow Today Energy
    unit_of_measurement: “kWh”
    state_topic: “tele/sonoff_pow_1/ENERGY”
    value_template: “{{ value_json.Today }}”

    • platform: mqtt
      name: Sonoff Pow Current
      unit_of_measurement: “Amps”
      state_topic: “tele/sonoff_pow_1/ENERGY”
      value_template: “{{ value_json.Current }}”

    • platform: mqtt
      name: Sonoff Pow Power
      unit_of_measurement: “Watts”
      state_topic: “tele/sonoff_pow_1/ENERGY”
      value_template: “{{ value_json.Power }}”

but i dont get any values …what i doing wrong???

Thanks

To get the code formatted correctly for the forum paste the code in
the edit box, leaving a blank line at the start and end, then select
the code and click the </> button in the small menu bar at the top of
the edit box.

I try this and nothing…i have last tasmota firmare ( Sonoff-Tasmota 5.11.1e by Theo Arends)

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

- platform: mqtt
  name: Sonoff Pow Today Energy
  unit_of_measurement: "kWh"
  state_topic: "tele/sonoff_pow_1/Today"
  value_template: "{{ value_json.Today }}"
1 Like

The usual reason you have nothing is that either there is no broker running, the password/username is wrong, the client id is the same as another client or the topic is wrong. Mostly it’s the topic.

0:00:06 MQT: Attempting connection…
00:00:06 MQT: Connected
00:00:06 MQT: tele/sonoff_pow_1/LWT = Online (retained)
00:00:06 MQT: cmnd/sonoff_pow_1/POWER =
00:00:06 MQT: tele/sonoff_pow_1/INFO1 = {“Module”:“Sonoff Pow”,“Version”:“5.11.1e”,“FallbackTopic”:“sonoff_pow_1”,“GroupTopic”:“sonoffs”}
00:00:06 MQT: tele/sonoff_pow_1/INFO2 = {“WebServerMode”:“Admin”,“Hostname”:“sonoff_pow_1-3818”,“IPAddress”:“192.168.1.115”}
00:00:06 MQT: tele/sonoff_pow_1/INFO3 = {“RestartReason”:“Software/System restart”}
00:00:06 MQT: homeassistant/switch/sonoff_pow_1/config = (retained)
00:00:07 MQT: stat/sonoff_pow_1/RESULT = {“POWER”:“ON”}
00:00:07 MQT: stat/sonoff_pow_1/POWER = ON
02:16:38 MQT: tele/sonoff_pow_1/STATE = {“Time”:“2018-01-25T02:16:38”,“Uptime”:0,“Vcc”:3.476,“POWER”:“ON”,“Wifi”:{“AP”:1,“SSId”:“IcemanHouse2”,“RSSI”:90,“APMac”:“26:A4:3C:4D:C9:00”}}
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}}

Sonoff pow this connect to MQTT server

topic???

tele/sonoff_pow_1/SENSOR

you have

tele/sonoff_pow_1/Yesterday

and

tele/sonoff_pow_1/Today

and presumably Current

yes…this is last tasmota firmware

5.11.1e

  • Replaced command Ina219Mode with command Sensor13
  • Add chunked webserver pages for large pages saving memory
  • Fix Non-English JSON temperature unit attachement
  • Add command Sensor15 2 to start MHZ19(B) Zero Point Calibration (#1643)
  • Fix Sonoff Pow Energy Today and Energy Total reading after restart (#1648)
  • Rewrite function pointers to save code space and memory (#1683)
  • Add option define HOME_ASSISTANT_DISCOVERY_ENABLE in user_config.h (#1685)
  • Fix SOnoff Pow Energy Period roll-over (#1688)

The HA side is wrong - see above

Wrong??? sorry?? i dont understand

i try this now and anything

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

- platform: mqtt
  name: Sonoff Pow Today Energy
  unit_of_measurement: "kWh"
  state_topic: "tele/sonoff_pow_1/SENSOR"
 value_template: "{{ value_json.Today }}"

- platform: mqtt
  name: Sonoff Pow Current
  unit_of_measurement: "Amps"
  state_topic: "tele/sonoff_pow_1/SENSOR"
  value_template: "{{ value_json.Current }}"

- platform: mqtt
  name: Sonoff Pow Power
  unit_of_measurement: "Watts"
  state_topic: "tele/sonoff_pow_1/SENSOR"
  value_template: "{{ value_json.Power }}"

39
this is the problem

@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