Multiline text in control pages - Solution!

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

Multiline text in control pages - Solution!

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!


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)
        if len(remainingtext) <= CharacterLimit:
            return lines

lines = splitlines(weatherstring)
if len(lines)==1:

Posted on
Tue Sep 19, 2017 11:15 am
Different Computers offline
User avatar
Posts: 1803
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.

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Wed Sep 20, 2017 4:34 am
DaveL17 offline
User avatar
Posts: 4080
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.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: Google [Bot] and 1 guest