F1 race

I saw a video in which a lamp reacts to the live status of a yellow flag, safety car, or for example a red flag.

Below the video there was a link, which I will include below. In the link you can see that someone has created an F1 sensor for Home Assistant.

Does anyone know if this can be made for Homey Pro, and if so, how?

ChatGPT
Q: “Can this code be used as an inspiration to build a Homey app that features a device that can act as a representation of the flags in a race. Green all ok, Yellow or red for caution and a stopped session: GitHub - Nicxe/f1_sensor: A Home Assistant Custom Integration that provides information about the next Formula 1 race and the full season calendar including Live data like race flags and Race Control messages”

A: Yes — the code from F1 Sensor could definitely serve as inspiration for building a Homey app / integration that represents race-flags via a device (lights or indicators). Here’s how and what to watch out for (both pros and cons):


:white_check_mark: What works — why it’s a good base/inspiration

  • F1 Sensor already provides live data about the race: session state (practice / qualifying / race), track status (CLEAR, YELLOW, RED, etc.), safety-car, etc. (newreleases.io)
  • You could take those statuses and map them to a “virtual device” or actual light in Homey (e.g. green = all clear; yellow/red = caution/stop).
  • On Homey, custom devices are modeled with capabilities (e.g. on/off, color) and device classes (e.g. “light”) so a device controlling a colored light as flag-indicator fits naturally. (homey.app)
  • If you build a Homey driver or app that either fetches the same F1 feed (or indirectly via a service like F1 Sensor + a bridge) you can create flows that trigger color changes or other behaviors when flag status changes.

:warning: What needs extra work / limitations & what may not work out of the box

  • F1 Sensor is built for Home Assistant, not Homey. The integration uses Home Assistant APIs/events; it’s not designed as a generic “flag feed to device” abstraction. (nicxe.github.io)
  • You cannot directly use F1 Sensor inside Homey — you’d need to port the logic: either replicate how it fetches F1 data (API calls, parsing) or have Home Assistant + a bridge/pass-through (e.g. MQTT) to feed Homey. The F1 Sensor docs explicitly state that you can mirror its output to e.g. an ESPHome device — but not directly inside another platform. (nicxe.github.io)
  • On the Homey side you need to implement a custom “device driver/app” (or perhaps a “virtual device/app”) that listens for the data feed and then updates the device capabilities (e.g. change light color / on-off). That requires familiarity with Homey’s SDK, capabilities, device classes, flows, etc. (apps.developer.homey.app)
  • Latency / synchronization: live race data (like flag change) often comes via API with some delay. If you use a broadcast video, delays may accumulate — you’d need to handle that (maybe allow offset/delay config like F1 Sensor does). (newreleases.io)

:bullseye: What you should do to use it as real inspiration / starting point

  1. Review F1 Sensor’s source: especially how it fetches and exposes sensors like f1_track_status, f1_session_status, safety car, etc. It shows clearly which states exist. (GitHub)

  2. Decide how to get data into Homey:

    • Option A: Write a Homey app that itself fetches the race-status feed (likely the same API F1 Sensor uses) and exposes a virtual device with color-capable light class.
    • Option B: Run F1 Sensor in a Home Assistant instance + use a bridge (MQTT, HTTP, etc.) to send state updates to Homey.
  3. Define a Homey “device” with appropriate capabilities (e.g. on/off, color) so flows can act on it as a “flag-light”. (apps.developer.homey.app)

  4. In your Homey app, map the race states to the corresponding color or indicator.

  5. Handle edge cases (e.g. connectivity loss, delays, session transitions, fallback when no race, etc.).


:light_bulb: Conclusion — Balanced view

Using F1 Sensor as inspiration is feasible and might save time understanding what data is available and how race-states can be structured. But it’s not an easy plug-and-play: you’ll need to adapt or reimplement data fetching and build a proper Homey driver/app on top of it.

If you want — I can draft a rough high-level design outline for how a Homey app based on F1 Sensor could look (data flow, device definition, error handling).

Here’s a clean, direct high-level design outline for a Homey app that uses F1 race-data (inspired by F1 Sensor) to drive a “race flag” device.


Homey App Design — F1 Race Flag Device

1. Data Source

Replicate how F1 Sensor fetches data:

  • Poll the same API (the “unofficial F1 live timing” endpoints F1 Sensor uses).

  • Extract:

    • Track status (CLEAR / YELLOW / RED)
    • Session state (GREEN / STOPPED / FINISHED)
    • Safety-car / VSC
    • Race running vs not running

You do not need Home Assistant. Just implement the fetcher directly in the Homey app.


2. Device Type in Homey

Create a driver with one device class, e.g.:

Device class: light
Capabilities:

  • onoff
  • light_hue (color)
  • light_saturation
  • measure_string (optional text capability: “Track Status: YELLOW”)

This lets flows and dashboards treat it as a color indicator.


3. Mapping F1 States → Light Colors

Implement simple state-mapping:

  • Track CLEAR → Green
  • Track YELLOW → Yellow
  • Track RED → Red
  • Safety Car → Flashing yellow (or solid yellow if flashing is not practical)
  • Session STOPPED → Red
  • No race running → Light off

4. Flow Triggers

Provide triggers like:

  • “Track status changed”
  • “Session state changed”
  • “Race started / ended”

