Multiline text in control pages - Solution!

Posted on
Tue Sep 19, 2017 9:00 am
aderrington offline
Posts: 116
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: 2533
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. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Sep 20, 2017 4:34 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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: No registered users and 5 guests

cron