Skip to content

Instantly share code, notes, and snippets.

@sstratoti
Last active April 15, 2024 00:49
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sstratoti/8021c5a4ee8e34313c3f59ba20c4a83a to your computer and use it in GitHub Desktop.
Save sstratoti/8021c5a4ee8e34313c3f59ba20c4a83a to your computer and use it in GitHub Desktop.
iOS Subflow for HomeAssistant Companion notifications
@bonanitech
Copy link

Awesome! It may also be a good idea to scrub the flow with this tool before that. 😉

@sstratoti
Copy link
Author

sstratoti commented Nov 21, 2021

@bonanitech Just did a diff after using that tool, had no idea that the server ID was in there, but it makes sense that it would be. The HA nodes need to use something to connect...

Is there a way to set that dynamically with the subflow module? Or all you all just going in and changing the HA nodes to point at your own instances each time I update this?

EDIT: Or using the scrubber you linked to replace the id... hah

@sstratoti
Copy link
Author

And next week turned into next year...
Sorry, work/life has been kicking my ass. I'm planning some time off over the next month or two, so I'll see about publishing it then. :)

@bonanitech
Copy link

It looks like there is a problem with nodes that depend on configuration nodes in subflow modules. We'll have to wait for a fix first.

@sstratoti
Copy link
Author

You mean for the subflow module? Also, you reminded me. I updated the code with a bug fix. I'll push that up now.

@sstratoti
Copy link
Author

Allows you to pass in an msg.notificationOverride.url into the subflow.
I use this to send me an alert when a new version of HA is available, and dynamically send in the URL to the blog post. :)
I'm also doing the same for HACS updates, and I send the user to the /hacs page in the app so I can easily (and heedlessly) keep things on the bleeding edge.

@bonanitech
Copy link

You mean for the subflow module?

Yes, I built a subflow module last week, and I noticed the issue during my testings. After installing it on a different machine, it didn’t work as expected because the reference to the configuration node was not valid anymore. Unfortunately, there's currently no way to manage the link between nodes inside a subflow module and configuration nodes.

I reported this issue via Slack a few days ago, and there is a post about the same issue on the forum (link below).

https://discourse.nodered.org/t/packaging-a-subflow-as-a-module-missing-broker-configuration/55485

@henriklund
Copy link

Out of curiosity, is there a reason why this subflow is limited to four actions?

@sstratoti
Copy link
Author

Last time I checked the docs, an iOS notification was limited to 4 and Android was limited to 3. Has there been a change that I missed?

@sstratoti
Copy link
Author

Ah - interesting. Android is limited to 3, iOS says the following:
“ iOS allows around 10 actions. Any more and the system UI for actions begins having scrolling issues”
Aside from the flow’s form being monstrous? Hahaha

@henriklund
Copy link

henriklund commented Feb 12, 2022

Thought so. I tweaked the code to 8 actions and that worked like a charm, so just wondered... (I had one for volume +5, +1, -1, -5 and wanted add toggle for mute).
Do you want a copy of the modifications?

@okets
Copy link

okets commented Mar 9, 2022

Hello @sstratoti,
I really liked your subflow and used it to replace some existing flows.
When using your sub-flow, I had few options missing that I used in my existing flows, so I tweaked your flow a bit to support them.
I would like to share the modified flow with you so you can review the changes and incorporate them in your flow for others to use if you would like.

  1. First change I made, adding "No-sound" to the sounds list and changed "create service call" to send a silent message in such a case.
  2. I changed "isCritical" Boolean to a list with interruption levels support, now you can choose between [Critical/Time Sensitive/Passive/Normal] instead of the old way that only supported [Normal/critical], and again changed "create service call" node to support this.

You can find my sub-flow json in my fork:
https://gist.github.com/okets/c7baea968aab019a09c9d2c80df29d40

I only changed the [input] node and the [create service call] node, so it should be easy enough to merge the changes.
I also changed the "info" link in the documentation to direct to this discussion instead of the broken link that was there.

