Trailing zero's (f.e. "2.10") in custom device

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
plugge

Trailing zero's (f.e. "2.10") in custom device

Post by plugge »

(Domoticz 2020.2, using dzVents)
For some reason virtual custom devices remove trailing decimal zero's, even when I feed it with

Code: Select all

mysensor.updateCustomSensor(string.format("%.2f", myvalue))

It does not matter whether myvalue is a number or a string.
Is this standard behavior from updateCustomSensor()?
I want the virtual custom device to represent a currency in visually pleasant way, f.e. "10.20" not "10.2".
Am I (absolute lua, Domoticz and dzVents beginner) doing something wrong?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trailing zero's (f.e. "2.10") in custom device

Post by waaren »

plugge wrote: Saturday 06 June 2020 2:43 For some reason virtual custom devices remove trailing decimal zero's, even when I feed it with a formatted string
Custom sensors convert strings to a number before storing them in the database and they are displayed on the GUI with a default number-format. If you feed it with a string of which the first none blank word cannot be converted to a number it will show 0.
Is this standard behavior from updateCustomSensor()?
Yes
I want the virtual custom device to represent a currency in visually pleasant way, f.e. "10.20" not "10.2".
You can use a virtual text sensor for that purpose. You have much more freedom on what can be displayed on such a device.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
plugge

Re: Trailing zero's (f.e. "2.10") in custom device

Post by plugge »

Thank you waaren! So, I can leave out the string formatting.
I wil stick to the custom sensor, because I prefer to have the log graph option with the data points.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest