I use the ‘Wasmachine’ flow to be noticed when the washingmachine has finished.
As an addition i also calcultate the costs of the power used.
With mathjs i round this calculation to 2 digits behind the separator.
Sometimes the calculation gives 20 cents. This is noted as € 0,2 in the message i send to myself.
Just for cosmetic reasons: Is there a way to format this into € 0,20 (2 digits so with the 0 added) in mathjs ? (number to string)
Like something as: usedpower$ = format$(number, € ##,00)
(In case of notation ‘fixed’, precision defines the number of significant digits after the decimal point)
So, with this Logics card ‘calc a value’, I want to accomplish 100 to be shown as 100.0 like this, but I get NaN values returned.
Thanks Robert. I realized this and changed the var name a few times.
First I used a / sign and before that a . sign. Will now try without special characters.
Is there a way to get the output to exclude the " "
I am wanting to turn a number (23) into 23.0 but the results outputs as “23.0” and the web command then fails.
It seems that the flow cards are adding these (possibly because they are using some sort of JSON formatting). I don’t know if there’s a way of removing them.
This is a follow-up to the thread Formatting number to 2 digits; just cosmetics , I have a similar requirement I would like to implement. I have a number variable with multiple digits that I want to assign to a string variable with control of the format. In Perl (yes, old guy here…), this would look like this:
my $fEnergyDiff=1.23456789;
my $strEnergyDiff=sprintf(“%.2f”,$fEnergyDiff);
printf “diff=$strEnergyDiff\n”;
This would produce the string “diff=1.23”. If I can do this in a Homey flow, I can use the string variable (strEnergyDiff) everywhere I need it, for example in log entries or in push messages.
When I run this, I get this in the Timeline: “fEnergyDiff=1.23456789, strEnergyDiff=1.23456789" (from step #3), as expected.
So, is it possible to do some clever JS stuff in step #2 so that the string variable will be assigned 1.23 and I get “fEnergyDiff=1.23456789, strEnergyDiff=1.23" in the Timeline? I did try some of the suggestions in the linked thread, but got nowhere.
When I run this, card #2 does the rounding and card #4 produces the correct 2-decimal numbers in the Timeline. Since Num already has 2-decimals (due to the round function), I don’t really need the Str variable (card #3).
I found during this testing that card #1 doesn’t work, the setting of this variable is ignored, the calculation in card #2 uses the value I set in the web interface instead (from the Variables button in the flow editor), card #1 is ignored. I am not sure why this happens - maybe somebody can explain it.
Anyway, thanks Adrian - your tip did the trick! /Erlend