Thank you for sharing,
let me know if you find my changes helpful.

@sstratoti
Copy link
Author

This is great, thanks so much for this! I'm in training this week and next, so I don't think I'll be able to take a look right away at merging it in, but I'll put it on my todo list!

I wanted to ask everyone's opinion about something. I've included a LOT of configuration options in this subflow. I've tried to incorporate all of the options that were available at the time, but I feel like I'm not using most of them. What do people feel about a "lite" version of the subflow and a "max" version?

I wish I could expand/collapse menu options depending on selections, or even group menu options together - but I don't think this is possible in a subflow, is it?

@DeltaNu1142
Copy link

My $0.02 (which thanks to current events is worth less than $0.01) is, even if I don't use all of the config options, I still want to see them. It gives me ideas about how to use it that I probably wouldn't have otherwise.

I think your question will be better answered by someone that doesn't want to see unused config options, though... if that person exists!

@okets
Copy link

okets commented Mar 10, 2022

@sstratoti
You documented the sub-flow's inputs very well and most of the inputs are optional.
in fact, It works so well that I am using your sub-flow for sending non-actionable messages as well.
In my opinion a lite version is not necessary.

BTW,
I also implemented an option to get the phone that triggered the Action so I can reply back only to it instead to all devices.
I use it for sending confirmation messages back to whoever triggered the action and not to all users.
I do it by populating the "services" to the following:
var triggeringPhoneName = msg.eventData.event.sourceDeviceName.replace("-","_").replace(" ","_").replace("’","").toLowerCase(); msg.notificationOverride={'services': 'mobile_app_'+triggeringPhoneName};
Works like a charm!

@sstratoti
Copy link
Author

sstratoti commented Mar 11, 2022

@henriklund

Thought so. I tweaked the code to 8 actions and that worked like a charm, so just wondered... (I had one for volume +5, +1, -1, -5 and wanted add toggle for mute). Do you want a copy of the modifications?

Do you have a copy somewhere where I could grab it and review it? I think I've made a few more updates and I want to make sure I don't lose them. I think I may turn this into a github project so we can use pull requests and an issue tracker...

@Elodis
Copy link

Elodis commented Mar 12, 2022

Love this subflow - works amazingly well. Trying to review the documentation to make some tweaks on my setup but I'm getting a 404? Is there an alternate source?

Link I'm getting from subflow: https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/actionable-notifications-subflow-for-ios.html

@sstratoti
Copy link
Author

Yeah, I was planning on submitting it to the HA NodeRed cookbook but was beta testing it a bit first - so thats a dead link right now. One day!

This is the link to the documentation I'd originally set up:
https://gist.github.com/sstratoti/8021c5a4ee8e34313c3f59ba20c4a83a?permalink_comment_id=3741675#gistcomment-3741675

Check out this post to see what the options are for message overrides:
https://gist.github.com/sstratoti/8021c5a4ee8e34313c3f59ba20c4a83a?permalink_comment_id=3966887#gistcomment-3966887

Let me know if you have any questions about this - the documentation might be slightly out of date, but I'm here to help and answer questions. :)

@Automot360
Copy link

@sstratoti
I’ am using your Subflow since the beginning and works very well.
Dump question how to update my already in use Subflow without deleting the existing one?
Thanks for your work.

@sstratoti
Copy link
Author

@Automot360

You might want to make a backup before you do this. The instructions for replacing the subflow should work perfectly fine, but it never hurts to make a full backup just in case.

Backup:

  1. Open Node red - click on the hamburger menu at the top right
  2. Select Export
  3. Select "All Flows" at the top.
  4. Click the "Download" button.

If you need to restore from backup, following the instructions below should work the same, except instead of pasting in the javascript in step 7, choose the file you downloaded and import that - and replace everything.

