Can I skip Flow and just use HomeyScript?

Must be the most common newbie question… but is there any way I can skip the Scratch-like Flows and just do everything in HomeyScript? I can’t find events in HomeyScript, but I might have missed something?

Thanks for the welcome! Regarding you pointing me to the “Welcome to the forum!” post - did you mean that I had missed something? I tried looking in the forum and in the knowledgebase, but I couldn’t find anything related. I’m sorry if I did something inappropriate.

Was just thinking of this myself… I belive you would need some flow cards, like the when cards.. and setting some variables.. but then i would assume you can do the rest in homeyscript?.. i do not know this for sure

How would you go about doing this?

I’ve played around quite a bit more, and from a programmers perspective, Homey has quite a bad solution. Flow looks nice, but the solution is messy as soon as I want to do something more advanced.
And HomeyScript really lacks some features, most noticeably:

  • set functions. Functions to do actions with Homey devices. Turn on a light etc.
  • events. To trigger a HomeyScript function when something happens with a Homey device.
  • classes, import, require - generally split functionality into multiple files or modules.
  • type safety

So, what I have to do now is to have a trigger in Flow (“When”), then start a HomeyScript (limited to one file, with no reusability), in the HomeyScript set tags, return back to the Flow and based on the tags have a bunch of Logic Flow cards, and do some actions (or use json instead of tags).
Everything is quite error prone, and a PAIN to debug.

Oh well, I guess it could be worse…

What are you trying to achieve that you think it is better in Homey Script?

Oh, I just want to make automation simpler. What I did yesterday was to write an automation that based on:

  • the hour of day,
  • the car’s state of charge,
  • the price per hour for electricity (which I can get as an array with the price for the upcoming 24 hours)
    come up with an automation that charges my car without my entire home going over a certain amount of used electricity per hour.
    So as the starting condition I just made sure Flow called the HomeyScript every minut, and then the HomeyScript did the calculation resulting in different tags. After that I returned to Flow and had to create a bunch of Logic Flow cards to determine what to do (like start the car charging, change the car charging power).

But it would have taken half the time if I could have stayed in HomeyScript. Not to mention if I had had a better IDE and had some lint to help out…

?
It’s in the examples

Did struggle a bit myself playing around, but when finding the device ID of the devices etc it got much easier.. try the script below, just change the device to whatever you want id from

/*
 * For each device, print its name, ID, and available device-specific action ("Then") cards
 * (cards with id format homey:device:<device-id>:<action>)
 */

const devices = await Homey.devices.getDevices();
const actionCards = await Homey.flow.getFlowCardActions();

for (const device of Object.values(devices)) {
  if (!device.capabilitiesObj) continue;
  if (device.class === 'light') {
    log(`\n=== ${device.name} ===`);
    log(`ID: ${device.id}`);

    // Print capabilities
    for (const capability of Object.values(device.capabilitiesObj)) {
      log(`${capability.title}: ${capability.value}`);
    }

    // List device-specific Then-cards
    log('Device-specific Then-cards:');
    let found = false;
    const prefix = `homey:device:${device.id}:`;

    for (const card of Object.values(actionCards)) {
      if (card.id && card.id.startsWith(prefix)) {
        found = true;
        log(`- ${card.titleFormatted || card.title} (card id: ${card.id})`);
        // Show argument names and types for usage
        if (card.args && card.args.length > 0) {
          let argList = card.args.map(a => `${a.name} [${a.type}]`).join(', ');
          log(`  Args: ${argList}`);
        } else {
          log('  Args: (none)');
        }
      }
    }
    if (!found) log('- (No device-specific action cards found for this device)');
    log('------------------------------');
  }
}

and from this i made a simple test script:

// Data Light device-specific IDs:
const offCardId = "homey:device:bd7719c5-32b9-4066-a419-832beb887c9b:off";
const onCardId  = "homey:device:bd7719c5-32b9-4066-a419-832beb887c9b:on";

// Turn off
await Homey.flow.runFlowCardAction({
  id: offCardId,
  args: {}
});
log('Light turned OFF. Waiting 10 seconds...');

// Wait 10 seconds (10,000 ms)
await wait(10000);

// Turn on
await Homey.flow.runFlowCardAction({
  id: onCardId,
  args: {}
});
log('Light turned ON again.');


The you are probably better out with somthing like HA.

But I think you shouldn’t need to check every minute.
Then it probably is easier to create a advanced flow but that probably isn’t as much fun for you.

I didn’t read a requirement why it could not in an advanced flow.

I think everything can be done in an advanced flow, since it’s possible to have code directly in the Flow. It’s just a matter of how complex it becomes, or how easy/hard it is to work with. Right now the logic is in a HomeScript of 230 lines.
Right now I have an advanced flow. I think that’s needed since the HomeyScript outputs some tags that I need the Flow to deal with (one tag if I should start/stop charing, one tag for which current to set, etc.)
You might be right that I don’t need to check every minute - the logic for me is projecting the power usage for an hour, with the possibility of altering the charging current of the car. And making sure I stay under a certain limit. So I constantly want to adjust the power usage, and the more often I do it, the less I have to adjust and the faster I can adapt to other things happening (like me turning on the oven).

Oh, you might be on to something here! So you mean I can trigger a Flow card from within HomeyScript?!

The issue for me is that many devices don’t have set methods in HomeyScript. Take Tesla App for Homey | Homey which has a ton of Flow cards. But it only has a handful of capabilities in HomeyScript.

But if what you’re saying is right, then I can call the Flow cards directly in HomeyScript, and then I only need to have a simple flow to trigger/start my HomeyScript.

I’ll have to try that out later today! Thanks! :slight_smile:

It seems strange to spend €400 on a device without wanting to use the one feature that might justify that price: (advanced) flows. For half the price you can buy/build a Home Assistant-based device that is more capable, supports more devices, provides logging/debugging, isn’t a black box, and supports creating all your automations programmatically if you prefer.

1 Like

Oh yes you can trigger THEN cards from withing homeyscript, you can also use AND cards.. and probably play around with logic cards etc.. i have not dug into all details yet..

The capabilities should be listed with the device ID, so i would asume your Tesla app has lots of different device ID’s to be discovered from all its device classes…