Unable to get power consumption Entity
Hi Alexx,
First of all thanks for your excellent work. I am a beginner so if my question is simple I am sorry. I've tried my best to read all forums to find the answer. I have managed to connect my Sonoff Pow R2 without Flashing. After adding these lines in my cnfigurations.yaml, I am getting the power consumption values in Developer Tools => States
force_update: [temperature, power] scan_interval: '00:05:00' # (optional) default 5 minutes sensors: [temperature, humidity, power, current, voltage]
Developer Tools => States
manufacturer: Sonoff model: Pow_R2 sw_version: PSC-B67-GL v3.5.0 local: online cloud: online rssi: -49 power: 0 current: 0 voltage: 233.7 consumption: 3.17, 4.08, 9.41, 6.8, 6.13, 3.57, 4.31, 6.12, 2.41, 6.38, 4.64, 7.48, 6.01, 6.96, 5.18, 2.54, 10.29, 6.08, 4.97, 5.13, 6.11, 3.21, 4.03, 8.77, 8.3, 5.65, 8.85, 4.38, 4.67, 8.71, 6.58, 4.17, 7.53, 4.24, 8.15, 5.36, 4.42, 8.72, 5.77, 4.77, 9.01, 4.99, 4.23, 2.4, 4.31, 3.08, 5.84, 6.63, 2.45, 5.87, 5.05, 6.87, 4.91, 4.74, 3.68, 3.35, 5.12, 4.71, 4.68, 6.11, 4.14, 4.27, 4.57, 5.05, 3.78, 7.78, 4.18, 5.01, 4.98, 8.46, 0, 0, 7.75, 10.39, 4.87, 7.68, 3.73, 8.96, 3.55, 8.2, 7.34, 5.85, 1.73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 friendly_name: Ballon icon: mdi:water-boiler supported_features: 0
Now I am trying to create a card on my lovelace interface to show my current consumption. Unfortunately , I don't have any entity to show power consumption. I can only switch it On and Off. Can you please tell me How can I add the consumption values to my Dashboard ?
Thanks and Regards,
Hi,
This is my example of my configuration.yaml
sonoff:
username: !secret sonoff_user
password: !secret sonoff_pass
reload: always
force_update: [temperature, humidity, power, current, voltage, rssi]
scan_interval: '00:01:00'
sensors: [temperature, humidity, power, current, voltage, rssi]
devices:
switch.sonoff_xxxxxxxxxxx:
name: Pump
force_update: True
switch.sonoff_yyyyyyyyy:
name: Microvave
force_update: True
After adding that, you have to restart your the server (Configuration --> Server Controls --> Restart') After that go to lovelace interface and look for the entity that use voltage, current and power.
Hope it helps.
@devilization your devices section is wrong and shouldn't work.
@riyas1980 why you don't read my docs https://github.com/AlexxIT/SonoffLAN#sonoff-pow-power-consumption
@devilization Thanks for your help. By combining your method and AlexxIT's logs, I've managed to get some datas
sonoff:
username: !secret
password: !secret
reload: always
force_update: [temperature, humidity, power, current, voltage, rssi]
scan_interval: '00:01:00'
sensors: [temperature, humidity, power, current, voltage, rssi]
devices:
switch.sonoff_ballon:
name: ballon
force_update: True
sensor:
- platform: template
sensors:
today_consumption:
friendly_name: Today consumption
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_ballon', 'consumption').0 }}"
ten_days_consumption:
friendly_name: 10 days consumption
unit_of_measurement: kWh
value_template: "{% set p=state_attr('switch.sonoff_ballon', 'consumption') %}{{ p[:10]|sum if p }}"
@AlexxIT I've read your docs many times before sending this message. I am a beginner so couldn't get it to work. Actually I am trying get consumption for 1 week for everyday (Consumption for monday, consumption for tuesday etc...). I don't know what I need to enter to get last 7 days consumption (Not total one, I need consumption per day)
Hope it's clear for you. I am not a native english speaker. Sorry if it's confusing.
Thanks again for your help.
sensor:
- platform: template
sensors:
today_consumption:
friendly_name: Today consumption
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_ballon', 'consumption').0 }}"
yesterday_consumption:
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_ballon', 'consumption').1 }}"
day_before_consumption:
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_ballon', 'consumption').2 }}"
@AlexxIT thank you, for the point out. I've fixed the devices section as mentioned. @riyas1980 By following @AlexxIT example above, please refer below for my sensor.yaml configuration, i manage to get it working.
#Room Air Cond Power Consumption
- platform: template
sensors:
today_Room_air_cond:
friendly_name: Room Air Cond Today
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').0 }}"
1_Room_air_cond:
friendly_name: Room Air Cond 1 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').1 }}"
2_Room_air_cond:
friendly_name: Room Air Cond 2 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').2 }}"
3_Room_air_cond:
friendly_name: Room Air Cond 3 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').3 }}"
4_Room_air_cond:
friendly_name: Room Air Cond 4 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').4 }}"
5_Room_air_cond:
friendly_name: Room Air Cond 5 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').5 }}"
6_Room_air_cond:
friendly_name: Room Air Cond 6 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').6 }}"
7_Room_air_cond:
friendly_name: Room Air Cond 7 Day Ago
unit_of_measurement: kWh
value_template: "{{ state_attr('sensor.sonoff_XXXXXXXXX_power', 'consumption').7 }}"
@AlexxIT Thanks alot for this components really appreciate it. Can you suggest a way to trigger an automation to run sonoff.update_consumption service with interval?
@AlexxIT @devilization Thanks a lot for your help. It looks good now.
Like @devilization I am now trying to trigger automatically sonoff.update_consumption service with interval.
Hi,
Below is my configuration in automations.yaml
- id: '1602173105130'
alias: Sonoff Update Consumption
description: ''
trigger:
- platform: time
at: 01:00:00
- platform: homeassistant
event: start
condition: []
action:
- service: sonoff.update_consumption
data: {}
mode: single
max: 3
So base on the configuration, i have 2 trigger point, which is:
- 1AM everyday
- Whenever i restart my HA
And make sure on the action you include the sonoff.update_consumption to call the service (as mention on @AlexxIT documentation)
Hey, @devilization
Am looking for a way to call sonoff.update_consumption every 5min i tried "numeric state" with power as a trigger it worked but it keep calling sonoff.update_consumption alot. making the logs messy
@devilization Thanks for your help. Everything is working fine :-)
Thanks everyone for the help. Please close this thread