Useful for automations (e.g. replay lighting, TV actions).


5. Settings Page

Allow user to configure:

  • Refresh interval (e.g. 3–10 seconds)
  • Delay offset (to sync with TV stream)
  • Turn light off outside race weekend
  • Type of color mode (solid / animate)

6. Update Loop

Homey app cron task:

  1. Fetch F1 data
  2. Parse track state
  3. Compare with previous state
  4. Update device capabilities
  5. Trigger flows if changed

Keep it lightweight to avoid app suspension.


7. Error Handling

  • If API unavailable → set state to “UNKNOWN” (light off or white).
  • If session not active → device off.
  • If repeated failures → expose warning in the device (“data source offline”).

8. Optional Enhancements

  • Add capabilities for:

    • Current lap
    • Weather
    • Driver status (if desired)
  • Add multiple devices (e.g. one global flag, one per sector).


If you want, I can provide:

  • A Homey app skeleton (SDK v3) with the driver structure
  • Example code for the fetch loop
  • The capabilities.json and driver manifest
  • A color-mapping helper that fits Homey’s hue values

LOL, this is the code it provided, haven’t checked it, but I think this can work:

Probably need to create an app skeleton with homey compose first and start from there.

But first, start here: Getting Started | Homey Apps SDK

// Folder structure (all in one document for the skeleton)
//
// /app.json
// /drivers/f1-flag/device.js
// /drivers/f1-flag/driver.js
// /drivers/f1-flag/driver.compose.json
// /app.js
// /lib/api.js
//
// ------------------------------------------------------------
// app.json
// ------------------------------------------------------------
{
  "id": "com.example.f1flags",
  "name": {
    "en": "F1 Flags"
  },
  "version": "1.0.0",
  "compatibility": ">=12.0.0",
  "sdk": 3,
  "category": ["lights"],
  "permissions": [],
  "drivers": [
    {
      "id": "f1-flag",
      "name": { "en": "F1 Race Flag" }
    }
  ]
}

// ------------------------------------------------------------
// app.js
// ------------------------------------------------------------
'use strict';

const Homey = require('homey');

class F1FlagsApp extends Homey.App {
  async onInit() {
    this.log('F1 Flags app started');
  }
}

module.exports = F1FlagsApp;

// ------------------------------------------------------------
// drivers/f1-flag/driver.compose.json
// ------------------------------------------------------------
{
  "name": {
    "en": "F1 Flag Indicator"
  },
  "class": "light",
  "capabilities": [
    "onoff",
    "light_hue",
    "light_saturation",
    "measure_string"
  ],
  "pair": [
    {
      "id": "auto"
    }
  ]
}

// ------------------------------------------------------------
// drivers/f1-flag/driver.js
// ------------------------------------------------------------
'use strict';

const Homey = require('homey');

class F1FlagDriver extends Homey.Driver {
  async onInit() {
    this.log('F1 Flag driver init');
  }
}

module.exports = F1FlagDriver;

// ------------------------------------------------------------
// drivers/f1-flag/device.js
// ------------------------------------------------------------
'use strict';

const Homey = require('homey');
const F1Api = require('../../lib/api');

class F1FlagDevice extends Homey.Device {
  async onInit() {
    this.log('F1 Flag device ready');

    this.api = new F1Api();
    this.previousState = null;

    this.pollInterval = setInterval(() => this.updateState(), 5000);
  }

  async updateState() {
    try {
      const data = await this.api.getTrackStatus();
      if (!data) return;

      const flag = data.status; // CLEAR / YELLOW / RED

      if (flag !== this.previousState) {
        this.previousState = flag;
        await this.applyFlag(flag);
      }
    } catch (err) {
      this.log('Error updating state:', err);
    }
  }

  async applyFlag(flag) {
    // map flag → hue/saturation
    let hue = 0;
    let sat = 1;

    switch (flag) {
      case 'CLEAR': // green
        hue = 0.33;
        break;
      case 'YELLOW':
        hue = 0.15;
        break;
      case 'RED':
        hue = 0.0;
        break;
      default:
        await this.setCapabilityValue('onoff', false);
        return;
    }

    await this.setCapabilityValue('onoff', true);
    await this.setCapabilityValue('light_hue', hue);
    await this.setCapabilityValue('light_saturation', sat);
    await this.setCapabilityValue('measure_string', flag);
  }

  async onDeleted() {
    clearInterval(this.pollInterval);
  }
}

module.exports = F1FlagDevice;

// ------------------------------------------------------------
// lib/api.js
// ------------------------------------------------------------
'use strict';

const fetch = require('node-fetch');

class F1Api {
  async getTrackStatus() {
    // Replace this with actual F1 endpoint logic
    try {
      const res = await fetch('https://example.com/f1/status');
      if (!res.ok) return null;
      return await res.json();
    } catch (e) {
      return null;
    }
  }
}

module.exports = F1Api;

DaneeGPT? :winking_face_with_tongue::wink:

1 Like

Thank you for your very detailed response.

Unfortunately, this is beyond my understanding.

Well, to be honest, I just asked ChatGPT (which incidentally is down now :thinking::joy:) and that’s where the answer comes from.

Maybe someone here will pick it up and turn it into an actual app, who’s up for the challenge?

:face_with_peeking_eye:

2 Likes