Calculate: Unknown token input: error

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Calculate: Unknown token input: error

#1 Post by Micha_he » 02 May 2021, 18:56

Is there some problems in the source from 20210429 ?

Code: Select all

141496: SW : GPIO=4 State=1 Output value=0
141503: EVENT: Taster1#Status=0
141513: ACT : AsyncEvent,Schalten1
141597: EVENT: Schalten1
141612: Calculate: Unknown token input: %eventvalue% = 0
141623: Calculate: Unknown token input: %eventvalue% = 0
141636: Calculate: Unknown token input: %eventvalue% = 0
141637: Calculate: Unknown token input: %eventvalue% = 0
141642: ACT : GPIO,12,0
141645: GPIO : port#12: set to 0
142796: SW : GPIO=4 State=1 Output value=1
142801: EVENT: Taster1#Status=1
This is the event from the rule:

Code: Select all

on Schalten1 do
  if %eventvalue%=1
    if [Plugin#GPIO#Pinstate#12]=0
      GPIO,12,1
    endif
  else
    if %eventvalue%=0
      if [Plugin#GPIO#Pinstate#12]=1
        GPIO,12,0
      endif
    else
      if %eventvalue%>1 or %eventvalue%<0
        // nichts machen
      else
        // umschalten
        GPIO,12,[Plugin#GPIO#Pinstate#12#!Z]
      endif
    endif
  endif
endon
With older fimware-versions I've not seen this problem. Checked version from 20210223: I saw no errors in the log!

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

Re: Calculate: Unknown token input: error

#2 Post by TD-er » 02 May 2021, 20:45

You could also use "elseif". See:
https://espeasy.readthedocs.io/en/lates ... lseif-else
That does make the code quite a lot simpler.

Is the eventvalue an integer value, or a floating point value?
If it is an integer value, the last elseif will never be true. (
N.B. I inverted it since you only used the else branch.

I also renamed %eventvalue% to %eventvalue1%

Code: Select all

on Schalten1 do
  if %eventvalue1%=1
    if [Plugin#GPIO#Pinstate#12]=0
      GPIO,12,1
    endif
  elseif %eventvalue1%=0
    if [Plugin#GPIO#Pinstate#12]=1
      GPIO,12,0
    endif
  elseif %eventvalue1%<1 and %eventvalue1%>0
    // umschalten
    GPIO,12,[Plugin#GPIO#Pinstate#12#!Z]
  endif
endon

Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Calculate: Unknown token input: error

#3 Post by Micha_he » 02 May 2021, 21:32

Sure, the else-branch works. We discuss about this, some time ago.
A way (maybe the only one) to recognise that %eventvalue% is not set (instead of the normal integer).

And with %eventvalue1%, the error is the same.

By the 'elseif', I agree with you.

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

Re: Calculate: Unknown token input: error

#4 Post by TD-er » 02 May 2021, 21:55

Does the event have an eventvalue?

Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Calculate: Unknown token input: error

#5 Post by Micha_he » 02 May 2021, 22:10

If the error ocourred, no !

Tommorow I can check if the erroris also reported, when the eventvalue is set.

Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Calculate: Unknown token input: error

#6 Post by Micha_he » 06 May 2021, 17:45

Late, but now I've checked it:

The error only occurs, when no value is passed to the event !
Can you restore the previous behavior? Have you an idea, what codechange affects the changed behavior?

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

Re: Calculate: Unknown token input: error

#7 Post by TD-er » 06 May 2021, 21:19

What version was working as you'd expect?
And even more important, what do you expect if you try to perform calculations with %eventvalue% which is not present?

Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Calculate: Unknown token input: error

#8 Post by Micha_he » 07 May 2021, 08:15

I mentioned it in #1... The last good version was 20210223.

The reason, why I use it in all of my switches is:

My event 'Schalten' is called with '0' for OFF, '1' for ON and without a eventvalue for TOGGLE the state.
Furthermore, it is better to check whether a eventvalue has been passed to a rule. And in the absence of a way to check for 'IS NOT SET' or 'IS NOT NULL', I need to use my special IF-clause.

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

Re: Calculate: Unknown token input: error

#9 Post by TD-er » 07 May 2021, 10:39

Yep, it should indeed have an "unset" value.

Micha_he
Normal user
Posts: 294
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Calculate: Unknown token input: error

#10 Post by Micha_he » 10 May 2021, 11:32

Do you have an idea how/where we can correct the error in a reasonable time or should I open a Github-issue ?
I can't even find the position in the source, where the eventvalues are compared... :cry:

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

Re: Calculate: Unknown token input: error

#11 Post by TD-er » 10 May 2021, 11:55

I think a GitHub issue is the most practical way.

The function that replaces the eventvalues, does have a very cryptic name ;)

replace_EventValueN_Argv
It is located in ESPEasyRules.cpp

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests