2 pages of information

I created a custom local application the reports the temp and humidity of sensors around my house. Anytime temp or humidity changes I push a new image to the Tydbyte. The problem is I can only fit r lines of information and wondered if there was a way to pause like 5 seconds and then display a second page of info without having to create and push a second image to the Tydbyte?

Here’s the image and code Im using…

Processing: 1000018281.webp…

load(“http.star”, “http”)
load(“time.star”, “time”)
load(“render.star”, “render”)
load(“math.star”,“math”)

Hue Outdoor Motion Sensor - Driveway (Outside)

OutsideURL = “http://192.168.86.25/apps/api/615/devices/411?access_token=e2c0b8b2-6102-409b-a164-7d8ab4772b1b

Ecobee Remote Sensor (Master Bedroom)

UpstairsURL = “http://192.168.86.25/apps/api/615/devices/396?access_token=e2c0b8b2-6102-409b-a164-7d8ab4772b1b

Ecobee Thermostat (Main Floor)

MainURL = “http://192.168.86.25/apps/api/615/devices/395?access_token=e2c0b8b2-6102-409b-a164-7d8ab4772b1b

SO Temp & Humidity Sensor #1 (Guest Room)

BasementURL = “http://192.168.86.25/apps/api/615/devices/1075?access_token=e2c0b8b2-6102-409b-a164-7d8ab4772b1b

Outside Weather Humidity Reported by Ecobee Thermostate

EBSuiteOutHumURL = “http://192.168.86.25/apps/api/615/devices/1068?access_token=e2c0b8b2-6102-409b-a164-7d8ab4772b1b

Helper Function

Iterate through attribues array for a name value equal to a specified string

def get_attribute_value(attributes, attribute_name):
# For all objects in array
for attribute in attributes:
# Check if name value matches one specified
if attribute[“name”] == attribute_name:
# If found, return the value inside of “currentValue” object
return attribute[“currentValue”]
# If not found, return null
return None

Main Function

Script for using api calls to gather sensor data for display

def main():
# *********************************************************************************** #
# OUTSIDE URL #

repout = http.get(OutsideURL)
attributes = repout.json()["attributes"]

# Specify the attribute name to search for
attribute_name = "temperature"

# Get the value of the specified attribute
value = int(get_attribute_value(attributes, attribute_name))

# Check if the value was found
if value != None:
    outside_temp = str(value)
else:
    outside_temp = "N/A"  # or handle the case when the attribute is not found

# *********************************************************************************** #
#                                    Upstairs URL                                     #

repup = http.get(UpstairsURL)
attributes = repup.json()["attributes"]

# Specify the attribute name to search for
attribute_name = "temperature"

# Get the value of the specified attribute
value = int(get_attribute_value(attributes, attribute_name))

# Check if the value was found
if value != None:
    upstairs_temp = str(value)
else:
    upstairs_temp = "N/A"  # or handle the case when the attribute is not found

# *********************************************************************************** #
#                                       Main URL                                      #

repmain = http.get(MainURL)
attributes = repmain.json()["attributes"]

# Specify the attribute name to search for
attribute1_name = "temperature"
attribute2_name = "humidity"

# Get the value of the specified attribute
value1 = int(get_attribute_value(attributes, attribute1_name))
value2 = int(get_attribute_value(attributes, attribute2_name))

# Check if the value1 was found
if value1 != None:
    main_temp = str(value1)
else:
    main_temp = "N/A"  # or handle the case when the attribute is not found
# Check if the value2 was found
if value2 != None:
    main_hum = str(value2)
else:
    main_hum = "N/A"  # or handle the case when the attribute is not found

# *********************************************************************************** #
#                                    Basement URL                                     #

repbase = http.get(BasementURL)
attributes = repbase.json()["attributes"]

# Specify the attribute name to search for
attribute1_name = "temperature"
attribute2_name = "humidity"

# Get the value of the specified attribute
value1 = int(get_attribute_value(attributes, attribute1_name))
value2 = int(get_attribute_value(attributes, attribute2_name))

# Check if the value1 was found
if value1 != None:
    basement_temp = str(value1)
else:
    basement_temp = "N/A"  # or handle the case when the attribute is not found
# Check if the value2 was found
if value2 != None:
    basement_hum = str(value2)
else:
    basement_hum = "N/A"  # or handle the case when the attribute is not found

# *********************************************************************************** #
#                                 EBSuiteOutHum URL                                   #

repEB = http.get(EBSuiteOutHumURL)
attributes = repEB.json()["attributes"]

# Specify the attribute name to search for
attribute_name = "weatherHumidity"

# Get the value of the specified attribute
value = int(get_attribute_value(attributes, attribute_name))

# Check if the value was found
if value != None:
    outside_hum = str(value)
else:
    outside_hum = "N/A"  # or handle the case when the attribute is not found


# *********************************************************************************** #

return render.Root(
    child=render.Stack(
        children=[
            render.Column(
                children=[
                    render.Text(
                        content = outside_temp + " Outside " + outside_hum + "%",
                        color="#FFFF14",
                    ),
                    render.Text(
                        content = upstairs_temp + " Master ",
                        color="#FF240C",
                    ),
                    render.Text(
                        content = main_temp + " Main " + main_hum + "%",
                        color="#41eb12",
                    ),
                    render.Text(
                        content = basement_temp + " Guest " + basement_hum + "%",
                        color="#15C0FF",
                    ),
                ]
            ),
        ]
    )
)

Yes, you can!

If you check my Product Hunt app, I display 3 screens for almost 5 seconds each:

The trick is to create an animation.Transformation to hold the widgets for each screen where the only important thing is the duration attribute, you’ll see that the keyframes array is empty. And finally you use render.Sequence passing an array with these transformations.

return render.Root(
    delay = 100,
    child = render.Column(
        children = [
            render_header(),
            render.Box(height = 1, width = 64, color = "#fdf0ee"),
            render.Sequence(
                children = frames, # frames is an array with 3 transformation objects
            ),
        ],
    ),
)

You will find other approaches if you look at other community apps, but this one has served me well.

1 Like

Thx for the quick response! Will give that a try.

Mark

1 Like