Integrating a Tasmotized Sonoff pow r2 in Home Assistant

Originally published on 12/11/2021
HA configuration.yaml on a command line interface (nano)

Last week I've been tinkering with Home Assistant and found out that it is a pretty handy piece of software after a few one click integration with my existing smart home devices i stumpled uppon a problem my Sonoff por R2 that was using mqtt to monitor my solar panel power not showing up, even with auto discovery on. So i created a custom config in the

configuration.yaml
and everything went smooth.

Finding the configuration file

First thing first. Find the configuration.yaml of your Home Assistant instalation. The location will differ depending on how you installed Home Assistant if you have the Core it will be on default is ~/.homeassistant. For my case, since i am running a supervised instalation on ubuntu the file resides in

/usr/share/hassio/homeassistant/configuration.yaml
. But the easiest way is to install the file editor addon and it will be open in the right folder so you only have to select the file you want. You can always refer to the Home Assistant documentation to get help.

The yaml for Sonoff pow r2 tasmota mqtt integration

With the file oppened i just inserted the following code. Having especial attention to the indentation. Yaml is very strict about the indentation, the indentation from start to finish has to be consistent, that is if you start with a TAB just stick with it or you will be getting errors, in my case my file has indentation of 2 spaces so i'm good here. FYI The word sensor dont have any indentation at all (root level).

sensor:
#pow_casa
- platform: mqtt
name: "PowCasa Power"
state_topic: "pow_casa/tele/SENSOR"
value_template: '{{ value_json.ENERGY.Power }}'
device_class: "power"
unit_of_measurement: "W"
- platform: mqtt
name: "PowCasa Energy Today"
state_topic: "pow_casa/tele/SENSOR"
value_template: '{{ value_json.ENERGY.Today }}'
device_class: "energy"
unit_of_measurement: "kWh"
- platform: mqtt
name: "PowCasa Voltage"
state_topic: "pow_casa/tele/SENSOR"
value_template: '{{ value_json.ENERGY.Voltage }}'
device_class: "voltage"</code></pre>

Like you see above I am capturing only the following fields from the json:

  • power: in Watts for showing in a gauge, its the current wattage;
  • Energy today that is useful to know how much energy passed in the sensor, that means for me the energy produced by my single solar panel, it will come very handy to integrate with the energy dashboard provided by Home Assistant, i will be doing a post on that, stay tunned;
  • And the Voltage measured by the sensor just to know that everything is within parameters;

That's all i need if you need more values just duplicate and adjust for what you need. If you want to inspect the JSON published by the sonoff there it is:

{
"Time": "2021-12-11T15:16:50",
"ENERGY": {
"TotalStartTime": "2020-02-12T17:27:38",
"Total": 1292.35181,
"Yesterday": 0.30205,
"Today": 0.87179,
"Period": 24,
"Power": 138,
"ApparentPower": 158,
"ReactivePower": 76,
"Factor": 0.88,
"Voltage": 235,
"Current": 0.672
}
}

Just like i did to get the JSON, i recommend MQTT Explorer app, very nice to debug MQTT problems you can see if the Sonoff is publishing his status and what is happening in your MQTT server. To see more about the sonoff tasmotized go to the tasmota documentation page.

My mqtt configuration in the tasmota admin page

My Pow R2 tasmota mqtt configuration

My sensor is publishing the updates on

pow_casa/tele
topic adjust yours according, in the Home Assistant configuration it has to match.

Conclusion

That is what is needed to get your Sonoff Pow R2 running Tasmota integrate it will be available in your Hass lovelace dashboard and ready to jump into your customized dashboards. Next i will be showing how to integrate this sensor with the energy dashboard to track my home energy consumption / generation, it will be up soon. Just be aware that you have other options too with this device, you are not limited to MQTT you can integrate with the Json Api. And if your Sonoff pow r2 is not flashed with Tasmota eWelink has an AddOn to Home Assistant i'm not sure but i think that it will support pow r2 too. If you have any doubt please post it in the comment section, i will be glad to help.

HomePrivacy policy