Send instant messages to iOS and Android devices from WISER

Discussion in 'C-Bus Automation Controllers' started by lcrowhurst, May 10, 2020.

  1. lcrowhurst

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    271
    Likes Received:
    97
    Location:
    Sydney, NSW, Australia
    Example: Send instant messages to iOS and Android devices from Wiser event

    An app called Pushover, available for iOS, Android and desktop clients allows the sending of alerts from the Wiser.

    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.

    There is a free trial for 7 day, the a AU7.99 one off fee after that.



    Add the following program in User Libraries

    1. require 'ssl.https'
    2. local pushover_url = 'https://api.pushover.net/1/messages.json'
    3. 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
    4. local user = 'PUT YOUR USER TOKEN HERE' -- Your user token, retrieve from settings inside pushover application for android or ios
    5. function pushover(title, message, sound, priority, device, url, url_title, retry, expire)
    6. if priority < -2 then priority = -2 end
    7. if priority > 2 then priority = 2 end
    8. if retry < 30 then retry = 30 end
    9. if retry > 86400 then retry = 86400 end
    10. if expire < retry then expire = retry end
    11. if expire > 86400 then expire = 86400 end
    12. if priority == 2 then prioritystring = ''.. priority .. '&retry=' .. retry .. '&expire=' .. expire ..'' else prioritystring = priority end
    13. now = os.date('*t')
    14. 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)
    15. local data_str = 'user=' .. user .. '&message=' .. message .. ' ' .. timestamp .. '&token=' .. token .. '&title=' .. title .. '&sound=' .. sound .. '&device=' .. device .. '&url=' .. url .. '&url_title=' .. url_title .. '&priority=' .. prioritystring .. ''
    16. local res, code, headers, status = ssl.https.request(pushover_url, data_str)
    17. end


    Event-based script

    Add the following script which will send pushover notification with sound


    1. require("user.pushover")
    2. --Set title for message
    3. title = 'CTC WISER'
    4. --Set message to be send (current time and date will be added automaticly)
    5. message = 'A button has been presses'
    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 = 'persistent'
    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. --Set the device name to send the message directly to that device, rather than all of the devices (multiple devices may be separated by a comma)
    12. device = ''
    13. -- Set link to open wiser
    14. -- Use CTC-Wiser://page/pagenumber to set the page number to open
    15. url = 'CTC-Wiser://'
    16. -- Set Title of the link to open Wiser
    17. url_title = 'Open Wiser'
    18. --Seconds to retry when not acknowledged, minimum = 30 (only used with priority 2)
    19. retry = 30
    20. --Seconds to expire retry when not acknowledged, maximum = 86400 (24 hrs, only used with priority 2)
    21. expire = 3600
    22. --Activate Pushover with parameters above
    23. pushover(title, message, sound, priority, device, url, url_title, retry, expire)
     
    lcrowhurst, May 10, 2020
    #1
  2. lcrowhurst

    Rytech

    Joined:
    Sep 11, 2017
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    there is an error on line 13 in your code

    now = os.date('*t

    it should read now = os.date('*t')
     
    Rytech, May 11, 2020
    #2
  3. lcrowhurst

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    271
    Likes Received:
    97
    Location:
    Sydney, NSW, Australia
    Correct user library called called pushover :

    require 'ssl.https'

    local pushover_url = 'https://api.pushover.net/1/messages.json'
    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
    local user = 'PUT YOUR USER TOKEN HERE' -- Your user token, retrieve from settings inside pushover application for android or ios

    function pushover(title, message, sound, priority, device, url, url_title, retry, expire)
    if priority < -2 then priority = -2 end
    if priority > 2 then priority = 2 end
    if retry < 30 then retry = 30 end
    if retry > 86400 then retry = 86400 end
    if expire < retry then expire = retry end
    if expire > 86400 then expire = 86400 end
    if priority == 2 then prioritystring = ''.. priority .. '&retry=' .. retry .. '&expire=' .. expire ..'' else prioritystring = priority end
    now = os.date('*t')
    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)
    local data_str = 'user=' .. user .. '&message=' .. message .. ' ' .. timestamp .. '&token=' .. token .. '&title=' .. title .. '&sound=' .. sound .. '&device=' .. device .. '&url=' .. url .. '&url_title=' .. url_title .. '&priority=' .. prioritystring .. ''
    local res, code, headers, status = ssl.https.request(pushover_url, data_str)
    end
     
    lcrowhurst, May 11, 2020
    #3
  4. lcrowhurst

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    The forums screw up Lua code. Wrapping it in a CODE tag reduces the errors, but some still get through.

    Be nice if someone could fix this.
     
    Ashley, May 11, 2020
    #4
  5. lcrowhurst

    Rytech

    Joined:
    Sep 11, 2017
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney

    have you had any success with this ? I can't seem to get it to work
     
    Rytech, May 12, 2020
    #5
  6. lcrowhurst

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    it works for me
     
    Pie Boy, May 12, 2020
    #6
  7. lcrowhurst

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    271
    Likes Received:
    97
    Location:
    Sydney, NSW, Australia
    Are you getting any errors?
     
    lcrowhurst, May 13, 2020
    #7
  8. lcrowhurst

    Rytech

    Joined:
    Sep 11, 2017
    Messages:
    8
    Likes Received:
    0
    Location:
    Sydney
    no i am not receiving any errors what so ever, is there anything else that needs to be changed

    cheers
     
    Rytech, May 13, 2020
    #8
  9. lcrowhurst

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    271
    Likes Received:
    97
    Location:
    Sydney, NSW, Australia
    1)I created a user ID in Pushover
    2) added an application , I called it SHAC
    3) installed pushover app on iPhone and signed in and added iPhone as device
    4) added the first scripts to SHAC user lib - Call it pushover
    5) Pasted APPLICATION TOKEN & USER TOKEN from Pushover web into Shac Script
    6) added an event script and pasted second script
     
    lcrowhurst, May 14, 2020
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.