POW R2 sonoff

Hello guys, after 2 days of configuration, I was able to integrate my Sonoff, TV, Air Quality Analyzer and my Sonos, thanks to different posts and information i found on both this site and the FR site
thank you!
About my Sonoff, I have POWR2 switches which are well recognized but I cannot find a way to retrieve the Voltage, Current and Amp information which is however well listed in development tools/entities (see photo).
Did any of you manage to integrate this info?
Can we add them in Energy?
My POW switch are not flashed
Thank you and have a nice sunday

No because they are not energy attributes. The energy dashboard only accepts energy sensors, not power, not voltage, not current sensors.

You can create a template sensor to break out the power attribute to its own sensor, then use the Riemann Sum integration to integrate your new power sensor with respect to time to produce an energy sensor you could use with the energy dashboard.

Search the forum. This has been covered many, many times.

Ok thank you, I,will try to understand what is a template first, I’m a little bit lost. :slight_smile:

Hi Tom,
I try this (line26)

and get this message

i tied also this

switch:

  • platform: template
    switches:
    sonoff_1001489baa_current:
    friendly_name: “courant pump”
    unit_of_measurement: “A”
    value_template: “{{ state_attr(‘switch.sonoff_1001489baa’, ‘current’) }}”

but same kind of error


As the message is telling it: Your indentation is wrong.

Yours (wrong indentation):

  - platform: template
   sensors:
     sonoff_1001489baa_current:
       friendly_name: "courant pump"
       unit_of_measurement: "A"
       value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"

Correct indentation:

  - platform: template
    sensors:
      sonoff_1001489baa_current:
        friendly_name: "courant pump"
        unit_of_measurement: "A"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
1 Like

In addition to the indentation issues described above:
You need to put your template sensor under sensor:, not sonoff:.
I don’t see a reason for using the legacy format of template sensor, but it should work. (Edit: but it won’t let you set the state_class that you’ll need for your energy sensor.)
I also don’t think http should be indented in your config. As it is right now, it is under sonoff instead of being a top-level key.

Because you haven’t posted your config in plain text (see point 11), I will only write the parts that need to change.

sonoff:
  username: sth
  # ...

http:
  ssl_certificate: sth
  # ...

sensor:
  - platform: template
    sensors:
      # ...

Tip: take a look at Storing secrets - Home Assistant for a better way to store the username and password.

Ok guys, thank you so much for your messages.
Here is what i done:

sensor:

  • platform: template
    sensors:
    sonoff_1001489baa_current:
    friendly_name: “courant pump”
    value_template: " {{ state_attr(â€č switch.sonoff_1001489baa â€ș, â€č current â€ș) }} "
    unit_of_measurement: " A "

Then it works so i continue with voltage and power

    friendly_name: "power pump"
    value_template: " {{ state_attr(â€č switch.sonoff_1001489baa â€ș, â€č power â€ș) }} "
    unit_of_measurement: " W "


    friendly_name: "voltage pump"
    value_template: " {{ state_attr(â€č switch.sonoff_1001489baa â€ș, â€č voltage â€ș) }} "
    unit_of_measurement: " V "

Then i get this in my board

Seems to work (even if numbers seems to not be updated)

But the thing is that i got a error message and cannot re start HA
at the bottom of the screen copy

And here is the message under file editor

Ondras, i will check again my config and update as you told me

Thank you guys !

Wondering about the less-than (<) and greater-than (>) signs in your yaml.

It might be helpful to take a look at the YAML Style Guide.

In fact when i paste into the forum it create <> vs « « or ‘ ‘ 
here is what i have

Please dont post pictures of text. Paste it and format it properly.

Look at your first sensor. Then look at the other two. They are missing the sensor map:

Makes it hard for the community to go through your coding to narrow down possible errors.

To paste and format your (yaml) code to the forum is actually quite easy:

  1. Paste the code block into the editor window here.
  2. Highlight that code block.
  3. Hit the </> -sign on the menu bar above the editor window.

Or take a look here:

1 Like

ok thank you for telling me, here is a copy of my last update.

sensor:  
  - platform: template
    sensors:
      sonoff_1001489baa_current:
        friendly_name: "courant pump"
        value_template: " {{ state_attr('switch.sonoff_1001489baa' , 'power') }} "
        unit_of_measurement: " A "
        
        
    sensors:    
        friendly_name: "power pump"
        value_template: " {{ state_attr('switch.sonoff_1001489baa' , 'power') }} "
        unit_of_measurement: " W "


    sensors:
        friendly_name: "voltage pump"
        value_template: " {{ state_attr('switch.sonoff_1001489baa' , 'voltage') }} "
        unit_of_measurement: " V "

and error I still get in editor

duplicated mapping key at line 35, column -168:
sensors:
^

and after testing config

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘friendly_name’]. Got ‘voltage pump’ expected dictionary for dictionary value @ data[‘sensors’][‘unit_of_measurement’]. Got ’ V ’ expected dictionary for dictionary value @ data[‘sensors’][‘value_template’]. Got " {{ state_attr(‘switch.sonoff_1001489baa’ , ‘voltage’) }} ". (See ?, line ?).

PS: LINE 35 is the line that starts with the second command ‘sensor’ as per bellow

Try this:

  - platform: template
    sensors:
      sonoff_1001489baa_current:
        friendly_name: "courant pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
        unit_of_measurement: "A"

      sonoff_1001489baa_power:
        friendly_name: "power pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
        unit_of_measurement: "W"

      sonoff_1001489baa_voltage:
        friendly_name: "voltage pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
        unit_of_measurement: "V"
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sonoff:
  username: xxxxx
  password: xxxx
  sensors: power, current, voltage, temperature, humidity, current
  mode: local
  reload: always 
  
  
http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
 
 

sensor:
platform: template
sensors:
  sonoff_1001489baa_current:
        friendly_name: "courant pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
        unit_of_measurement: "A"
        
        
  sonoff_1001489baa_power:    
        friendly_name: "power pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
        unit_of_measurement: "W"

  sonoff_1001489baa_voltage:
        friendly_name: "voltage pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
        unit_of_measurement: "V"

so I retype manually everything to understand the changes.
no error in the file editor, yes !!!
ut stil have error if I test the config before I want to start:

Integration error: platform - Integration ‘platform’ not found. Integration error: sensors - Integration ‘sensors’ not found.

  sensor:
    - platform: template
      sensors:
        sonoff_1001489baa_current:
          friendly_name: "courant pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
          unit_of_measurement: "A"

        sonoff_1001489baa_power:
          friendly_name: "power pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
          unit_of_measurement: "W"

        sonoff_1001489baa_voltage:
          friendly_name: "voltage pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
          unit_of_measurement: "V"
ok i change:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sonoff:
  username: xxxxx
  password: xxxxx
  sensors: power, current, voltage, temperature, humidity, current
  mode: local
  reload: always 
  
  
http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
 
 

  sensor:
    - platform: template
      sensors:
        sonoff_1001489baa_current:
          friendly_name: "courant pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
          unit_of_measurement: "A"

        sonoff_1001489baa_power:
          friendly_name: "power pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
          unit_of_measurement: "W"

        sonoff_1001489baa_voltage:
          friendly_name: "voltage pump"
          value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
          unit_of_measurement: "V"

But now error at line 20 :invalid config for [http]: [sensor] is an invalid option for [http]. Check: http->http->sensor. (See /config/configuration.yaml, line 20).

  1. http:
    21 ssl_certificate: /ssl/fullchain.pem
    22 ssl_key: /ssl/privkey.pem

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘sensors’][‘sonoff_1001489baa_current’][‘value_template’]. Got “{{ state_attr(‘switch.sonoff_1001489baa’, ‘current’}}” invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘sePreformatted textnsors’][‘sonoff_1001489baa_power’][‘value_template’]. Got “{{ state_attr(‘switch.sonoff_1001489baa’, ‘power’}}” invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘sensors’][‘sonoff_1001489baa_voltage’][‘value_template’]. Got “{{ state_attr(‘switch.sonoff_1001489baa’, ‘voltage’}}”. (See ?, line ?).

The issue is caused by wrong indentation (again).

Please compare the below with your version:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sonoff:
  username: xxxxx
  password: xxxxx
  sensors: power, current, voltage, temperature, humidity, current
  mode: local
  reload: always 

http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

sensor:
  - platform: template
    sensors:
      sonoff_1001489baa_current:
        friendly_name: "courant pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
        unit_of_measurement: "A"

      sonoff_1001489baa_power:
        friendly_name: "power pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
        unit_of_measurement: "W"

      sonoff_1001489baa_voltage:
        friendly_name: "voltage pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
        unit_of_measurement: "V"
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sonoff:
  username: +66xxxx
  password: xxxxx
  sensors: power, current, voltage, temperature, humidity, current
  mode: local
  reload: always 
  
  
http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
 

sensor:
  - platform: template
    sensors:
      sonoff_1001489baa_current:
        friendly_name: "courant pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current'}}"
        unit_of_measurement: "A"

      sonoff_1001489baa_power:
        friendly_name: "power pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'power'}}"
        unit_of_measurement: "W"

      sonoff_1001489baa_voltage:
        friendly_name: "voltage pump"
        value_template: "{{ state_attr('switch.sonoff_1001489baa', 'voltage'}}"
        unit_of_measurement: "V"

i retype manually everything, I’m really lost here, because it is exactly the same
then I tried also just to copy / paste your last script, but still get same message