iMessage Indigo Plugin [New Plugin]

Posted on
Wed Oct 31, 2018 1:36 am
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

iMessage Indigo Plugin [New Plugin]

Indigo iMessage Plugin

Image

What it can do:

- Parse and send iMessages from within Indigo
- Send Animated GIFs/pdf files etc from within Indigo
- Ask a question via iMsg and then response/run actionGroup when confirmation received.
- Works with Mojave, untested on below versions - but shouldn't be issue
- Indigo 7.1 and above
- Beta currently

For Mojave will need to change System Permissions to access imsg database file

Basics

- Mojave tested, from 0.4.1 compatible with OSX Sierra and Below
- Indigo 7.2
- Need to be signed into Messages/iMsg app on Indigo Mac with ideally separate indigo account, whatever account is signed in will be the one where the messages come from
- Will very likely need to give Indigo and IndigoPluginHost.app and IndigoServer.app Full Disk Access in the Security and Privacy settings

Image
/Library/Application Support/Perceptive Automation/Indigo 7 (or 7.2)
IndigoPluginHost.app
IndigoServer.app

Both located there to drag and drop into Security & Privacy Full Disk Access

(sorry - don't believe any way around this - and probably needed for other plugins)

See here:

https://www.macworld.com/article/331198 ... ccess.html


Installation

- Download latest release and enable

In Pluginstore:
http://www.indigodomo.com/pluginstore/195/



- Go to plugin Config screen to set allowed Buddies...

- If any issues working out what is the correct Buddy Handle (can be email or phone number and needs to be exact) Enable 'Show Buddy Handle in Log' and send the Indigo iMessage computer a message. This will highlight in error red in the log the correct Buddy Handle. This should be used for that buddy both in the allowed buddies screen and also when sending any iMessage/Question/File etc.

- Any further issues turn debug logging on and check 3 checkboxes - should supply useful information


Image

Works

- Connects to iMessage chat.db via sql and parse messages received via regular simple, read-only SQL command
- At first run will backup the iMsg database to Users/Documents file - just in case... (haven't had any issues)
- Checks every few seconds - so far no problems in my testing
- Need to set allowed Buddies in Plugin Config otherwise any received iMsg will be ignored
- No Indigo devices needed - works solely through triggers and action

Setup Commands Recognised

- Enables you to recognise any iMsg received from Buddy as something to act on
- No formatting of message
- Just simple whole text

Felt best to use Indigo itself for actions with Triggers being the message itself - means very familiar

Create Separate Indigo Triggers for iMsg Plugin for each command want recognised

Via individual Trigger for each iMessage text wish to action on

eg. this an Indigo Trigger
Image

Type of trigger is IMessage Plugin Event, Command Received

Edit the command Received, then standard indigo conditions and actions performed.

Then can create any indigo action passed on the command received, including a iMsg reply to confirm.

eg. One Indigo Action from same Trigger

Image


Example Commands (any recevied text you wish can be a trigger!)
- All off
- Gate Open
- Lock House
- Alarm on

Three current Plugin Actions

Send Imsg
- Allow to send imsg text to any buddy you know
- Tick box - to send reply to last buddy received message from enabling ongoing conversation
- Allows variable and device state substitution
- So can send message:
- 'Glenn is located %%d:1490780461:address%% and has about %%d:1490780461:homeTimeText%% to travel to get home'
& clever indigo will fill in the blanks

Send iMsgFile
- sends file/image/animated gif to buddy
(again has tickbox for last buddy)
- Allows sending Animated Gifs via BlueIris or other Security plugin.
- Just need path to file location,or %%v:112312%% Variable substition and save to path
- eg.
The BlueIris lastAnimGif path variable which is updated by BlueIris plugin when AnimatedGif created.


Ask iMsg Question

Image

- Sends a question to Buddy - waits the timeout period for a positive or negative response
- If timeout sends a timeout reply
- If confirmation received - then runs the specified action group

- Following are valid confirmation replies - anything else will be ignored, OR if matches trigger acted on whilst waiting.

valid = {"yes": True, "y": True, "ye": True, 'yeah':True, 'ok':True, "no": False, "n": False, 'nope':False, 'never':False}

Sorry only english currently - but easy to add as many confirmation 'Oui' 'Non' that anyone needs down the track.

- Also allows - for specified reply (%%V:112123%%) substitution allowed

Additional

Messages accept indigo substitution for both variables and devices.
- So can send message:
'Glenn is located %%d:1490780461:address%% and has about %%d:1490780461:homeTimeText%% to travel to get home'

- with Number referring to FindFriends Device:
Indigo will substitute both the address and the travel time in these places.



Python Script Control (if needed for full flexibility)

- Via a Python script you can access the Plugin actions to send and reply to Imsgs.
- So can via script create question and send via the following standard message.

Code: Select all
    imessageID = 'com.GlennNZ.indigoplugin.iMessage'

    imsgPlugin = indigo.server.getPlugin(imessageID)
    imsgPlugin.executeAction('sendQuestion', props={'message':'The question you wish to ask', 'buddyId':'example@email.com', 'lastBuddy':False, 'timeout':600,'confirmedimsg':'All done.','actiongroup':ActionGroupIDtoRunwhenConfirmed})
    return;

Props to send:
- message: the question to ask
- buddyId: the buddy handle
- lastBuddy: just the last buddy msg received from
- timeout : timeout in seconds
- confirmedimsg: message if confirmation is received
- actiongroup: the ID number of the action group to run if confirmed.

Here is an example script that list devices on (via allowed list, and notallowed list), saves this list to a variable and then sends message listing devices on, via the plugin waits for confirmation, before running the confirmation AG to turn off all listed in variable.


Code: Select all
on_name = []
on_id = []

def AskQuestionGlenn(question, AGtoRun, replyifsuccess) :
   
    imessageID = 'com.GlennNZ.indigoplugin.iMessage'
    imsgPlugin = indigo.server.getPlugin(imessageID)
    imsgPlugin.executeAction('sendQuestion', props={'message':question, 'buddyId':'example@.com', 'lastBuddy':False, 'timeout':600,'confirmedimsg':replyifsuccess,'actiongroup':AGtoRun})
    return;

def CheckModulesRunning() :
    acceptable_modules = ["Smart Switch (DSC24)","RGBW LED Bulb (ZW098)","Smart Energy Switch (DSC24-2E)","Dimmer Switch (FGD211)","Smart Energy Illuminator (DSC08101)",                     "Relay Power Switch","Smart Energy Switch (DSC06106)", "Double Relay Switch (FGS221)", "Hue Bulb (Original, Downlight, Spotlight, LightStrip Plus)" ]

    notallowedid = [1049034630, 879903489, 1732408457, 1618015973,1595081762,660021281,1509636685,90390894,1047676499,614856779,1373207126,1332040796,1797065670]

    dev_list = indigo.devices.iter()
    for x in dev_list:
        if hasattr(x, "displayStateValRaw") and x.displayStateValRaw not in ["off", 0] and x.model in acceptable_modules and x.id not in notallowedid :
            on_name.append(x.name)
            on_id.append(x.id)
    return;

CheckModulesRunning();

numberon = len(on_id)

if numberon == 0 :
    indigo.server.log("Checking Running devices - None found on.")

if numberon > 0 :
    indigo.server.log("Checking Running devices - Modules running - iMsg sent")
    Question = "Attention\n I have noticed that you are both away and \nThe following lights/devices are on \n"
    ListModules = " , ".join(on_name)
    idsoff = indigo.variables[1410863016] # "MsgOnDevices"
    indigo.variable.updateValue(idsoff, unicode(on_id))
    Statement = Question + ListModules + "\n Would you like me to turn them off?"
    AskQuestionGlenn(Statement, 95680424, "They have all been turned off");
   

and for completeness here is the Action Group that is called when above is run
Code: Select all
onid = indigo.variables[1410863016] # "MsgOnDevices"

onidstring = onid.value
onidstring = onidstring.replace("[","")
onidstring = onidstring.replace("]","")  # Covert indigo string variable back to list
onidstring = onidstring.replace(" ","")

if len(onidstring) > 1:
    onidlist = onidstring.split(",")
else:
    onidlist = onidstring


if len(onidlist) >= 1 :
    indigo.server.log("iMsg: Turning off All Devices ")
    indigo.server.log(unicode(onidstring))
    for i in range(len(onidlist)):
       indigo.device.turnOff(int(onidlist[i]))
elif len(onidlist) < 1 :
    indigo.server.log("iMsg: No Devices On ") 
Last edited by GlennNZ on Mon Jan 21, 2019 5:35 pm, edited 4 times in total.

Posted on
Wed Oct 31, 2018 9:55 am
roussell offline
User avatar
Posts: 1096
Joined: Aug 18, 2008
Location: Alabama

Re: iMessage Indigo Plugin [New Plugin]

Very nice! Can’t wait to try this, thanks!

Terry


Sent from my iPhone using Tapatalk

Posted on
Wed Oct 31, 2018 10:39 am
Different Computers offline
User avatar
Posts: 1894
Joined: Jan 02, 2016
Location: East Coast

Re: iMessage Indigo Plugin [New Plugin]

Very cool!

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Wed Oct 31, 2018 1:11 pm
matt (support) offline
Site Admin
User avatar
Posts: 19133
Joined: Jan 27, 2003
Location: Texas

Re: iMessage Indigo Plugin [New Plugin]

Cool – thanks for sharing it (and documenting how to use it)!

Image

Posted on
Wed Oct 31, 2018 2:37 pm
eme jota ce offline
Posts: 546
Joined: Jul 09, 2009
Location: SW Florida

Re: iMessage Indigo Plugin [New Plugin]

Great plugin. Thanks for the contribution.

Just installed using an iCloud account created just for the Indigo server. Am seeing some errors. Appears that Indigo is seeing the "status" message I send form personal account to Indigo iCloud account, but has an error replying.

{I removed my email and the iCloud ID from the messages, below, where it says {Removed}}

iMessage Plugin Error Exception in SendImsg
Traceback (most recent call last):
File "plugin.py", line 546, in sendiMsg
self.as_sendmessage(buddyHandle, theMessage)
File "plugin.py", line 251, in as_sendmessage
reply = my_ascript_from_string.run()
File "/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoPluginHost.app/Contents/Resources/PlugIns/applescript/__init__.py", line 90, in run
return self._unpackresult(*self._script.executeAndReturnError_(None))
File "/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoPluginHost.app/Contents/Resources/PlugIns/applescript/__init__.py", line 65, in _unpackresult
raise ScriptError(errorinfo)
ScriptError: Messages got an error: Can?t get buddy id "{removed}". (-1728) app=u'Messages' range=259-284

Posted on
Wed Oct 31, 2018 2:48 pm
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

iMessage Indigo Plugin [New Plugin]

eme jota ce wrote:
Great plugin. Thanks for the contribution.
Just installed using an iCloud account created just for the Indigo server. Am seeing some errors. Appears that Indigo is seeing the "status" message I send form personal account to Indigo iCloud account, but has an error replying.
{I removed my email and the iCloud ID from the messages, below, where it says {Removed}}


That’s no good. That seems to be an AppleScript error essentially something is wrong with the buddyId.

Would seem the buddy handle isn’t correct.

Set up a trigger for a command , turn debugging on, check the debug boxes and send your indigo MAC iMsg account a message. This will give you the correct, iMsg buddyhandle for that account.

[and I should add some error trapping, and a more sensible message for this]

Glenn

Posted on
Thu Nov 01, 2018 12:38 am
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: iMessage Indigo Plugin [New Plugin]

Release 0.0.6


Image


Change Log:

- Better reporting of errors if Buddy details incorrect or file information incorrect/less red!
- Add 'Show Buddy Handle in Log' Checkbox in Plugin Config Setting
- If any issues working out what is the correct Buddy Handle (can be email or phone number and needs to be exact) Enable 'Show Buddy Handle in Log' and send the Indigo iMessage computer a message. This will highlight in error red in the log the correct Buddy Handle. This should be used for that buddy both in the allowed buddies screen and also when sending any iMessage/Question/File etc.

Posted on
Thu Nov 01, 2018 8:16 am
eme jota ce offline
Posts: 546
Joined: Jul 09, 2009
Location: SW Florida

Re: iMessage Indigo Plugin [New Plugin]

GlennNZ wrote:
eme jota ce wrote:
Great plugin. Thanks for the contribution.
Just installed using an iCloud account created just for the Indigo server. Am seeing some errors. Appears that Indigo is seeing the "status" message I send form personal account to Indigo iCloud account, but has an error replying.
{I removed my email and the iCloud ID from the messages, below, where it says {Removed}}


...
Set up a trigger for a command , turn debugging on, check the debug boxes and send your indigo MAC iMsg account a message. This will give you the correct, iMsg buddyhandle for that account.

...

Glenn


Followed your instructions. Also removed a second buddy from the configuration buddy list.. Plugin is working great. No errors.

Posted on
Thu Nov 01, 2018 11:30 am
petematheson offline
Posts: 734
Joined: Sep 14, 2014
Location: Southampton, UK

Re: iMessage Indigo Plugin [New Plugin]

Is it possible to send to a group iMessage with this?

Posted on
Thu Nov 01, 2018 2:17 pm
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: iMessage Indigo Plugin [New Plugin]

petematheson wrote:
Is it possible to send to a group iMessage with this?


No not possible.

Except to say can send x3 actions iMsg to x3 recipients - just won’t be a combined group chat.

Group chats in iMsg can only be referred to with a chatID which is a long list of numbers. Buddy Handles, group chat names won’t work.
The chatID doesn’t seem to exist until a group message is received. Whilst I could grab the chatID from database for an exisiting group message to potentially send messages to..
1. would need a bit of refactoring,
2. Probably of limited value as presume starting a group chat preferred.

Glenn

Posted on
Thu Nov 01, 2018 2:19 pm
petematheson offline
Posts: 734
Joined: Sep 14, 2014
Location: Southampton, UK

iMessage Indigo Plugin [New Plugin]

Existing group chat would be great if possible.
At the moment I send a tonne of alerts to both me and my wife in separate messages.
A group chat could mean a single message, plus we could reply back / chat about cctv images, alarm warnings etc ! :)


Sent from my iPhone using Tapatalk

Posted on
Thu Nov 01, 2018 2:29 pm
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: iMessage Indigo Plugin [New Plugin]

Maybe possible; and will have a look would involve adding chatID to everything.

Other issue of three/four way chat will be Plugin will parse any of the chat for actionable messages. Regardless of whom the message is directed at Plugin will review and if matches any action triggers run that group.
Depending on how complicated triggers are, and may not be ideal -
Eg.
Wife: Did I leave the oven on?
Indigo: turning on oven.
Etc.etc.

Posted on
Thu Nov 01, 2018 2:31 pm
petematheson offline
Posts: 734
Joined: Sep 14, 2014
Location: Southampton, UK

Re: iMessage Indigo Plugin [New Plugin]

Ooh there’s an idea! I could disarm my alarm and turn off the siren via text!

Please make it so captain

- long running issue with my house, presence detection and a cleaner. :)


Sent from my iPhone using Tapatalk

Posted on
Thu Nov 01, 2018 3:09 pm
GlennNZ offline
Posts: 587
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: iMessage Indigo Plugin [New Plugin]

petematheson wrote:
Ooh there’s an idea! I could disarm my alarm and turn off the siren via text!

Please make it so captain
- long running issue with my house, presence detection and a cleaner. :)
Sent from my iPhone using Tapatalk


The plugin does that currently without problem - just not from group chat.

Could also set up plugin based iMsg question asking “I notice you are all away and have not armed alarm. Would you like me to do so?” Or Equivalent - needs input to do so, so on odd occasional previously mentioned cleaner there doesn’t set alarm off!

Obviously many ways to communicate back to Indigo with fantastic HomeKit plugin coming to mind.

I do find as simple as text messaging is - it has a higher acceptance factor for those Luddites within the household. Happy to text commands, less happy to ask Siri same ones ....
And benefit is can ask question and need to confirm, rather than just schedule turn off, arm etc - to catch odd occasion that on holiday or cleaner etc..

Glenn



Sent from my iPhone using Tapatalk

Posted on
Sat Nov 03, 2018 2:02 pm
petematheson offline
Posts: 734
Joined: Sep 14, 2014
Location: Southampton, UK

Re: iMessage Indigo Plugin [New Plugin]

Thanks for this - Have installed tonight and had a bit of a play.

Unless I'm missing something, this seems a more complicated version of the Messages plugin that already exists, albeit hasn't been updated in 3 years.

I can create devices for each Buddy, and I can pick which buddy to send/receive from in an action.
I've entered the Buddy numbers in the plugin config, but after which - why do I need to re-enter these buddy numbers in each action?

Things that would be on my want list :)
    Create Device for each Buddy - So you don't have to type the number manually each time
    Create Device for each Group Text - To text groups of people :)
    Send combined Text & Image in single action - Use this to send 'Motion detected on Driveway & Send Image

Who is online

Users browsing this forum: No registered users and 0 guests