Page 1 of 1

Calculate: Unknown token input: error

Posted: 02 May 2021, 18:56
by Micha_he
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!

Re: Calculate: Unknown token input: error

Posted: 02 May 2021, 20:45
by TD-er
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

Re: Calculate: Unknown token input: error

Posted: 02 May 2021, 21:32
by Micha_he
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.

Re: Calculate: Unknown token input: error

Posted: 02 May 2021, 21:55
by TD-er
Does the event have an eventvalue?

Re: Calculate: Unknown token input: error

Posted: 02 May 2021, 22:10
by Micha_he
If the error ocourred, no !

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

Re: Calculate: Unknown token input: error

Posted: 06 May 2021, 17:45
by Micha_he
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?

Re: Calculate: Unknown token input: error

Posted: 06 May 2021, 21:19
by TD-er
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?

Re: Calculate: Unknown token input: error

Posted: 07 May 2021, 08:15
by Micha_he
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.

Re: Calculate: Unknown token input: error

Posted: 07 May 2021, 10:39
by TD-er
Yep, it should indeed have an "unset" value.

Re: Calculate: Unknown token input: error

Posted: 10 May 2021, 11:32
by Micha_he
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:

Re: Calculate: Unknown token input: error

Posted: 10 May 2021, 11:55
by TD-er
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