POW R2 sonoff

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…

You are missing the closing ) in

value_template: "{{ state_attr('switch.sonoff_1001489baa', 'current') }}"

Same for the other templates.

Ondras, you are right, these were not in the script…thank you so much it works now!!! thank you all for your help!
i understand now, same as mathematic formula if you start with ( you need a ) at the end …:slight_smile:

Yup, Sorry, happened in the haste. It’s also pointed out in the error message.

Now, this should go:

# 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"

no problem Tamsy :slight_smile: you helped me a lot and you probably get confused with all my stupid questions :slight_smile: again it works now…:slight_smile: now I need to find a way to refresh these datas because it is static since 30 minutes…and get it integrated in energy board

Capture d’écran 2022-03-24 à 13.25.56