Example: Send instant messages to iOS and Android devices with Logic Machine

Task

How to send instant messages, like alerts to the users phone or tablet? There are ready apps for iOS and Android pushover_logo_logicmachinedevices to handle this task.
For example, there is an app called Pushover, available for iOS, Android and desktop clients.
Before using the example below, please register on the Pushover website to get user ID and Application API Token and insert them into even-based script instead of userkey.

Add the following program in User Libraries

Source code    
  1. require 'ssl.https'
  2.  
  3. local pushover_url = 'https://api.pushover.net/1/messages.json'
  4. local token = 'PUT YOUR APPLICATION TOKEN HERE' -- Your application token, at least 1 app must be created at pushover.net to get the application token
  5. local user = 'PUT YOUR USER TOKEN HERE' -- Your user token, retrieve from settings inside pushover application for android or ios
  6.  
  7. function pushover(title, message, sound, priority, retry, expire)
  8. if priority < -2 then priority = -2 end
  9. if priority > 2 then priority = 2 end
  10. if retry < 30 then retry = 30 end
  11. if retry > 86400 then retry = 86400 end
  12. if expire < retry then expire = retry end
  13. if expire > 86400 then expire = 86400 end
  14. if priority == 2 then prioritystring = ''.. priority .. '&retry=' .. retry .. '&expire=' .. expire ..'' else prioritystring = priority end
  15. now = os.date('*t')
  16. timestamp = string.format('%02d', now.day) .. '-' .. string.format('%02d', now.month) .. '-' .. now.year .. ' ' .. string.format('%02d', now.hour) .. ':' .. string.format('%02d', now.min) .. ':' .. string.format('%02d', now.sec)
  17. local data_str = 'user=' .. user .. '&message=' .. message .. ' ' .. timestamp .. '&token=' .. token .. '&title=' .. title .. '&sound=' .. sound .. '&priority=' .. prioritystring .. ''
  18. local res, code, headers, status = ssl.https.request(pushover_url, data_str)
  19. end

Event-based script

Add the following script which will send pushover notification with sound

Source code    
  1. require("user.pushover")
  2. --Set title for message
  3. title = 'LogicMachine'
  4. --Set message to be send (current time and date will be added automaticly)
  5. message = 'Storing LBK1'
  6. --Set sound to be played on device
  7. --pushover(default), bike, bugle, cashregister, classical, cosmic, falling, gamelan, incoming, intermission, magic, mechanical, pianobar, siren, spacealarm, tugboat, alien, climb, persistent, echo, updown, none
  8. sound = 'updown'
  9. --Set priority (-2 = no notification only badge and message in app, -1 = notification without sound or vibration, 0 = default, 1 = bypass user quiet hours (set in App not iOS), 2 = bypass user quiet hours (set in App not iOS) + acknowledge required
  10. priority = 1
  11. --Seconds to retry when not acknowledged, minimum = 30 (only used with priority 2)
  12. retry = 30
  13. --Seconds to expire retry when not acknowledged, maximum = 86400 (24 hrs, only used with priority 2)
  14. expire = 3600
  15. --Activate Pushover with parameters above
  16. pushover(title, message, sound, priority, retry, expire)

 

Created by Erwin van der Zwart