Page 1 of 1
Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 17:52
by BartSr
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
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 18:15
by TD-er
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]}'
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 18:18
by TD-er
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]"}'
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 19:47
by Ath
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.
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 19:57
by BartSr
TD-er, indeed. Quotes are required.
Publish domoticz/in, '{"idx":1010, "svalue":"[int#1]"}'
Thanks!
Bart
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:00
by BartSr
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
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:13
by Ath
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.
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:53
by BartSr
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
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:56
by chromo23
get rid of the "then"
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:57
by TD-er
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]"
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 20:57
by TD-er
chromo23 wrote: ↑23 Oct 2023, 20:56
get rid of the "then"
And of course... the good old "oops missed that one too"
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 21:01
by chromo23
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..
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 21:10
by BartSr
@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?
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 21:17
by Ath
You might want to have a look at these operators first:
https://espeasy.readthedocs.io/en/lates ... y-function
Re: Calculate : unknown token ---- integer conversion
Posted: 23 Oct 2023, 23:23
by BartSr
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.