iMessage Plugin  

Developer: Glenn's Plugins     Like this plugin? Show your appreciation!
Category: Notification & Messaging
Github: Github Repo
Assistance: Get help!   
Plugin ID: com.GlennNZ.indigoplugin.iMessage
Latest release: v0.1.4 released on Nov. 12, 2018
Requires: Indigo v7.0.2 or higher
(Check the Releases tab below for older releases that may have different requirements)
  Download latest release

Indigo iMessage Plugin

What it can do:

  • Parse and send iMessages from within Indigo
  • Send Animated GIFs/pdf files etc from within Indigo
  • 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
  • Indigo 7.2
  • Need to be signed into Messages/iMsg on Indigo Mac with ideally separate indigo account
  • Will very likely need to give Indigo and IndigoPluginHost.app and IndigoServer.app Full Disk Access in the Security and Privacy settings

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

See here:

https://www.macworld.com/article/3311982/macs/the-difference-between-accessibility-and-full-disk-access.html

Installation

  • Download latest release and enable
  • Go to plugin Config screen to set allowed Buddies...

  • If hard to find out Buddy Handle (sometimes email, sometimes phone) enable Config checkbox 'Show Buddy Handle in Log'. Send indigo Mac and iMsg if all is functioning correctly, the Plugin will highlight for you the correct Buddy Handle to use in the Plugin Config and the send iMessage boxes as required.

  • Any issues turn debug logging on and check 3 checkboxes - should supply useful information (including Buddy Handles as sometimes email sometimes phone numbers.)

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

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

Example Commands (any 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

  • 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. 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.

``` 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 ``` 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 ")
```

Release details
Released on: Nov. 12, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.1.4

0.1.4

Bug fix of hidden Buddy List

Release details
Released on: Nov. 7, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.1.3

0.1.3

Add debugexceptions option - to also show exception message if errors Some log changing Add menu item - Log Status - to show plugin status in case of error

0.1.2

Add PluginStore Update Checking (via github) Enable UpdateChecking code Add Catch for Full Disk Access issues with error message directing to RTM :)

Release details
Released on: Nov. 6, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.1.1

Changes 0.1.1

  • Add Action to send msg and File combined (as requested)
  • Auto hide Buddy Handle field if using 'use last buddy'
  • Bug fix for resetting last command - wasn't correctly resetting last command after 120seconds
  • Typo fix

Changes 0.1.0

  • Major change to parsing of received messages - better support for multiple incoming messages from multiple buddies at same time. (Multiples streams of conversation)
  • Correctly ignores duplicate messages
  • Multiple messaging buddies occuring at same time dealt with correctly
  • Confirmation Question replies Y/N etc. can occur after other messages sent, provided within timeout set eg. after question received, can send other iMsg commands, get more information before replying Yes/No equivalent

  • If same message from same buddy sent within 120 seconds also ignored

  • Ignores everything except last message within 5 seconds - if wrong resend quickly and will act on that most recent message
  • As requested Buddies selectable as list following entering into pluginConfig allowed Bud
Release details
Released on: Nov. 5, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.1.0

Changes: - Major change to parsing of received messages - better support for multiple incoming messages from multiple buddies at same time. (Multiples streams of conversation) - Correctly ignores duplicate messages - Multiple messaging buddies occuring at same time dealt with correctly - Confirmation Question replies Y/N etc. can occur after other messages sent, provided within timeout set eg. after question received, can send other iMsg commands, get more information before replying Yes/No equivalent

  • If same message from same buddy sent within 120 seconds also ignored
  • Ignores everything except last message within 5 seconds - if wrong resend quickly and will act on that most recent message
  • As requested Buddies selectable as list following entering into pluginConfig allowed Bud
Release details
Released on: Nov. 1, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.0.6

Changes:

  • 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 - as below:

  • 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.
Release details
Released on: Nov. 1, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

Release 0.0.5

Changes:

Politer error reporting if buddy information or file information is incorrect.

Release details
Released on: Oct. 31, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

What it can do:

  • Parse and send iMessages from within Indigo
  • Send Animated GIFs/pdf files etc from within Indigo
  • 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
  • Indigo 7.2
  • Need to be signed into Messages/iMsg on Indigo Mac with ideally separate indigo account
  • Will very likely need to give Indigo and IndigoPluginHost.app and IndigoServer.app Full Disk Access in the Security and Privacy settings

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

See here:

https://www.macworld.com/article/3311982/macs/the-difference-between-accessibility-and-full-disk-access.html

Installation

  • Download latest release and enable
  • Go to plugin Config screen to set allowed Buddies...
  • Any issues turn debug logging on and check 3 checkboxes - should supply useful information (including Buddy Handles as sometimes email sometimes phone numbers.)

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

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

Example Commands (any 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

  • 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. 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.

``` 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 ``` 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 ")
```

Release details
Released on: Oct. 29, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin 0.0.2

Action added - ask imsg Question.

Select - BuddyHandle or last Buddy Message/Question to Send Timeout for reply in seconds Action Group to run if confirmed Confirmation Message to send if confirmed/when AG run

Only one question, per buddy at a time [can have multiple buddy questions though]

If no confirmation from Buddy other messages will continue to be parsed.

eg.

Can ask question "Shall I turn all lights off?" Timeout for 5 minutes Buddy - can send other commands - Gate etc. which are run If No/Yes/Y/N/Nope/Yeah/ye send (anycase) will terminate that current Question for that Buddy

Release details
Released on: Oct. 28, 2018
Requires: Indigo v7.0.2+
Changes in this release

Indigo iMessage Plugin

0.0.1 Beta

Parse and send iMsg Works with Mojave Beta currently Will need to change System Permissions to access imsg database file

Basics:

Mojave tested Indigo 7.2 Signed into iMsg with ideally separate indigo account Will very likely need to give Indigo and IndigoPluginHost.app and IndigoServer.app Full Disk Access in the Security and Privacy settings (sorry - don't believe any way around this)

So far

Connects to chat.db via sql and parse messages received Checks every few seconds - so far no problems in my testing Need to set allowed Buddies in Plugin Config No devices needed.

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 recognisation Felt best to use Indigo itself for actions with Triggers

Create Separate Triggers for iMsg Plugin for each command want recognised

Edit the Command Received Then can create any indigo action passed on the command recevied. eg. All off Gate Open Lock House Alarm on

Two current actions

Send Imsg and send iMsgFile

Allow to send imsg text to any buddy you know Tick box - to send reply to last buddy received message from enabling ongoing discussion Allows variable and device state substitution

send iMsgFile - sends file/image/animated gif to buddy (again has tickbox for last buddy)

todo

  • Have some logic triggers Yes / No and returns a condition response - enabling you to ask questions 'Do you want the Gate opened?' etc and waits for affirmative before triggering. Still thinking this through