Page 1 of 1

Map switch binary to String

Posted: 06 Feb 2019, 04:43
by trumee
Hello,

I have a switch which produces a value 0 and 1. How can I convert these to 'OFF' and 'ON' strings to display them in OLED?

Does ESPEasy support strings?

Thanks

Re: Map switch binary to String

Posted: 06 Feb 2019, 05:34
by grovkillen
Values can not be strings but using rules you can interpret any value and output ita string to your OLED.

Re: Map switch binary to String

Posted: 06 Feb 2019, 12:16
by Plumifrons
Any hint or example, as I'm having this problem as well (see viewtopic.php?f=2&t=6292... ?

Re: Map switch binary to String

Posted: 06 Feb 2019, 20:40
by Domosapiens
Found in my notes:
From here https://github.com/letscontrolit/ESPEas ... -383228300
for the Wiki:
Format Transformation:
Feature to transform Values from numeric to strings or to format numeric values.

Syntax:
[task#value#transformation#justification]

Where #transformation is:
Format of PIN states of GPIO (0 or 1)
#V: value unformatted
#O: 1/0 -> ON/OFF
#C: 1/0 -> OPEN/CLOSE
#U: 1/0 -> UP/DOWN
#u: 1/0 -> U/D
#Y: 1/0 -> YES/NO
#y: 1/0 -> Y/N
#I: 1/0 -> IN/OUT
#X: 1/0 -> X/O
#Z: 1/0 -> 1/0
Adding ! to any of the above formatting inverts the logic.
So for example:
#O! 1/0 -> OFF/ON
#Z! 1/0 -> 0/1
#Y! 1/0 -> NO/YES
Format of any number value (floats):
#Dx.y: x digits + y decimals
#E: convert to ceiling
#F: convert to floor
Examples (value = 3.1415):
#D -> 3
#D3 -> 003
#D.2 -> 3.14
#D3.2 -> 003.14
#E -> 4
#F -> 3
#R: justifies the latest value to the right according to the number of characters exported by the LCD (tested on LCD). Not tested on other displays.
Justification formats applis to the transformed value:
#Pn: prefix with padding spaces
#Sn suffix with padding spaces
Example (value = 1)
#U#S5 -> UP (+3 spaces)
#U#P5 -> (3 spaces) UP
New Transformations:
#H: Hot/Cold
#M: Man/Auto
#m: M/A
New Justifications:
#Lx: Left (x=number of chars)
#Rx: Right (x=number of chars)
#Ux.y: Substring (x=first char; y=number of chars)
Never tried it, please report back with working examples ;) ;)

Re: Map switch binary to String

Posted: 07 Feb 2019, 01:01
by trumee
Thanks the transformation worked for me and OLED does show the string. Would be great if you could add a transformation for Empty/Full.

Re: Map switch binary to String

Posted: 22 Feb 2019, 09:08
by Plumifrons
Yes, this did the trick.

I've send from my Pi a 0 (for not charging) or a 1 to a dummy task called "charging". In the settings of the oled I've used

Code: Select all

Charging:[charging#charging#Y]
And with the "#Y" the 0 or 1 of the value of the task is converted to "NO" or "YES".