solved - S0 Counter - Rules - calculate after new pulse

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

solved - S0 Counter - Rules - calculate after new pulse

#1 Post by spitzlbergerj » 30 Oct 2022, 10:12

Hi,
I want to build a pulse counter for the S0 interface of three electricity meters. The counting of the pulses works already. Now I want to reproduce the current meter value via Rules.

My electricity meters emit 100 and 1000 pulses per kWh. The counted pulses must be divided by 100 or 1000 to calculate the actual meter value. Furthermore, I would like to calculate the meter reading to 1 decimal digit.

I have used "generic pulse counter" as devices. The variables count and total are filled accordingly.

Now I have created a rule that should do the calculation:

Code: Select all

// -------------------------------------------------------
// Set the pulses per kWh per counter unit
// -------------------------------------------------------
//
On System#Boot do
  let,11,100 // Electricity meter 1: 100 pulses per kWh
  let,12,1000 // Current counter 2: 1000 pulses per kWh
  let,13,1000 // Current counter 3: 1000 pulses per kWh
endon


// -------------------------------------------------------
// current total divided by pulses = meter value
// so that the meter value contains only one decimal digit
// round the quotient to (pulses per kWh) 10 and later divide by 10
// -------------------------------------------------------
//
on Pulse1#Total > 0 do
  let,1,round(Pulse1#Total/([int#12]/10))/10
endon

on Pulse2#Total > 0 do
  let,2,round(Pulse2#Total/([int#12]/10))/10
endon

on Pulse3#Total > 0 do
  let,3,round(Pulse3#Total/([int#13]/10))/10
endon
Unfortunately the variables 1, 2 and 3 always remain at 0.

The devices are defined as:
Screenshot 2022-10-30 101114.png
Screenshot 2022-10-30 101114.png (110.21 KiB) Viewed 2908 times
What am I doing wrong?

Many greetings and thanks
Sepp
Last edited by spitzlbergerj on 30 Oct 2022, 13:39, edited 1 time in total.
Interested layman ... ;)

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

Re: S0 Counter - Rules - calculate after new pulse

#2 Post by Ath » 30 Oct 2022, 10:52

You forgot a couple of square braces:
f.e. here

Code: Select all

on Pulse1#Total > 0 do // The event doesn't have braces
  let,1,round([Pulse1#Total]/([int#12]/10))/10 // Accessing a variable requires square braces
endon
/Ton (PayPal.me)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: S0 Counter - Rules - calculate after new pulse

#3 Post by spitzlbergerj » 30 Oct 2022, 11:15

Thanks, @Ath,

I have now tried it with this:

Code: Select all

on [Pulse1#Total] > 0 do
  let,1,round([Pulse1#Total]/([int#12]/10))/10
endon

on [Pulse2#Total] > 0 do
  let,2,round([Pulse2#Total]/([int#12]/10))/10
endon

on [Pulse3#Total] > 0 do
  let,3,round([Pulse3#Total]/([int#13]/10))/10
endon
But the problem still exists ...

I show the variable on the display as follows
Screenshot 2022-10-30 111327.png
Screenshot 2022-10-30 111327.png (53.22 KiB) Viewed 2899 times
Var#11 is displayed correctly as 100 and all others are still displayed as 0

Any further ideas?
Interested layman ... ;)

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

Re: S0 Counter - Rules - calculate after new pulse

#4 Post by TD-er » 30 Oct 2022, 11:26

Can you show what is sent to the (debug) log?
Also not sure if it matters, but you can also just compute the value and then use formatting when showing it on the display.

Code: Select all

let,1,[Pulse1#Total]/[var#12]
See for formatting:
https://espeasy.readthedocs.io/en/lates ... red-values

Code: Select all

[var#1#D.1]

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

Re: S0 Counter - Rules - calculate after new pulse

#5 Post by Ath » 30 Oct 2022, 11:30

spitzlbergerj wrote: 30 Oct 2022, 11:15 I have now tried it with this:

Code: Select all

on [Pulse1#Total] > 0 do
  let,1,round([Pulse1#Total]/([int#12]/10))/10
endon
You have also added braces to the event (on .. do) line, but there you shouldn't have braces... :? (see comments in the example)
/Ton (PayPal.me)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: S0 Counter - Rules - calculate after new pulse

#6 Post by spitzlbergerj » 30 Oct 2022, 11:54

Many thanks to you all,

here is the log:

Code: Select all

1817352: EVENT: Pulse1#All=0,10021,0
1817392: EVENT: Pulse2#Count=0
1817396: EVENT: Pulse2#Total=45
1817401: EVENT: Pulse2#Time=0
1817432: EVENT: Pulse3#All=2,41,378
1818348: EVENT: Pulse1#All=0,10021,0
1818392: EVENT: Pulse2#Count=0
1818396: EVENT: Pulse2#Total=45
1818400: EVENT: Pulse2#Time=0
1818431: EVENT: Pulse3#All=0,41,0
1819350: EVENT: Pulse1#All=1,10022,5791
1819392: EVENT: Pulse2#Count=0
1819398: EVENT: Pulse2#Total=45
1819402: EVENT: Pulse2#Time=0
1819431: EVENT: Pulse3#All=0,41,0
1820408: EVENT: Pulse1#All=0,10022,0
1820412: EVENT: Pulse2#Count=0
1820415: EVENT: Pulse2#Total=45
1820423: EVENT: Pulse2#Time=0
1820441: EVENT: Pulse3#All=0,41,0
one more pulse at pulse counter 1

@Ath, sorry, I had tried it at the trigger first without [ ], that didn't work, so I added them brackets then.
Unfortunately the rule in both variants, i.e. trigger without brackets, does not work yet

@TD-er, unfortunately the simple statement without round doesn't work either.
Interested layman ... ;)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: S0 Counter - Rules - calculate after new pulse

#7 Post by spitzlbergerj » 30 Oct 2022, 12:02

Hi,

I have just found a solution. The following rule gets triggered and then also the correct calculation is done

Code: Select all

on Pulse1#Time=0 do
  let,1,[Pulse1#Total]/[var#11]
endon
Tahnks a lot for your help

Regards
Josef
Interested layman ... ;)

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

Re: S0 Counter - Rules - calculate after new pulse

#8 Post by TD-er » 30 Oct 2022, 12:32

Not sure whether the "=0" part should be there in the "on Pulse1#Time=0 do"

So keep an eye on that to see if keeps working as expected.

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

Re: S0 Counter - Rules - calculate after new pulse

#9 Post by Ath » 30 Oct 2022, 12:38

You seem to have the setting "Single event with all values" checked for Pulse1, as there is a Pulse1#All event. That's not wrong, but if you enable that setting, the separate Pulse1#Count, Pulse1#Total and Pulse1#Time events won't be generated for that task, only that single Pulse1#All event, with all task values, comma separated and thus available as %eventvalue1%, %eventvalue2% and %eventvalue3% in the event.

Using the %eventvalue1% etc. arguments has the advantage that you receive the value at the moment the event was generated, instead of the current value when using the [taskname#value] variable, there can be a delay before the rule is processed, but the %eventvalue1% etc. values are kept with the event.
/Ton (PayPal.me)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: S0 Counter - Rules - calculate after new pulse

#10 Post by spitzlbergerj » 30 Oct 2022, 13:02

Thank you, @Th-er and @Ath,

I will keep this in mind.

@Ath, I didn't understand fully the %eventvalue1%, %eventvalue2% and %eventvalue3% unfortunately. Could you explain it to me or link the doc for it.

And what would my rules look like then.

It would be great if I could update the rules for each event. Then I could also set the delay for the pulse counters higher.

And yes, I had the ALL option partially switched on. It is now off everywhere

Thanks
Sepp
Interested layman ... ;)

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

Re: S0 Counter - Rules - calculate after new pulse

#11 Post by TD-er » 30 Oct 2022, 13:16

I think sending a single event with "All" values is the better option in this use case.

Like what Ton said, it has all 3 values from the same moment and it generated less events to process.
%eventvalue1% is the the first task value (Count)
%eventvalue2% is the second task value(Total)
%eventvalue3% is the 3rd task value (time)

Code: Select all

on Pulse1#All do
  let,1,%eventvalue2%/[var#11]
endon

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

Re: S0 Counter - Rules - calculate after new pulse

#12 Post by Ath » 30 Oct 2022, 13:17

spitzlbergerj wrote: 30 Oct 2022, 13:02 @Ath, I didn't understand fully the %eventvalue1%, %eventvalue2% and %eventvalue3% unfortunately. Could you explain it to me or link the doc for it.
Documentation: https://espeasy.readthedocs.io/en/lates ... eventvalue
And please also look at the examples on that page (also above the paragraph that link takes you to)
/Ton (PayPal.me)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: S0 Counter - Rules - calculate after new pulse

#13 Post by spitzlbergerj » 30 Oct 2022, 13:38

Oh, Yes, that's great. Thanks a lot
Interested layman ... ;)

spitzlbergerj
Normal user
Posts: 11
Joined: 29 Oct 2022, 09:22
Location: Germany - Bavaria
Contact:

Re: solved - S0 Counter - Rules - calculate after new pulse

#14 Post by spitzlbergerj » 01 Nov 2022, 08:48

Hi @Ath and @TD-er,

I have now tried around for a while. And it seems that the event

Code: Select all

on Pulse1#All do
...
enddo
would not be recognized. Anyway no let command is executed

But if I set the trigger to

Code: Select all

Pulse1#*
then it works.

Can this be?
Interested layman ... ;)

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

Re: solved - S0 Counter - Rules - calculate after new pulse

#15 Post by Ath » 01 Nov 2022, 09:18

spitzlbergerj wrote: 01 Nov 2022, 08:48 I have now tried around for a while. And it seems that the event

Code: Select all

on Pulse1#All do
...
enddo
would not be recognized. Anyway no let command is executed

But if I set the trigger to

Code: Select all

Pulse1#*
then it works.

Can this be?
The <taskname>#All event is only generated if the corresponding checkbox is enabled for that task, if disabled, a separate event for each Value is generated.

Using "on Pulse1#* do" will catch any event for that task, including every Value event, or the All event if that's generated.
/Ton (PayPal.me)

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

Re: solved - S0 Counter - Rules - calculate after new pulse

#16 Post by TD-er » 01 Nov 2022, 13:01

Please note that if you haven't checked to send all values in a single ....#All event, it will send as many events as there are task values for that task.
Thus if you try to calculate stuff, it may be that the event handler block in the rules may be run too often.

Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests