How to send a push confirmation from homeyscript

Hi all,

I’m trying to get a push confirmation working from HomeyScript.
The script does not return an error… I use it in Adv.Flow card “And - homeyscript run script”
Sending a push message works fine, but the confirm version does not work yet.
Any thoughts?

// send push confirmation to user
Homey.flow.runFlowCardAction({
        uri: 'homey:manager:mobile',
        id: 'push_confirm',
        args: {
			    user: {
			    athomId:  'myAthomIDhere'
		    	},
		    text: 'Test push confirmation test-push_confirmation.js'
        },
      });
  return(true);

.
This script works OK:


// send push msg to user
Homey.flow.runFlowCardAction({
        uri: 'homey:manager:mobile',
        id: 'push_text',
        args: {
			    user: {
			    athomId: 'myAthomIDhere'
		    	},
		    text: 'Test push notification test_pushmessage.js'
        },
      });

(Note: The AthomID of users can be found by running
Homey.users.getUsers();
in web-api playground)

1 Like

The push confirmation isn’t an action card (THEN column) but a condition card (AND column), not sure that is possible.

You need to add await before Homey.flow.runFlowCardAction. The script is erroring after it is done executing so your wont be able to see the error.

Thanks Jeroen, tried earlier and got the error as well.
But, nów I suddenly get the “action” part, thanx Caseda.
While that card is a condition card, the “run flowcard” has to be the condition type as well :crazy_face:

Very nice, this works now:

const response = await Homey.flow.runFlowCardCondition({
        uri: 'homey:manager:mobile',
        id: 'push_confirm',
        args: {
			    user: {
			    athomId: MyUserAthomID
		    	},
		    text: 'Test push confirmation from HomeyScript, now choose Yes to confirm; for No, just ignore this:'
        },
      });
  log (response);    
  return(true);

.
A follow up question:
Replying the pushmessage with either yes or no, results in yes and the flow continues. Is that as designed?
Because, when the message is sent, and I don’t respond to the question, the flow stops.
So now we have a “Should I do action A, press Yes; if not, don’t respond” option.
I was expecting a
-Yes: do this
-No: do nothing, or do something else

This post helps me, but can you send also a image from the gallery? The card exist in the flowmanager but need this in a homey script.

Run the example flowcard list, and in the returned data, search for the app id of the app you use. It will show all app’s flowcards you can use in HS.

You can find the app id in the app’s appstore URL. It is the reversed ‘url’ right after /app/
For instance, this is the app id for the Homeyscript app

You can also find it here, https://tools.developer.homey.app/tools/devices when you search for a device of your app in question

Thanks, I know now the syntax, the id of the card is push_image, I believe that I need the image token. So I tried to get the token with the command bellow

const myImage = await Homey.images.getImage({id:‘enter_my_image_id’})

But get the error about missing scope and no access error message.

My script looks like

Homey.flow.runFlowCardAction({
        uri: 'homey:manager:mobile',
        id: 'push_image',
        args: 
        {
			    user: 
            {
			        athomId: 'my user id'
		    	  },
		      text: 'Test push notification'
        },
        droptoken: 
        {
          image: 'id of my images'
        }

the script runs but no notifictions received, when i change the type to push_text I get the notification on my mobile. Does some if it is possible to use the push_image from script and how it needs to setup?

You can send it in a flow right?
And you can start a flow from HS.

Yes that works fine, I want to speed things up. My flow runs a script, I set some variabel and based on that the flow send the push notification. The flow runs every 5 seconds, I can see that the flow will take some while waiting for the script finished. I think on this moment I cannot be done, no big deal. But if someone knows how please let me know.

Well, all flowcards can be simulated through HS. Am sure of that.
But, im not sure you can get the image (ID) that you need.
Im willing to take a look tomorrow or at least this week.

The WebApi/developer page shows all images, so there is some way of getting the image (id) (which you will need for the card or you would need have access to a real/binary file in HS?).

Hi Peter, Don’t know if you found out, but the reason that it always results in Yes is that you have a return(true) as the last line. If you use return(response.result) instead then you will get a Yes or No.

Found this topic because i can’t find an option within Homey to send a push message to te last person leaving the house. I am using smartPresence and within the flow i get the username. So, i thought to solve it by modifying this script.

But, i never came that far, because the script isn’t sending a push message at all. With the standard action flowcard i can send push messages. So pushmessages is working. I tried it by just running the script as a test and by using a actionflowcard with running this script. I also entered my athomID.

Maybe i’m on the wrong track.

Without the await, i don’t get an errormessage. By the way i’m using a Homey '23

1 Like

I had a work around.

Step 1:
Make a flow with a notification to your phone.

Step 2: go to Homey Developer Tools
And log in.

Step 3: type: Homey.flow.getFlows();

Step 4: search the flow with search function of your browser.

Step 5: extract the “Actions” everything you will need is in that field.

Step 6 :use await Homey.flow.runFlowCardAction()

await Homey.flow.runFlowCardAction({
 uri: "homey:manager:mobile",
  id: "push_text",
  args: {
      user: {
        name: '<name>',
        id: '<ID>,
        image: '<info of image>',
        athomId: '<Athomid>'
      },
      text: '<Text or variable here>'
      }
});

If you use a function, don’t use await.
use the ’ ’ and not the " ".

Good luck.

Greetings

Do you know how i set this up in a normal advanced flow? (dutch) I have adding questionmark and ‘verzoek’ at the beginnen of the pushmessage, but i can’t get the question when recieving the notification?

Normal advanced flow

for a standard flow or for an advanced flow?
I’ll show both.

Standard flow:
With the code below, you can save it as script, and run the script as AND condition, just like you would do with the normal Push confirmation flow card

Screenshot from 2024-06-02 19-36-29


Code:

// push confirmation
// to retreive the user ID and Athom ID, open this site
// https://tools.developer.homey.app/tools/api-playground
// and run the line:
// Homey.users.getUserMe();

const response = await Homey.flow.runFlowCardCondition({
        uri: 'homey:manager:mobile',
        id: 'homey:manager:mobile:push_confirm',
        args: {
			    user: {
			    athomId: 'your_athomid_here',
                id: 'your_id_here'
		    	},
		    text: 'Test push confirmation from HomeyScript, now choose Yes to confirm; for No, just ignore this:'
        },
      });
  log (response);    
  return(true);



Advanced flow:
You can use the Homeyscript AND card “Run code”, and paste the code above in that card

Screenshot from 2024-06-02 19-27-12

This is an example of what the webapi playground returns:

1 Like

Thank you, i’m new with the scripting, but i will take look for it :+1:
I normally only use the standard cards in the homey web portal

1 Like