Calculate : unknown token ---- integer conversion
Moderators: grovkillen, Stuntteam, TD-er
Calculate : unknown token ---- integer conversion
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
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
You can store it in a variable and then access that variable via [int#N] where N is the variable number.
Like this:
Like this:
Code: Select all
let,1,[Power#W]
Publish domoticz/in, '{"idx":1010, "svalue":[int#1]}'
Re: Calculate : unknown token ---- integer conversion
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]
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
Don't try to use strings in ESPEasy rules calculations (comparisons are also calculated), that won't work.
/Ton (PayPal.me)
Re: Calculate : unknown token ---- integer conversion
TD-er, indeed. Quotes are required.
Publish domoticz/in, '{"idx":1010, "svalue":"[int#1]"}'
Thanks!
Bart
Publish domoticz/in, '{"idx":1010, "svalue":"[int#1]"}'
Thanks!
Bart
Re: Calculate : unknown token ---- integer conversion
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
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
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.
Your use of '1500' in that comparison is causing the "calculate : unknown token" error message.
/Ton (PayPal.me)
Re: Calculate : unknown token ---- integer conversion
Ath,
So if I understand you well this is expected to be OK?
But it throws same "calculate : unknown token" error
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
Re: Calculate : unknown token ---- integer conversion
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".
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
And of course... the good old "oops missed that one too"
Re: Calculate : unknown token ---- integer conversion
Jep, sometimes all this syntax stuff gets confusing..
Re: Calculate : unknown token ---- integer conversion
@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?
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
You might want to have a look at these operators first: https://espeasy.readthedocs.io/en/lates ... y-function
/Ton (PayPal.me)
Re: Calculate : unknown token ---- integer conversion
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests