I have a Sonoff POW R2 (original fw) and I’m trying to get some information, but I don’t know if i´m gonna get having the device with original firmware.
The main question is: Is it possible to extract from the device more info than the power, current, and voltage?
This 3 information I have working fine, but I thought I just had to multiply the power information and the rate, so I would have monthly and daily rate (of course, using utility_meter)
This is my lovelace:
You can see, only today 22.5Kwh … that’s impossible… I would like a way to capture the daily info from the device or ewelink app …
Checking my ewelink app, today was only 0.15, not 22 …
You are using the incorrect sensor for the utility meter. You need to use an energy sensor, not power.
The POW2 does have a total energy consumed sensor that you can feed to utility meters for weekly/monthly/yearly cycles. It also has total energy consumed sensors for today and yesterday.
I do not know if/how these are available on the standard firmware. Tasmota certainly has them:
That´s the problem… sonoff provides me only on/off, current, power and voltage… there´s no “energy sensor”… that´s why I’m using the power info to do all the math
I know tasmota is much better, but my pow r2 is a little but inaccessible, behind heavy furniture, etc…
I don’t think that custom components offers energy sensor, as (I believe) one could only turn existing attributes into sensors.
But, yeah, @Guilherme_Gimenes , I’m interested in the result of the test that Tom suggested above.
Searching through the internet… would this help at all? Let us know.
The only way I found to have my sonoff devices linked to HA was to use this custom component I got here:
I just downloaded and copied the folder “sonoff” with all its contents to my folder “custom_components” and then added the code you just mentioned. Always worked perfectly with my 4 basicR2 and 2 TX switches.
Is there any other way to have them working with HA?
I just checked the link I pasted here and it says there´s no energy option …
I´m already doing that. Actually it only converts W to Kwh, and then I multiply by the rate I have. The issue is: I´m still using the power sensor, not the energy, got it? I have to find a way to get a energy sensor… and I´m not sure If I will be able to get it having the original fw.
for example, using power sensor, converted to K, 759KWh in one day LOL … times 0.62, 472 bucks in one day.
The integral of power with respect to time is energy. The output of the integral sensor is energy. You have an energy sensor, use it in your utility meter. Many people do this. Search the forum.
My custom component provides me only voltage, power and voltage. If I use the integration, it will convert K to KWh… It is doing that… but it shows like 400KWh in one day… checking my app, the correct number should be like 2KWh a day. If my component provides also energy, I would use it with the integration, to convert to KWh, and then multiply by the rate to know the cost. I´m using incorrectly the power sensor as the source of the information I need.
Riemann sum method to be used. Available methods are trapezoidal, left and right.
In case you have an appliance which produces spikey consumption (like an on/off electrical boiler) you should opt for the left method to get accurate readings.
Thank you very much @k8gg ! it worked!
My sensors.yaml
custo_energia_mes_simples: # teste de valor multiplicando o mensal pelo valor. Está funcionando corretamente, mas não possui botão dinamico para informar o valor.
friendly_name: Custo Mensal 2 - valor no codigo
value_template: "{{ (states('sensor.consumo_mes_kwh') | float * 0.62) | round(2) }}"
unit_of_measurement: 'R$'
consumo_dia_kwh:
friendly_name: Consumo DIA # marcação do consumo diário do SONOFF POW R2 >> é necessário "call service" sonoff:update_consumption, em Developer Tools\Services para update. Usar automation
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_1000fe1f6c', 'consumption').0 }}"
consumo_mes_kwh:
friendly_name: Consumo MÊS # marcação do consumo diário do SONOFF POW R2 >> é necessário "call service" sonoff:update_consumption, em Developer Tools\Services para update. Usar automation
unit_of_measurement: kWh
value_template: "{% set p=state_attr('switch.sonoff_1000fe1f6c', 'consumption') %}{{ p[:22]|sum if p }}"
Now I know how much I´m spending daily. The only issue is that I cannot know monthly, only the past 30 days… and now for example, if I set to 30, it will show me 23 days this months + 7 days last month… it shows me periods, not the whole closed month… no big deal.
To have it working real-time, I have to manually call the service “sonoff:update_consumption”, so the next step is to create an automation to have the sensors updating, I don’t know, every hour maybe.
Sorry, @tom_l , I´m still a newbie, that´s why I ask basic questions here. (and sometimes the English language is a problem too)
Using the code below, I´m able to get the KWh (daily and monthly), but like I said, it´s a continuous counter, so if I set to 30, on July 1st, it will count the past 30 days, not july 1st onwards.
sensors.yaml:
consumo_dia_kwh:
friendly_name: Consumo DIA
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_1000fe1f6c', 'consumption').0 }}"
consumo_mes_kwh:
friendly_name: Consumo MÊS
unit_of_measurement: kWh
value_template: "{% set p=state_attr('switch.sonoff_1000fe1f6c', 'consumption') %}{{ p[:30]|sum if p }}"
2 new entities created:
So, you are saying I must add to my configuration.yaml:
but the question is: which entity / source should I use? switch.sonoff_1000fe1f6c (main), sensor.consumo_dia_kwh (day) or sensor.consumo_mes_kwh (month) ?
Is there no continuous energy consumption meter that does not reset?
Ideally that is what you want to feed the utility meter.
But, the utility meter is clever and only reacts to an increase. So it shouldn’t matter if the sensor you use for it resets occasionally.
Say you have a utility meter with a yearly cycle, if on day 30 you get an increase from 90 to 95 in the sensor you feed the utility meter, it will add 5 to the utility meter value. The next day the sensor resets to 0 then increases to 7. The utility meter still adds 7 to its total.
If all you have is the 30 day sensor you should still be able to use that for any cycle length in the utility meter.
consumo_dia_kwh:
friendly_name: Consumo DIA # marcação do consumo diário do SONOFF POW R2 >> é necessário "call service" sonoff:update_consumption, em Developer Tools\Services para update. Usar automation
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_1000fe1f6c', 'consumption').0 }}"
consumo_mes_kwh:
friendly_name: Consumo MÊS # marcação do consumo diário do SONOFF POW R2 >> é necessário "call service" sonoff:update_consumption, em Developer Tools\Services para update. Usar automation
unit_of_measurement: kWh
value_template: "{% set p=state_attr('switch.sonoff_1000fe1f6c', 'consumption') %}{{ p[:25]|sum if p }}"
with the code above, 2 entities were generated:
1 - sensor.consumo_dia_kwh: 1-day count - it works for me
2 - sensor.consumo_mes_kwh: 30 days count - it doesn’t work for me, because I need the month (right now June, not the past 30 days including 5 days of May)
notice that my code is “25” instead of 30… I did it on purpose today, because today is 25th and now I´m able to see the the whole June
I´m using as a source, “sensor.consumo_mes_kwh” and a new entity was created: sensor.consumo_mensal_utility_meter
And I´m using this entity, hoping it will work. I will wait until 1st of july, to see if the counter will start over… right now, it is increasing every day… if it is 1kwh, and the day increases 1.5, this entity also increases 1.5 becoming 2.5 …let´s see what´s gonna happen
I´m able to capture the daily energy, and it resets everyday. (If I set to “1” instead of “0”, it shows me yesterday´s energy)
sensors.yaml:
energy_day_kwh:
friendly_name: Day Energy
unit_of_measurement: kWh
value_template: "{{ state_attr('switch.sonoff_1000fe1f6c', 'consumption').0 }}"
consumo_mes_kwh:
and I´m able to get the energy from the past 30 days (today is July 2nd, so I´m getting 28 days from June and 2 from July)
energy_month_kwh:
friendly_name: Month energy
unit_of_measurement: kWh
value_template: "{% set p=state_attr('switch.sonoff_1000fe1f6c', 'consumption') %}{{ p[:30]|sum if p }}"
so far so good. What I did next to capture the current month, excluding days from the previous month:
configuration.yaml:
utility_meter:
Energy TEST:
source: sensor.energy_day_kwh
cycle: monthly
Check below: The day is correct, I just checked the app and it is the same
But… The month is wrong. Today is July 2nd, and the number should be 2.42 (yesterday) + 1.19 (today) = 3,61 … instead of 1.14 …