Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#1 Post by RonkA » 08 Jan 2023, 19:16

Hello,

I am looking for someone who can help me with an Esp-easy project that I am stranded with.

18 Months ago I had a stroke and since then my short term memory has failed me and my 'brain processing capacity' has dropped quite a bit.
Tinkering with domotica has been my hobby for years and I am more or less trying to pick up the thread again.
Recently I started with Esp and that is fun but like the rest of my live now a very steep learning curve..

Last year I made a KWH counter for my 3 phase boiler in Domoticz: https://www.domoticz.com/forum/viewtopic.php?t=38717
Now I want to do the same for my Quooker, but I can't open it to place an actor in it, so I have to do it on the wcd side.
I once bought a Sonoff pow-r2 V2.0 and was able to flash it to Esp-easy (A few weeks later... (google has become really a search-engine not a find-engine))
In the end I managed to activate the meter via rules, this is where it actually stops;

What I would like is that when the quooker switches on, the pow-r2 switches on a switch, I use domoticz, from here I can do the calculation as I do with my boiler.

So I managed to link the button to domoticz and pressing it works instanly in Domoticz so the calculation would be correct.
But I can't get any further things done via rules, it must be a problem with syntax or something else, but I'm stuck here.
I did manage to make a dummy that takes over the 'power' value when I press the button (I see it in the log of the esp) but further calculations or operations i cannot get to work..

My idea is after powerup Domoticz gets a' off' statement; Then if the 'power' value exceeds, for example, 50 watts, Domotics gets a switch on statement 'on', if the power falls under the 50 watts a 'off' statement is issued.

Code: Select all

on POW_r2#Power>50 do
 GPIO,13,1
 else
 GPIO,13,0
endon
I tried everything, variations on the above, TaskValueSet etc , searched everywhere.. I can't...I'M STUCK!!! Help!!

Could you help me with this or do you know someone who can help me?

I like to hear it.

Sincerely,
RonkA.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#2 Post by Ath » 08 Jan 2023, 19:32

Welcome (back) to ESPEasy :),

There's a syntax issue in your rules, indeed, you're mixing the "on event do" and "if condition" commands, and that's not supported.
Your rule should be like this:

Code: Select all

on POW_r2#Power do
  if %eventvalue1%>50
    GPIO,13,1 // LED on
  else
    GPIO,13,0 // LED off
  endif
endon
Assuming you have, in ESPEasy, a Switch device task configured for GPIO 13, and a matching device in Domoticz, with that idx configured in ESPEasy, it will be immediately visible in Domoticz if the LED is switched on.
/Ton (PayPal.me)

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#3 Post by RonkA » 09 Jan 2023, 00:45

Hello Ath,

Thanks for the info, sandly it did not resulted in success.
I pasted the rule you gave me and i added system#boot to close the relay at startup to get power to the Quooker so the measurement is possible:

Code: Select all

on System#Boot do
  GPIO,12,1
endon
on POW_r2#Power do
  if %eventvalue1%>50
    GPIO,13,1 // LED on
  else
    GPIO,13,0 // LED off
  endif
endon
It Doesnt work;
The POW r2 has a button on it (GPIO-0);To test if i could see the status in Domoticz change i tried:

Code: Select all

on System#Boot do
  GPIO,12,1
endon
on button#state do
if [button#state]=0
gpio,13,1
else
gpio,13,0
endif
endon
This does work to reach Domoticz..

I try to understand the %eventvalue1% command, so from 'POW_r2' the value 676.24 is read from 'Power' and is placed in %eventvalue1% i understand correct?
So 672.24>50 thus Led should turn on. (screenshot gives ledstate 1 but thats from the buttonstate; the test rule not from the first rule..)
ESP.jpg
ESP.jpg (98.76 KiB) Viewed 1577 times
But No Bueno.. if i set the log on 'debug' the measurement floods the log so thats not an option.. so back to square 1..Suggestions?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#4 Post by TD-er » 09 Jan 2023, 08:16

To combine switches and relais with Domoticz, you need to use this: https://espeasy.readthedocs.io/en/lates ... #p029-page

Just keep in mind the GPIO for the relay may be different from the example screenshots of the POW r1.

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#5 Post by RonkA » 09 Jan 2023, 12:02

No Bueno..

From domoticz i can turn the led on the device on and off (inverted; if domoticz says off, the led is on, but that's no problem)

Could it be that the 'POW_r2#Power' value change is not strong enough to start the rule to work?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#6 Post by TD-er » 09 Jan 2023, 12:14

Do you have "send all values in single event" checked on the task?
If so, then you will not see the event you try to match here.

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#7 Post by RonkA » 09 Jan 2023, 12:35

I have "send all values in single event" unchecked on all possible tasks

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#8 Post by TD-er » 09 Jan 2023, 13:42

Perhaps it helps to 'debug' the rules a bit more by sending stuff to the log of ESPEasy.

Code: Select all

on POW_r2#Power do
  if %eventvalue1%>50
    logEntry,"POW_r2#Power > 50: %eventvalue1% Watt"
    GPIO,13,1 // LED on
  else
    GPIO,13,0 // LED off
  endif
endon
This way, you can see how often this event is sent.

But like I also asked you via email, what do you try to achieve?
Maybe we can come up with way more elegant solutions if we know what you want to know.

What I mean is, would you like to calculate the power consumption of the Quooker, or how often it switches on, or how long?
And not like "If the Quooker switches on, I want a switch activated in Domoticz", since that's what you now try to do, but it may not be relevant for what you actually want to achieve.
If it actually is what you want to achieve, because you need to turn on a fan or whatever, then that's what I want to know from you.

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#9 Post by RonkA » 08 Mar 2024, 14:16

Trying to boost this thread, no more trying to switch on or of at a powerusage; iI now would like to monitor the power beeing used via Domoticz.. (so no funny stuff anymore, just measure..)
back to step 2, i read that to get the different values of data to Domoticz is done by using SendtoHTTP so i now use this for the rule.

Code: Select all

on System#Boot do
  GPIO,12,1
endon

On POW_2_Sensors#POW_2_Voltage do
SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=231&nvalue=0&svalue=[POW_2_Sensors#POW_2_Voltage] //Send the Voltage data to Domoticz
SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=327&nvalue=0&svalue=[POW_2_Sensors#POW_2_Power] //Send the Watt data to Domoticz
SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=233&nvalue=0&svalue=[POW_2_Sensors#POW_2_Current] //Send the Amp data to Domoticz
SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=234&nvalue=0&svalue=[POW_2_Sensors#POW_2_Pulses] //Send the Usage data to Domoticz
endon
I renamed the devicename from POW_r2 to 'POW_2' seeing everyone on forums called it that; dont know if this is necessary..

In Domoticz i have the dummy powermeter and if i send via a browser the value 100 to it using:

Code: Select all

192.168.178.2:7080:/json.htm?type=command&param=udevice&idx=327&nvalue=0&svalue=100
it does register and sets the value correctly.

in the debuglog there are many CSE entrys but no further actions so i think the On-- do part of the rule is not triggering..
i dont understand why this is not working like is should as it doing for many others..
Is there a wiki or help to get this thing working, because i'm loosing my mind over this

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#10 Post by TD-er » 08 Mar 2024, 15:09

POW_2_Sensors#POW_2_Voltage

This implies you have a task named: "POW_2_Sensors" and it does have a taskvalue named: "POW_2_Voltage"
Please check the logs to see what event is generated.

If you have checked the checkbox to send it all in a single event, then the event will be like this:
POW_2_Sensors#All

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#11 Post by RonkA » 08 Mar 2024, 20:05

Made some progress..

not the single event but Devices->Data Acquisition->Interval being zero was the problem.. now set to 5 seconds and the log states:
5518805: EVENT: POW_2#Voltage=225.62
5518811: EVENT: POW_2#Power=0.00
5518816: EVENT: POW_2#Current=0.00
5518821: EVENT: POW_2#Pulses=34589.00
5522797: EVENT: POW_2#Voltage=224.56
5522804: EVENT: POW_2#Power=0.00
5522809: EVENT: POW_2#Current=0.00
5522812: EVENT: POW_2#Pulses=34589.00
Etc.
Onto the next hurdle.. sending POW_2#Power=0.00 to domoticz dummy 327..

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#12 Post by Ath » 08 Mar 2024, 21:24

RonkA wrote: 08 Mar 2024, 20:05 Made some progress..
5518811: EVENT: POW_2#Power=0.00
5518816: EVENT: POW_2#Current=0.00
5518821: EVENT: POW_2#Pulses=34589.00
5522797: EVENT: POW_2#Voltage=224.56
5522804: EVENT: POW_2#Power=0.00
5522809: EVENT: POW_2#Current=0.00
5522812: EVENT: POW_2#Pulses=34589.00
Etc.
Well, this list of events makes it somewhat more clear, you should use exactly those name as the values, like:

Code: Select all

On POW_2#Voltage do
  SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=231&nvalue=0&svalue=[POW_2#Voltage] //Send the Voltage data to Domoticz
  SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=327&nvalue=0&svalue=[POW_2#Power] //Send the Watt data to Domoticz
  SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=233&nvalue=0&svalue=[POW_2#Current] //Send the Amp data to Domoticz
  SendToHTTP 192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=234&nvalue=0&svalue=[POW_2#Pulses] //Send the Usage data to Domoticz
endon
Not sure why you added those postfixes/prefixes to the names?
/Ton (PayPal.me)

RonkA
Normal user
Posts: 10
Joined: 07 Jan 2023, 02:58
Location: The Netherlands

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#13 Post by RonkA » 08 Mar 2024, 22:30

Just all copy/paste problems..

Made some progress, have data going to Domoticz via this rule:

Code: Select all

on System#Boot do
  GPIO,12,1
endon

On POW_2#Power do
 if [POW_2#Power]!=[LAST#Power]
  SendToHTTP,<user>:<pass>@192.168.178.2,7080,/json.htm?type=command&param=udevice&idx=327&nvalue=0&svalue=[POW_2#Power]
   TaskValueSet 6,1,[POW_2#Power]
 endif
endon
Some more Copy/paste..
As i understand should this POW_2#Power only update the dummy counter if the value changes, i dont see this happening but part of the mistery is solved so success!!

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Sonoff POW-R2 v2.0 to monitor powerusage via Domoticz

#14 Post by TD-er » 08 Mar 2024, 22:32

You can also use system variables instead of dummy tasks to keep track of those changes.

Or.... just leave it as it is now as it is now working :)

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests