Page 1 of 1

Display string values as floats

Posted: 28 Dec 2020, 13:53
by BertB
Hi,
I have a P1 gatway that sends information to Domoticz to a device I named Energy.
I created also a node red script that is subscribed to domoticz/out. It receives the packages from Energy, but te data I need is in svalue format

"Battery: 255
RSSI: 12
description: ""
dtype: "P1 Smart Meter"
hwid: "84"
id: "1"
idx: 651
name: "Energy"
nvalue: 0
stype: "Energy"
svalue1: "1970425"
svalue2: "1212286"
svalue3: "555504"
svalue4: "1361336"
svalue5: "411"
svalue6: "0"
unit: 1

I would like to sum svalue1 and svalue2 with 3 decimals and display it on a Oled display.
I want to do the same with svalue3 and svalue4. So I need to convert the values to floats, I think.

To test the setup I have a MQTT import device, that actually gets data and a OLED device that displays it. But the normal formula's do not work here.

How can I format the data as described above?

Re: Display string values as floats

Posted: 28 Dec 2020, 13:56
by TD-er
See this part of the docs: https://espeasy.readthedocs.io/en/lates ... red-values
Does that help?

Re: Display string values as floats

Posted: 28 Dec 2020, 19:54
by BertB
This is very helpful, but I am not there yet.
The values I obtain with MQTT device, are the svalue bits in the JSON string.
The come like 1234567, but I want to show them as 1234.567.
I cannot simply divide, because the values are in string format.

On the other hand, I would like to sum two values. For that, I need them in a float format as well.

Re: Display string values as floats

Posted: 28 Dec 2020, 21:01
by Ath
In the Rules engine of ESPEasy, you can just use these values as if they where floats ;)

Re: Display string values as floats

Posted: 28 Dec 2020, 21:59
by TD-er
Doesn't the import plugin trigger events which you can act on in the rules?

Re: Display string values as floats

Posted: 29 Dec 2020, 10:48
by Ath
It does, but in the current version only when there is a numeric value found (must be convertable to float or else it will be discarded, and no event generated)