Display string values as floats

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Display string values as floats

#1 Post by BertB » 28 Dec 2020, 13:53

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?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Display string values as floats

#2 Post by TD-er » 28 Dec 2020, 13:56

See this part of the docs: https://espeasy.readthedocs.io/en/lates ... red-values
Does that help?

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Display string values as floats

#3 Post by BertB » 28 Dec 2020, 19:54

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.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Display string values as floats

#4 Post by Ath » 28 Dec 2020, 21:01

In the Rules engine of ESPEasy, you can just use these values as if they where floats ;)
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Display string values as floats

#5 Post by TD-er » 28 Dec 2020, 21:59

Doesn't the import plugin trigger events which you can act on in the rules?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Display string values as floats

#6 Post by Ath » 29 Dec 2020, 10:48

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)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 28 guests