Multiline text in control pages - Solution!

Posted on
Tue Sep 19, 2017 9:00 am
aderrington offline
Posts: 97
Joined: Feb 03, 2015

Multiline text in control pages - Solution!

Hi,
So i've been wondering how to take a string (from Weather underground - Detailed forecast) and split it onto 2 lines for use in a control page.

i've had a friend work on something this morning that works really well, so thought i'd share it with you all.
I've created 2 variables that the control page reads the data from.
And also set up a trigger that performs this Python script whenever change is detected on the detailed forecast state.

The devices ID and Variable IDs will need to be changed to your specific IDs.
Also the character limit would also need to change depending on text size and label size.

Hope it's of some use to you guys!

Andrew

Code: Select all
weatherstring = indigo.devices[266180261].states["foreText1"]
CharacterLimit = 73
def splitlines(weatherstring):
    lines= []
    remainingtext = str(weatherstring)
    def sliceofffirstline(remainingtext):
        chunk = str(remainingtext[:CharacterLimit])
        lastspaceindex = chunk.rfind(' ')
        line = str(remainingtext[:lastspaceindex])
        remainingtext = remainingtext[lastspaceindex:]
        return remainingtext, line
   
    while True :
        if len(remainingtext) > CharacterLimit:
            remainingtext, slice = sliceofffirstline(remainingtext)
            lines.append(str(slice).strip())
        if len(remainingtext) <= CharacterLimit:
            remainingtext.strip()
            lines.append(str(remainingtext).
            strip())
            return lines
            break

lines = splitlines(weatherstring)
if len(lines)==1:
   indigo.variable.updateValue(1812552637,lines[0])
   indigo.variable.updateValue(753872597,"")
else:
   indigo.variable.updateValue(1812552637,lines[0])
   indigo.variable.updateValue(753872597,lines[1])

Posted on
Tue Sep 19, 2017 11:15 am
Different Computers offline
User avatar
Posts: 1269
Joined: Jan 02, 2016
Location: East Coast

Re: Multiline text in control pages - Solution!

Not only does this take care of a wish of mine for a year or more, it's specifically using exactly the plugin I need to make the fix work in! Thanks very much.

Refugee from SmartThings and so happy to be on Indigo now.
Sierra on an i5 running Harmony Hub, Hue, Security Camera, DomoPad, EPS Device Extensions EPS Smart Dimmer, MatplotLib, Plex, Scale Adapters, uniFiAP, Wunderground.

Posted on
Wed Sep 20, 2017 4:34 am
DaveL17 offline
User avatar
Posts: 3305
Joined: Aug 20, 2013

Re: Multiline text in control pages - Solution!

There are a couple other options for you to consider for multiline text.

The matplotlib plugin has a built-in device for plotting multiline text. It converts the text to an image that you can then link to in a control page. One way I use this device type is for plotting severe weather alerts that can sometimes be quite long.

Here is another thread which discusses other options. There are several options in the thread and you should read to the end as some of the scripts evolved over time.

Lastly, on my GitHub Homepage is a link to a script that generates animated GIFs for multiline text (displaying one line of text at a time) that's kind of visually interesting. I wouldn't recommend this one for long blocks of text but it would be workable for something like 3-5 lines.

My GitHub Homepage also has links to some other scripts that you might find helpful, too.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest