We have moved at community.getvera.com

Author Topic: convert character to word  (Read 304 times)

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
convert character to word
« on: December 06, 2017, 12:51:18 pm »
Hey guys...

I have a scene that tell us the weather in the morning.. but I need to deal with temperature under 0 ;)

Code: [Select]
local outsideTemp = luup.variable_get(TEMP_SID, "CurrentTemperature", 68)
my outsideTemp contain sometime something like "- 2" and I would need to convert the - to "moins" and convert + to ""

any idea....
« Last Edit: December 06, 2017, 12:53:37 pm by DesT »
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: convert character to word
« Reply #1 on: December 06, 2017, 01:30:34 pm »
This will do it...

Code: [Select]
local function translate (text)
    local lookup = {
        ["-"] = "moins ",
        ["+"] = " ",
    }
    return (text:gsub ("%W", lookup))
end

so that
Code: [Select]
print (translate "-42 +23")

gives you
Code: [Select]
moins 42  23
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: convert character to word
« Reply #2 on: December 06, 2017, 02:14:45 pm »
AK,

thanks... working fine ;)
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules