Hue app via HomeyScript - individual device control working, but not setScene, groupOn, groupOff - hints & tips?

Hi all,

I am currently failing to make any hue scene changes through HomeyScript, and would very much appreciate any insights or pointers.
This is with the official Hue App for Homey, using Hue Bridge.

What works:

  • I can set scene from a normal (non-script) Flow + Philips Hue app
  • I can set individual lights on or off through HomeyScript + Philips Hue app
  • I can list the available scenes through HomeyScript by interrogating the FlowCards available through the Philips Hue app

What doesn’t work:

  • I can call the runFlowCardAction with what I believe should be the right information to setScene, and it doesn’t return any errors - but it doesn’t cause any change in the light setting.
  • After failing with setScene, I went back and tried groupOn/groupOff, but they didn’t work for me either (no error, but no action).

Again, controlling individual lights works fine (HomeyScript + Philips Hue official app), but not these wider hub controls (scenes & groups).

Is anyone able to help spot what I am (presumably) doing wrong? I haven’t found any discussion in the forum, and I assume that I can’t be the first to try this with the Homey Pro (early 2023), so I’d guess other people must have this working?

HomeyScript trial:

// HomeyScript using Philips Hue official app from Athom B.V
// Developed using versions:
// - Philips Hue app v5.9.1
// - Homey Web App version 1.9.57
// - Homey Pro (Early 2023), version 10.0.0-rc.122

// Status as of 8-July-2023:
// Not setting scene; everything before that works, but not the setScene
// runFlowActionCard doesn't return any errors, but the lights don't change state
// (can set scene via non-script flow, and even call that from HomeyScript, but not locally in script)
// why??

const flowcard_uri = 'homey:manager:flow';
const owner_name = 'Philips Hue';
const card_id = 'homey:app:nl.philips.hue:setScene';

// edit to match an available Hue scene, or empty string to list all available scenes
const scene_name = 'Front garden evening';
// const scene_name = '';

log('Philips Hue: Flow Card Actions:')
const actionCards = await Homey.flow.getFlowCardActions();
for( const card of actionCards ) {
  if( card.ownerName == owner_name ) {
    log(" ", card.id)
   }
}

for( const card of actionCards ) {
  if (card.id == card_id) {
    const options = await Homey.flow.getFlowCardAutocomplete({
      uri: flowcard_uri,
      id: card.id,
      name: 'scene',
      query: '',
      type: 'flowcardaction'
    })
    log('\n');
    log('Card properties for:', card_id);
    log(card)
    log('\n');
    log('Philips Hue: Scenes:');
    for( scene of options ) {
      if( !(scene_name.length) || (scene.name == scene_name) ) {
        log(scene.description, " : ", scene.name, "; scene id=", scene.id);
      }
    }
   }
}

log('\n');
if(!scene_name.length) {
  log('No scene name specified so skipping setScene step')
} else {
  log("runFlowCardAction: flowcard uri=", flowcard_uri, "; card id=", card_id, "; name=", `'${scene_name}'`);
  await Homey.flow.runFlowCardAction({
    uri: flowcard_uri,
    id: card_id,
    args: {
            name: `'${scene_name}'`,
            // type: 'autocomplete',
          }
  })
  .then(() => log('Scene set OK'))
  .catch(error => log(`Scene set Error:`, error));
}

(re-targeting & updating question after initially putting as reply to what looked like a related topic over on developers forum: Activate Hue scene with HomeyScript? - #5 by Colin_Osborne)

you are missing a lot of arguments in your action flow card (untested, but these should be the right arguments):

await Homey.flow.runFlowCardAction({
  uri: 'homey:app:nl.philips.hue',
  id: 'homey:app:nl.philips.hue:setScene',
  args: {
    scene: {
      bridge_id: [BRIDGE ID],
      description: 'Philips hue',
      id: [SCENE ID],
      name: [SCENE NAME],
    },
  },
});

Not sure about the “description” value, that might be the bridge’s name.

Meant to respond on your first post, but kind of forgot.

Oh goodness, yes, thank you! … that works

I had multiple mistakes and misunderstandings …

  • I hadn’t understood the structure, naming and therefore passing of the ‘scene’ within the args … scene: { … params …}.
  • I had skipped passing bridge_id … not thinking through what I was previously getting/doing courtesy of the Homey API/services, but that now I need to go via Philips Hue App for myself and out through the Hue Bridge.
  • And yes I was trying to control a scene by name, not by ID. I’m sure I had tried ID earlier in my battles, but lost that along the way while failing due to my other mistakes.

Having tried a few experiments, the essential requirements are the scene id and bridge_id. It is not necessary to give the description or scene name.

Here is an updated script, which shows the setScene action card structure, lists one or more of the scenes including scene id and bridge_id values, and if a specific scene was specified then it activates that scene.

// HomeyScript using Philips Hue official app from Athom B.V
// Developed using versions:
// - Philips Hue app v5.9.2
// - Homey Web App version 1.9.58
// - Homey Pro (Early 2023), version 10.0.0-rc.122

// Status as of 15-July-2023: working!
// Shows structure of Philips Hue app setScene action card
// Lists scenes (if given empty scene name), or shows & selects 1 specific scene by name
// Activates specific scene (if a specific scene name was given in the script)

const flowcard_uri = 'homey:manager:flow';
const owner_uri = 'homey:app:nl.philips.hue';
const card_id = 'homey:app:nl.philips.hue:setScene';
const card_arg_name = 'scene';

// edit to match an available Hue scene, or empty string to list all available scenes
const scene_name = 'Study';
// const scene_name = '';

var scene_id = null;
var bridge_id = null;

log('Get Philips Hue FlowCardActions');
const actionCards = await Homey.flow.getFlowCardActions();
for( const card of actionCards ) {
  if (card.id == card_id) {
    log('FlowCardActions for card id:', card_id);
    log(card);
  }
}

log ('\n');
log('Get Philips Hue app setScene parameters');
const options = await Homey.flow.getFlowCardAutocomplete({
  uri: flowcard_uri,
  id: card_id,
  name: card_arg_name,
  query: '',
  type: 'flowcardaction'
})
var found_scene = false
for( scene of options ) {
  if( !(scene_name.length) || (scene.name == scene_name) ) {
    log('setScene parameters for scene name: ', scene.name);
    log(scene);
    scene_id = scene.id;
    bridge_id = scene.bridge_id;
  }
  if ( scene_name.length && (scene.name == scene_name) ){
    found_scene = true;
  }
}

log('\n');
log('Setting scene (if specified & found)');
if (!found_scene){
  log('Did not find scene to activate');
} else {
  log('runFlowCardAction: uri=', owner_uri, '; id=', card_id, '; arg:', card_arg_name, '; bridge_id=', bridge_id, '; id=', scene_id);
  await Homey.flow.runFlowCardAction({
    uri: owner_uri,
    id: card_id,
    args: {
      scene: {
        bridge_id: bridge_id,
        id: scene_id,
      },
    },
  })
  .then(() => log('runFlowCardAction OK'))
  .catch(error => log(`runFlowCardAction Error:`, error));
}