Calculate : unknown token ---- integer conversion

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Calculate : unknown token ---- integer conversion

#1 Post by BartSr » 23 Oct 2023, 17:52

Problem:

Power-indicator in Domoticz shows sometimes very, very high value (peak)
Somewhere I read this may be caused by not publishing an integer value
I tried to do a rule like this but logfile shows: calculate : unknown token

logEntry shows [Power#W] = 26

if [Power#W] < '1500' then
Publish domoticz/in, '{"idx":1010, "svalue":[Power#W]}'
endif

But in fact the problem might be solved by converting [Power#W] into an integer.
In digged into the docs but couldnot find a conversion function e.g. INT([Power#W]). Does such exists?

What might be a solution?

Bart

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

Re: Calculate : unknown token ---- integer conversion

#2 Post by TD-er » 23 Oct 2023, 18:15

You can store it in a variable and then access that variable via [int#N] where N is the variable number.

Like this:

Code: Select all

let,1,[Power#W]
Publish domoticz/in, '{"idx":1010, "svalue":[int#1]}'

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

Re: Calculate : unknown token ---- integer conversion

#3 Post by TD-er » 23 Oct 2023, 18:18

By the way, not sure if Domoticz expects quotes around the "svalue" element as the svalue is intendes as "string value".
So maybe you need to wrap "" around the [int#1]

Code: Select all

Publish domoticz/in, '{"idx":1010, "svalue":"[int#1]"}'

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

Re: Calculate : unknown token ---- integer conversion

#4 Post by Ath » 23 Oct 2023, 19:47

BartSr wrote: 23 Oct 2023, 17:52 Problem:
...
if [Power#W] < '1500' then
Don't try to use strings in ESPEasy rules calculations (comparisons are also calculated), that won't work.
/Ton (PayPal.me)

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Calculate : unknown token ---- integer conversion

#5 Post by BartSr » 23 Oct 2023, 19:57

TD-er, indeed. Quotes are required.

Publish domoticz/in, '{"idx":1010, "svalue":"[int#1]"}'
Thanks!

Bart

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Calculate : unknown token ---- integer conversion

#6 Post by BartSr » 23 Oct 2023, 20:00

Ath,

As log showed value 26 I did not realize this might be a string-value.
But if I want to do calculation within rules, can I convert [Power#W] into numeric?

-Bart

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

Re: Calculate : unknown token ---- integer conversion

#7 Post by Ath » 23 Oct 2023, 20:13

ESPEasy always uses numeric values internally, the concept of strings is only used for (log) messages, displays and sending url's to external systems, etc. You can't assign/store a string value in an internal variable (yet).

Your use of '1500' in that comparison is causing the "calculate : unknown token" error message.
/Ton (PayPal.me)

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Calculate : unknown token ---- integer conversion

#8 Post by BartSr » 23 Oct 2023, 20:53

Ath,

So if I understand you well this is expected to be OK?

Code: Select all

if [Power#W] < 1500 then
Publish domoticz/in, '{"idx":1010, "svalue":"[Power#W]"}'
endif
But it throws same "calculate : unknown token" error


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

Re: Calculate : unknown token ---- integer conversion

#10 Post by TD-er » 23 Oct 2023, 20:57

What is the value of [Power#W] ?
Maybe you should log this first to see whether it is a numerical value or something like "NaN".

Code: Select all

logentry,"Checking Power#W : [Power#W]"

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

Re: Calculate : unknown token ---- integer conversion

#11 Post by TD-er » 23 Oct 2023, 20:57

chromo23 wrote: 23 Oct 2023, 20:56 get rid of the "then" :D
And of course... the good old "oops missed that one too" ;)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Calculate : unknown token ---- integer conversion

#12 Post by chromo23 » 23 Oct 2023, 21:01

TD-er wrote: 23 Oct 2023, 20:57 And of course... the good old "oops missed that one too"
Jep, sometimes all this syntax stuff gets confusing..

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Calculate : unknown token ---- integer conversion

#13 Post by BartSr » 23 Oct 2023, 21:10

@chromo23
sure, that's it... (mixed up Domoticz dzVent syntax)

@ TD-er and/or Ath
for this case not important but if I want to calculate with e.g. temperatures :is there a way to check a value not being NaN or should I just set the option of error value to -127 and checking for == not -127 first?

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

Re: Calculate : unknown token ---- integer conversion

#14 Post by Ath » 23 Oct 2023, 21:17

You might want to have a look at these operators first: https://espeasy.readthedocs.io/en/lates ... y-function
/Ton (PayPal.me)

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Calculate : unknown token ---- integer conversion

#15 Post by BartSr » 23 Oct 2023, 23:23

Ath, sure I didnot use the correct syntax for the 'equals, not equals, greater then etc'. But most important is how to validate the sensor data.

Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests