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.
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'}}"
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.
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:
- Paste the code block into the editor window here.
- Highlight that code block.
- Hit the </> -sign on the menu bar above the editor window.
Or take a look here:
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).
- 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 text
nsorsâ][â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âŠ