Import Updated Flow:

  1. View the "raw" javascript above, and copy it all.
  2. Open Node red - click on the hamburger menu at the top right
  3. Paste it into the the "clipboard" text box. It might have a pink tint to it.
  4. click the import button
  5. It should present a menu that says "Some of the nodes you are importing already exist in your workspace."
  6. Click the "View Nodes" button.
  7. Make sure "Replace" to the right of the subflow is checked, and then click "import selected".

You should be all set!

@okets
Copy link

okets commented Mar 21, 2022

Hello @sstratoti,
I made some significant changes to your original sub-flow as I kept using it in more complex scenarios.
among the changes I made:

  1. Adding "No-sound" to the sounds list and changed "create service call" to send a silent message in such a case.
  2. Changed original "isCritical" Boolean to interruption levels list now you can choose between [Critical/Time Sensitive/Passive/Normal] instead of the old way that only supported [Normal/critical].
  3. Fixed multiple bugs around context storage, clearing messages and figuring out actions. now it can find the correct message when using tags in overrides, clears the correct messages etc.
  • the old code did not find the correct messages for actions if notificationOverride.tag was set.
  • the old code could only clear messages using the last service used, not the service used for the actual notification.
    ios notifications

You can find my updated sub-flow json in my fork:
https://gist.github.com/okets/c7baea968aab019a09c9d2c80df29d40

I will keep maintaining the link above as I make more changes or fixes.

@sstratoti
Copy link
Author

@okets and @henriklund - Thank you for your contributions to this code! I've mentioned this before - I really wanted to set up a github project for this so that we could all contribute code fixes and track issues.

I'm working on that now. I'm going to upload my latest code, and then grab the code from @okets gist and pull in your updates.

The repository will be found here: https://github.com/sstratoti/actionable-notifications-subflow-for-ios

I'm also updating the readme and am planning to add installation / update instructions.

@sstratoti
Copy link
Author

New repository is live!

@henriklund - would you like to be a contributor? Or could I take a peek at your changes to allow for +8 actions? It'll save me copy/paste time at least. :)

@sstratoti
Copy link
Author

I've added a wiki with details on installation, upgrading, and updated documentation. Please take a look and point out any spelling mistakes I've made. haha

@Automot360
Copy link

@sstratoti
Thank you!

@henriklund
Copy link

New repository is live!

@henriklund - would you like to be a contributor? Or could I take a peek at your changes to allow for +8 actions? It'll save me copy/paste time at least. :)

It is nothing fancy. Just repeat the properties for following until you reach action8Icon:

  • action4Title
  • action4ActivationMode
  • action4AuthenticationRequired
  • action4Destructive
  • action4Behavior
  • action4TextInputButtonTitle
  • action4TextInputPlaceHolder
  • action4Icon

In "Create service call" and "build message" change
[1,2,3,4]
to
[1,2,3,4,5,6,7,8]

@andystewart999
Copy link

You mean for the subflow module?

Yes, I built a subflow module last week, and I noticed the issue during my testings. After installing it on a different machine, it didn’t work as expected because the reference to the configuration node was not valid anymore. Unfortunately, there's currently no way to manage the link between nodes inside a subflow module and configuration nodes.

I reported this issue via Slack a few days ago, and there is a post about the same issue on the forum (link below).

https://discourse.nodered.org/t/packaging-a-subflow-as-a-module-missing-broker-configuration/55485

Hi - did the issue with configuration nodes ever get resolved, to your knowledge?

Cheers,
Andy

@bonanitech
Copy link

Hi - did the issue with configuration nodes ever get resolved, to your knowledge?

Some pull requests related to that were merged a couple of weeks ago. I haven't had the time to test if that fixed the issue.

@sstratoti
Copy link
Author

Have you tried the code in

https://github.com/sstratoti/actionable-notifications-subflow-for-ios

instead? I’ve made a few updates since this gist was created.

@andystewart999
Copy link

andystewart999 commented Apr 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment