# Sonoff POW R2 readings - Calculating costs? :)

Gooooooooood morning, afternoon or evening

I’m trying to get the costs \$\$\$ of recorded power usage from my Sonoff POW R2.
I’m not sure if this is possible and after scouring the HA community, google and youtube, I have found many people asking similar questions with either little responses or solutions that did not work…

The reason for this request:

My SPA (Hot Tub) drains lotssss of power (\$\$\$\$) as it is pretty much an "always ON" water pump+heater.

To control the SPA’s filter and heater I am using a Sonoff TH16 and Sonoff POW R2.
With these two devices, I am using automations (thanks to @tom_l ) to turn the SPA - ON for 2hrs and then OFF - at 3 different set times a day (to activate the filter) and an “over ride” feature (to activate the heater) for when I want to use the SPA.

I want to use the Sonoff POW R2 readings to help me efficiently customise the FILTER ON/OFF automations and when to HEAT the SPA.

I would greatly appreciate any assistance

• Energy cost = 1kWh = \$0.34

I’d like to be able to show:

• total cost for the day

• total cost for the week

• total cost for the month

• It would need to reset each month

Below is a little example I mocked up:

I appreciate any help

Kind regards

Paul

Hmmmm after much research, I think the answer to my question has something to do with “templates”… not sure entirely how these work, but I’m learning

I’ll report back after I tinker with a few things.

Templates are not that hard. Here is mine

``````  kosten_server:
value_template: "{{ states.sensor.sonoff_pow2_1_total_energy.state | multiply(0.28) | round(2)}}"
friendly_name: 'Kosten'
unit_of_measurement: '€'
``````

Multiply 0.28 is 28 cents per kw/h here in germany. Round 2 gives you two digits after the comma.

After that you just have to display it with - sensor.kosten_server (or the name you choose for the template) in your groups or lovelace.

Result looks like this.

5 Likes

Thanks for the help @Piet1702

Good timing - I actually figured it out last night too:

``````- platform: template
sensors:
spa_power_today_cost:
friendly_name: "Today's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.spa_power_usage_today')|float * 0.35)| round(2) }}"
spa_power_yesterday_cost:
friendly_name: "Yesterday's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.spa_power_usage_yesterday')|float * 0.35)| round(2) }}"
``````

Worked perfectly… next I’ll try to figure out how to log 1 month worth of readings and calculate the cost of that too.

6 Likes

Hello @pppaulie_s

Would it be possible for you to share the complete setup that you are useing with the Sonoff POW R2?

I have some POW R2 on the way and would really like the same setup as you have running.

BR.

can someone give an example how to calculate costs for each month? thanks

G’day @Orion,

Please see below for my Washing Machine and Dryer YAML.

• This creates sensors to measure the volts, amps, watts etc.
• It also uses “templates” to calculate costs for “yesterday” and “todays” usage (@ 0.35cents AUD per KWh)
• It also notifies me (automation) through my SONOS via TTS (Bedroom and Living Room) when the cycle is complete

``````sensor:
# LAUNDRY SENSORS
# DRYER SONOFF POW R2
- platform: mqtt
name: "Dryer Volts"
state_topic: "dryer/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Voltage"] }}'
unit_of_measurement: "volts"
- platform: mqtt
name: "Dryer Amps"
state_topic: "dryer/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Current"] }}'
unit_of_measurement: "amps"
- platform: mqtt
name: "Dryer Watts"
state_topic: "dryer/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Power"] }}'
unit_of_measurement: "watts"
- platform: mqtt
name: "Dryer Power Usage - TODAY"
state_topic: "dryer/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Today"] }}'
unit_of_measurement: "kW"
- platform: mqtt
name: "Dryer Power Usage - YESTERDAY"
state_topic: "dryer/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Yesterday"] }}'
unit_of_measurement: "kW"

# WASHING MACHINE SONOFF POW R2
- platform: mqtt
name: "Washing Machine Volts"
state_topic: "washing_machine/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Voltage"] }}'
unit_of_measurement: "volts"
- platform: mqtt
name: "Washing Machine Amps"
state_topic: "washing_machine/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Current"] }}'
unit_of_measurement: "amps"
- platform: mqtt
name: "Washing Machine Watts"
state_topic: "washing_machine/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Power"] }}'
unit_of_measurement: "watts"
- platform: mqtt
name: "Washing Machine Power Usage - TODAY"
state_topic: "washing_machine/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Today"] }}'
unit_of_measurement: "kW"
- platform: mqtt
name: "Washing Machine Power Usage - YESTERDAY"
state_topic: "washing_machine/tele/SENSOR"
value_template: '{{ value_json["ENERGY"]["Yesterday"] }}'
unit_of_measurement: "kW"

# DRYER Template COSTS
- platform: template
sensors:
dryer_power_today_cost:
friendly_name: "Dryer - Today's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.dryer_power_usage_today')|float * 0.35)| round(2) }}"
dryer_power_yesterday_cost:
friendly_name: "Dryer - Yesterday's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.dryer_power_usage_yesterday')|float * 0.35)| round(2) }}"

# WASHING MACHINE Template COSTS
- platform: template
sensors:
washing_machine_power_today_cost:
friendly_name: "Washing Machine - Today's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.washing_machine_power_usage_today')|float * 0.35)| round(2) }}"
washing_machine_power_yesterday_cost:
friendly_name: "Washing Machine - Yesterday's Cost"
unit_of_measurement: '\$'
value_template: "{{ (states('sensor.washing_machine_power_usage_yesterday')|float * 0.35)| round(2) }}"

binary_sensor:
# Washer and Dryer on/off status
- platform: template
sensors:
washer_status:
friendly_name: "Washing Machine Status"
#delay_on:
# seconds: 10
#minutes: 10
delay_off:
seconds: 5
#minutes: 3
value_template: >-
{{ states('sensor.washing_machine_watts')|float > 0 }}
dryer_status:
friendly_name: "Dryer Status"
#   delay_on:
#     minutes: 10
delay_off:
seconds: 5
value_template: >-
{{ states('sensor.dryer_watts')|float > 0 }}

automation:
#NOTIFY via Sonos TTS
#WASHING MACHINE
trigger:
platform: state
entity_id: binary_sensor.washer_status
to: 'off'
action:
- service: notify.android
data:
message: Washing Machine has finished its cycle
- service: media_player.volume_set
data:
entity_id: media_player.bedroom
volume_level: 0.5
- service: media_player.volume_set
data:
entity_id: media_player.living_room
volume_level: 0.5
data:
entity_id: media_player.bedroom
message: "The Washing Machine has finished its cycle"
data:
entity_id: media_player.living_room
message: "The Washing Machine has finished its cycle"

#DRYER
trigger:
platform: state
entity_id: binary_sensor.dryer_status
to: 'off'
action:
- service: notify.android
data:
message: Dryer has finished its cycle
- service: media_player.volume_set
data:
entity_id: media_player.bedroom
volume_level: 0.5
- service: media_player.volume_set
data:
entity_id: media_player.living_room
volume_level: 0.5
data:
entity_id: media_player.bedroom
message: "The Dryer has finished its cycle"
data:
entity_id: media_player.living_room
message: "The Dryer has finished its cycle"

switch:
#WASHING MACHINE & DRYER ON/OFF POWER SWITCH
- platform: mqtt
name: "Dryer Power"
state_topic: "dryer/stat/POWER"
command_topic: "dryer/cmnd/POWER"
qos: 1
retain: true
- platform: mqtt
name: "Washing Machine Power"
state_topic: "washing_machine/stat/POWER"
command_topic: "washing_machine/cmnd/POWER"
qos: 1
retain: true``````
3 Likes

Hi @DobriyS,

Unfortunately I haven’t worked out how to calculate costs for a month yet…
On the to-do list

1 Like

I just found this component - Utility Meter
I think this component will help to calculate costs

The `utility meter` component provides functionality to track consumptions of various utilities (e.g., energy, gas, water, heating).

From a user perspective, utility meters operate in cycles (usually monthly) for billing purposes. This sensor will track a source sensor values, automatically resetting the meter based on the configured cycle. On reset an attribute will store the previous meter value, providing the means for comparison operations (e.g., “did I spend more or less this month?”) or billing estimation (e.g., through a sensor template that multiplies the metered value per the charged unit amount).

3 Likes

Great find @DobriyS, that component looks like it will do the trick! When I get a moment, I’ll have a play around with it and see what happens.
Thank you for sharing this!!

Massive, I was just looking for something like this. Thanks all!

1 Like

Hello there! How is the monthly reset set?
Thank you !!

did u got it working? for monthly and yearly tracking ? please share your experience

nothing works i have mqtt discovery on and i can’t find out what i’m doing wrong for the cost calculation i tried everything please for help

this is how it loks im my config have is forgot enything?

• platform: template
kosten_computer:
value_template: “{{ (states(‘sensor.computersystem_energy_total’) | float * 0.28) | round(2)}}”
friendly_name: ‘Kosten’
unit_of_measurement: ‘€’

hi paul
i saw you have an mspa jaccuzi and sonof th16 and pow 2
how did you connect al this?
i’m very interested in this
i want to control my mspa with the pow r2 and th

now the jaccuzi has a wired controller buth i want to replace this with the powr2 and th16

if i read it correct you did this?
how did you do it?

many thanks

to give you more info i have a mspa silvercloud with a wired remote =

And i’m willing to open the plastic unit and replece the cables with sonoff.
I already opened it and followed the cables, i found 3 of 4 connection point, each point goes to another ‘device’ (i think = heather, pump, temp sensor, airblower)

if you could tel me how to wire the sonoff sensors to it it would really by helpfull!!
the wire that goes to the tempsensor look straigt forward = i should replace this one with a sonof TH16 and the waterproof sensor of sonof.
The oher devices (pump, heather and air blower) are for me not clear.

i’m an advanced user with sonof and tasmota so i know how to flash this devices (flashed TH16, POWR2 and mini’s
i just dont know the wiring , if you would help me that would me very much appreciated,

if you have some questions about tasmota you can also ask me them

Hello All
I am interested in this topic as well but I am a newcomer and
I am not really sure, what part of code belongs to what file (folder)
I would be very appreciated for an explanation, how to call the consumption (tay, week,month) of a Sonoff POW .
@ pppaulie_s, Paul … how did you get the reading on you’re first published sheet ? Could you advise ?
I really appreciate every help. (German would be fine too.)
Wolfgang