@V1per You don’t need to search for the space, simply change the {1,2} to {1,3} then up to three digits are matched.
-
How cut a string and convert it to a number
-
Ok, but than I have a string "56 " if this is not a problem to convert it into a number this will work.
But I don’t now how to convert this into a number. I became no variable chown from this device in Pimatic.
-
@V1per I see. The error message is more or less a warning. The variable is evalated correctly and also can be used in numeric operation. Pimatic distinguish only between Expression variable and Value variable but internally checks if it is a number or a string.
Nevertheless this behaviour should be corrected by the developers.
-
@Heizelmann
Great, how you said, ignore the error message and it works.
Thank you!!! -
@mwittig
The device works now how expected but my log were spamed with hundreds off error messages:error [pimatic]: Got string value for attribute $FZ of VariablesDevice but attribute type is number
Can you please help me?
-
@V1per said in How cut a string and convert it to a number:
Can you please help me?
You should set the expression as part of the variables device! Don’t use a variable as this won’t get re-evaluated when the traffic value changes. If you still see the error try the following work-around:
max(0, subString("$traffic.traffic", "^\d\{1,2\}"))
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig said in How cut a string and convert it to a number:
max(0, subString("$traffic.traffic", "^\d\{1,2\}"))
This don`t work now it shows “Unkown”.
And I have allready set the expression “Number” in the variables device and this device throws out this error messages, but it works.
-
@mwittig
That is strange now it don’t work anymore… I have changed back to:subString("$traffic.traffic", "^\d\{1,3\}")
But now it says allways “Unknown” even after a restart of pimatic, what the hell is that?
-
For me it works with the workaround from @mwittig
max(0, subString("$traffic.traffic", "^\d\{1,3\}"))
The device looks like this ( @V1per maybe you check this)
{ "variables": [ { "name": "travelTimeMinutes", "expression": "max(0,subString(\"$traffic.traffic\", \"^\\d\\{1,3\\}\"))", "type": "number" } ], "xAttributeOptions": [], "id": "travelVariables", "name": "travelVariables", "class": "VariablesDevice" }
-
You are right the workaround works. I am on work, so I can only arrive pimatic with my phone. So I think I have set spaces " " after the end of the funktion and this was the reason why the “Unknown” appears.
Thanks a lot to you guys!