Can someone with programming skills help me?

I am trying to display solar production and electricity consumption data on my Tidbyt. I am writing the data into a local data.json file at regular intervals. How can I now get some of this data pushed to the Tidbyt ? I am totally lost and maybe someone can help me based on the json file I already have ?

My Json file looks like this:

“currentBatteryChargeDischarge”: 0,
“currentPowerConsumption”: 457.73999786376953,
“currentPvGeneration”: 0

I am trying to render these three values onto my Tidbyt. I have installed Pixlet but for the life of me can not figure out how to use the starlark language to create the file which then needs to be served / pushed to the tidbyt using pixlet.

is the JSON file on your local computer or hosted on a web server somewhere, even if its locally?

Here is a basic star file that reads a json file via http and then displays a few values from that json file. This script output a webp file which you can then push to your tidbyt

load("", "render")
load("", "http")
load("encoding/", "base64")
load("", "cache")

url = ""

def fetch_data():  # fetch the data
    rep = http.get(url)
    if rep.status_code != 200:
        fail("request failed with status %d", rep.status_code)
    data = rep.json()["spots"][0]["stations"][0]["data_values"][0][2:7] # trim the data down to the small subset we need
    return data

def main():

    data = fetch_data()
    wind_avg = int(data[0]*0.87+0.5) # get avg and conver to into and kph

    wind_lull = 0 #int(data[1]*0.87+0.5)
    wind_gust = int(data[2]*0.87+0.5)
    wind_dir = data[4].strip('"')
    wind_dir_degrees = data[3]

    swell1 = "3.9f,13s,N352" # fake swell data
    color_light = "#00FFFF" #cyan
    color_medium = "#AAEEDD" #??
    color_strong = "#00FF00" #green
    color_beast = "#FF0000" # red
    wind_color = color_medium
    if (wind_avg < 10): # change color based on intensity
        wind_color = color_light
    elif (wind_avg < 25):
        wind_color = color_medium
    elif (wind_avg < 30):
        wind_color = color_strong
    elif (wind_avg >= 30):
        wind_color = color_beast

    return render.Root(
        child = render.Box(
                main_align = "center",
                children = [
                        content = "Windy-Tron",
                        font = "tb-8"

                        content = "%dg%d kts" % (wind_avg, wind_gust),
                        font = "6x13",
                        color = wind_color
#                     render.Text(
#                         content = "%s " % wind_dir,
#                     ),
                        content = "%s %d°" % (wind_dir,wind_dir_degrees),
                        color = "#FFAA00",




The file is sitting in my user folder /user/marcbaier

Thanks a lot! How do I set it so that the file is not taken from an URL but from my local user folder?

For that you need to pass the json data as a command line argument to pixlet like this :

./pixlet render data=$(cat data.json)

I’m not sure if that syntax will work exactly like that though. might need some extra quotes in there to make it work. Join the discord and we can help more : Tidbyt

I tried it with this simple script:

load(“”, “render”)
import json

def main():
with open("/users/marcbaier/data.json", “r”) as f:
contents = json.load(f)
return render.Root(
child = render.Text(str(contents[“currentPowerConsumption”]))

But i am getting an error back: error loading applet: failed to load applet: starlark.ExecFile: got illegal token, want primary expression

I don’t think starlark can open local files like python can.

I know it’s kind of a roundabout way to do but you can read the file in with a normal python script, then call the pixlet command from within python with the json object serialized and it works pretty good like this :

with open(alltime_json_filename, 'r') as f:
        alltime_leaderboard = json.load(f)
command = './pixlet render data=\'' + json.dumps(alltime_leaderboard)

Use Python it is very straight forward.


I still don’t get why there needs to be a programming language that can’t open files.