Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


[TUTORIAL] Popup notifications and custom images


Sankotronic

Recommended Posts

  • Topic Author
  • 4 hours ago, andyhud said:

    Thanks @Sankotronic

     

    So if I want a notification for a "device" using this system (e.g is it on or off) do I create a scene first with an IF statement then add this code?

     

    Sorry, I'm still very new to Fibaro.. learning all the time!

     

    It really depends on what information you want to send, but in general yes, you first need to check status of the device with if / then and then you send notification. You don't need to apologise for your questions, just ask what you want to know!

     

    So, give me details what you want and I can then make example code.

    Link to comment
    Share on other sites

    Guest andyhud
    11 hours ago, Sankotronic said:

     

    It really depends on what information you want to send, but in general yes, you first need to check status of the device with if / then and then you send notification. You don't need to apologise for your questions, just ask what you want to know!

     

    So, give me details what you want and I can then make example code.

    Hi @Sankotronic

    Many thanks for your reply, really appreciate it

     

    I'm not trying to do anything "specific", but I was trying to understand how and where you put the code for these popup notifications. I know it sounds stupid, but you can't add the code on your phone, so it must be in a scene or VD on the HC2 correct? I just didnt know where to put the code on your first post!

     

    Or do I create a scene for example using graphical blocks, convert it to to a LUA scene then paste this code at the bottom?

     

    Many thanks again

     

    Andy

    Link to comment
    Share on other sites

  • Topic Author
  • Hi @andyhud,

     

    you can check how I used popup message code in some of my scenes posted here on forum:

    You can adapt above scenes for almost any other usage. You can make block scene and then convert it to LUA or you can take code like above scenes and then change it to suit your need.

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • Hello all,

     

    I have updated first post with new findings! Previous solution with copying icon link from local connection is then working only when mobile devices with Fibaro app are connected locally on home network. If you want to see icons on popup notifications also when you are connected remotely then please check first post.

     

    Enjoy! :-) 

    Link to comment
    Share on other sites

    • T.Konopka pinned this topic
    • 1 month later...

    I can not help myself to set the notification apart from the push to come to this code also as notifications on the control panel - anyone help?

     

    -- BIRTHDAY CALENDAR
    -- LUA script by marecki_0luk1
    -- version 1.0, 2014-07-11


    -- Configuration --
    -- 1) Put your deviceID into mDevices
    -- 2) Fill your birthday calendar
    -- 3) Change notification time
    -- 4) Change device icon



    local virtualId = fibaro:getSelfId();
    local mDevices = {}; -- put device ids here
    local today = "d"..tostring(os.date("%m%d"));
    local tomorrow = "d"..tostring(os.date("%m%d", os.time()+24*60*60));
    local next_day = os.time()+24*60*60;
    local notification_hour = "20"; -- time to notify user
    local note;
    local next_birthday;

    local birthday_calendar={
    d0101="",
    d0101="",
    d0102="",
    d0103="",
    d0104="",
    d0105="",
    d0106="",
    d0107="",
    d0108="",
    d0109="",
    d0110="",
    d0111="",
    d0112="",
    d0113="",
    d0114="",
    d0115="",
    d0116="",
    d0117="",
    d0118="",
    d0119="",
    d0120="",
    d0121="",
    d0122="",
    d0123="",
    d0124="",
    d0125="",
    d0126="",
    d0127="",
    d0128="",
    d0129="",
    d0130="",
    d0131="",
    d0201="",
    d0202="",
    d0203="",
    d0204="",
    d0205="",
    d0206="",
    d0207="",
    d0208="",
    d0209="",
    d0210="",
    d0211="",
    d0212="",
    d0213="",
    d0214="",
    d0215="",
    d0216="",
    d0217="",
    d0218="",
    d0219="",
    d0220="",
    d0221="",
    d0222="",
    d0223="",
    d0224="",
    d0225="",
    d0226="",
    d0227="",
    d0228="",
    d0229="",
    d0301="",
    d0302="",
    d0303="",
    d0304="",
    d0305="",
    d0306="",
    d0307="",
    d0308="",
    d0309="",
    d0310="",
    d0311="",
    d0312="",
    d0313="",
    d0314="",
    d0315="",
    d0316="",
    d0317="",
    d0318="",
    d0319="",
    d0320="",
    d0321="",
    d0322="",
    d0323="",
    d0324="",
    d0325="",
    d0326="",
    d0327="",
    d0328="",
    d0329="",
    d0330="",
    d0331="",
    d0401="",
    d0402="",
    d0403="",
    d0404="",
    d0405="",
    d0406="",
    d0407="",
    d0408="",
    d0409="",
    d0410="",
    d0411="",
    d0412="",
    d0413="",
    d0414="",
    d0415="",
    d0416="",
    d0417="",
    d0418="",
    d0419="",
    d0420="",
    d0421="",
    d0422="",
    d0423="",
    d0424="",
    d0425="",
    d0426="",
    d0427="",
    d0428="",
    d0429="",
    d0430="",
    d0501="",
    d0502="",
    d0503="",
    d0504="",
    d0505="",
    d0506="",
    d0507="",
    d0508="",
    d0509="",
    d0510="",
    d0511="",
    d0512="",
    d0513="",
    d0514="",
    d0515="",
    d0516="",
    d0517="",
    d0518="",
    d0519="",
    d0520="",
    d0521="",
    d0522="",
    d0523="",
    d0524="",
    d0525="",
    d0526="",
    d0527="",
    d0528="",
    d0529="",
    d0530="",
    d0531="",
    d0601="",
    d0602="",
    d0603="",
    d0604="",
    d0605="",
    d0606="",
    d0607="",
    d0608="",
    d0609="",
    d0610="",
    d0611="",
    d0612="",
    d0613="",
    d0614="",
    d0615="",
    d0616="",
    d0617="",
    d0618="",
    d0619="",
    d0620="",
    d0621="",
    d0622="",
    d0623="",
    d0624="",
    d0625="",
    d0626="",
    d0627="",
    d0628="",
    d0629="",
    d0630="",
    d0701="",
    d0702="",
    d0703="",
    d0704="",
    d0705="",
    d0706="",
    d0707="",
    d0708="",
    d0709="",
    d0710="",
    d0711="",
    d0712="",
    d0713="",
    d0714="",
    d0715="",
    d0716="",
    d0717="",
    d0718="",
    d0719="",
    d0720="",
    d0721="",
    d0722="",
    d0723="",
    d0724="",
    d0725="",
    d0726="",
    d0727="",
    d0728="",
    d0729="",
    d0730="",
    d0731="",
    d0801="",
    d0802="",
    d0803="",
    d0804="",
    d0805="",
    d0806="",
    d0807="",
    d0808="",
    d0809="",
    d0810="",
    d0811="",
    d0812="",
    d0813="",
    d0814="",
    d0815="",
    d0816="",
    d0817="",
    d0818="",
    d0819="",
    d0820="",
    d0821="",
    d0822="",
    d0823="",
    d0824="",
    d0825="",
    d0826="",
    d0827="",
    d0828="",
    d0829="",
    d0830="",
    d0831="",
    d0901="",
    d0902="",
    d0903="",
    d0904="",
    d0905="",
    d0906="",
    d0907="",
    d0908="",
    d0909="",
    d0910="",
    d0911="",
    d0912="",
    d0913="",
    d0914="",
    d0915="",
    d0916="",
    d0917="",
    d0918="",
    d0919="",
    d0920="",
    d0921="",
    d0922="",
    d0923="",
    d0924="",
    d0925="",
    d0926="",
    d0927="",
    d0928="",
    d0929="",
    d0930="",
    d1001="",
    d1002="",
    d1003="",
    d1004="",
    d1005="",
    d1006="",
    d1007="",
    d1008="",
    d1009="",
    d1010="",
    d1011="",
    d1012="",
    d1013="",
    d1014="",
    d1015="",
    d1016="",
    d1017="",
    d1018="",
    d1019="",
    d1020="",
    d1021="",
    d1022="",
    d1023="",
    d1024="",
    d1025="",
    d1026="",
    d1027="",
    d1028="",
    d1029="",
    d1030="",
    d1031="",
    d1101="",
    d1102="",
    d1103="",
    d1104="",
    d1105="",
    d1106="",
    d1107="",
    d1108="",
    d1109="",
    d1110="",
    d1111="",
    d1112="",
    d1113="",
    d1114="",
    d1115="",
    d1116="",
    d1117="",
    d1118="",
    d1119="",
    d1120="",
    d1121="",
    d1122="",
    d1123="",
    d1124="",
    d1125="",
    d1126="",
    d1127="",
    d1128="",
    d1129="",
    d1130="",
    d1201="",
    d1202="",
    d1203="",
    d1204="",
    d1205="",
    d1206="",
    d1207="",
    d1208="",
    d1209="",
    d1210="",
    d1211="",
    d1212="",
    d1213="",
    d1214="",
    d1215="",
    d1216="",
    d1217="",
    d1218="",
    d1219="",
    d1220="",
    d1221="",
    d1222="",
    d1223="",
    d1224="",
    d1225="",
    d1226="",
    d1227="",
    d1228="",
    d1229="",
    d1230="",
    d1231=""}

    -- Send birthday notification
    function sendPush(note) 
       if tostring(os.date("%H")) == tostring(notification_hour) then
    for i = 1, # mDevices do
    fibaro:call(mDevices, "sendPush", note);
    end;
       end;
    end;

    -- main LOOP
    -- Always show if there is a somebody's birthday today
    if birthday_calendar[today] ~= "" then
    note = "Dzisiaj urodziny obchodzi " .. birthday_calendar[today];
    fibaro:call(virtualId, "setProperty", "ui.birthdayL1.value", note);
    sendPush(note);
        fibaro:log(note);
    else
        fibaro:call(virtualId, "setProperty", "ui.birthdayL1.value", "Dzisiaj nikt nie obchodzi urodzin");
    end;

    if birthday_calendar[tomorrow] ~= "" then
    note = "Jutro urodziny obchodzi " .. birthday_calendar[tomorrow];
    fibaro:call(virtualId, "setProperty", "ui.birthdayL2.value", note);
    sendPush(note);
        fibaro:log(note);
    elseif birthday_calendar[tomorrow] == "" then
        -- check for nearest birthday....
    fibaro:log("looking forward ...");  
    repeat 
       next_day = next_day + 24*60*60;           
         --fibaro:debug(tostring(os.date("%m%d", next_day)));
       next_birthday = "d"..tostring(os.date("%m%d", next_day));
         --fibaro:debug(next_birthday);
         if birthday_calendar[next_birthday] ~= "" then
           note = "Najbliższe urodziny " .. tostring(os.date("[%Y-")) .. tostring(os.date("%m-%d]", next_day)) .." obchodzi " .. birthday_calendar[next_birthday];
    fibaro:call(virtualId, "setProperty", "ui.birthdayL2.value", note);
         fibaro:log(note);
           --sendPush(note);
          end;    
         if next_birthday == "d1231" then      
           --fibaro:debug("Year changed");
           change_year = true;
           next_day = (os.time({day=01,month=01,year=tostring(tonumber(os.date("%Y"))+1),hour=00,min=00,sec=00})+os.time()-os.time(os.date("!*t")));
       --fibaro:debug(tostring(next_day));
           end;
       until birthday_calendar[next_birthday] ~= "";
    end;

    -- check every hour to send notification
    fibaro:sleep(1000*60*60);
     

    Link to comment
    Share on other sites

    • 3 months later...

    Hi,

    I have a problem to add the picture to notification from HK Vision camera.

    The link that I can check in browser on PC and in IOS device is http://192.168.1.133/streaming/Channels/1/picture - I have nice pictures both  in browser and in my iphone.

    If I put that link into img source - no picture is in notfication. If I put any other internet address with picture - everything is OK.

    The idea of the scene is to present photo of a guest before making decision of opening door lock.

    I have photos of guests by e-mail - but I want to have it smarter (push photo - decide to open door or not).

    Any ideas or suggestions?

     

    Link to comment
    Share on other sites

    • I.Srodka unpinned and unfeatured this topic
    • 4 weeks later...
    On 3/15/2017 at 10:53 AM, Sankotronic said:

    Popup notifications and custom images

     

    Here is short tutorial how to change default icons on popup notifications using icons added to our HC gateways. As you all know popup notifications can be very useful since they can be found in Fibaro application Notifications inbox as shown on the following picture:

     

    Please login or register to see this attachment.

    Unfortunately popup messages does not give any sound when received but they stay in that inbox waiting for us to see them. Positive side of this type of notifications is that they can contain exact time when they where sent by some process and have long and informative message with title, subtitle, icon and different frame color depending on type of the notification. Here is basic code that is used to send popup notifications that will be shown on all mobile devices that are included into the HC system:

    Please login or register to see this code.

    Notice that in above code we can define type of the popup notification and it is set to "Info" that gives popup message blue frame we can define also next types of popup notification:

    • Info         - blue color frame
    • Success - green color frame
    • Warning - yellow color frame
    • Critical   - red color frame

    If you run above code and only change type you will get following popup notifications:

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    On above pictures you can see that default icons change depending on type of the notification, but they are not really good enough and in most cases we like to have more informative icon like that nice red flashing light for burglar alarm for example:

    Please login or register to see this attachment.

    On above picture you can also see that only one button is defined and that sceneId is equal to 0 what means that no scene will be triggered when button is pressed. It is possible to have more than one button and also it is possible to set so that scene with defined ID is triggered if button is pressed. See code bellow:

    Please login or register to see this code.

    Running above code will result in following popup notification:

    Please login or register to see this attachment.

    WOW, from above picture and code you can see that this popup notification not only have custom image but also have two buttons giving us possibility to make choice to either disarm alarm by pressing button Disarm which will then trigger scene with ID 177 or just close notification by pressing Cancel button.

     

    And now finally how to get URL path to custom icons that are already loaded to HC2 so that they can be shown on popup messages? It is quite simple. Just right click on icon anywhere on the web GUI and then on open menu select following option depending on browser you use:

     

    On Safari:

    Please login or register to see this attachment.

     

    On Chrome:

    Please login or register to see this attachment.

     

    On Firefox:

    Please login or register to see this attachment.

     

    And paste that URL to your LUA code. TADA! Thats it!

    Enjoy your popup notifications with your icons!! :-) 

     

    NOTE: Above solution with copying image address works only when mobile devices are connected locally on your home network! If you are away from home then you will not see your custom icons on popup notifications!

     

    So what to do to get custom icons on popup messages always no matter are you connected to HC locally or remotely?

     

    Well, answer is simple, you need to put your icons on some server so that they can be downloaded by mobile application. Usually FTP server will be sufficient but what if you don't have any such space on internet and you don't want to open it?

     

    Here is solution No. 1

     

    DROPBOX

    Arrange your custom icons in Dropbox folder. Now right click on icon and on popup menu select option "Copy Dropbox Link". This is same for all OS's, macOS and Windows. Now you can paste this link in your code and it will look like this:

    Please login or register to see this code.

    Since we need this icon to download to our app to be shown you need to change dl=0 to dl=1 so final link will look like this:

    Please login or register to see this code.

    When app needs to download icon first time there could be some short delay before icon is shown on popup notification. Each next occurrence will be instant because icons will be kept by the Fibaro app until it is closed on mobile device. At least I get that impression after using this feature for one day.

     

    Enjoy coding! :-) 

     

     

     

     

    Nice turorial!

    It’s a way to send this pop up for a specific user?

     

    How to run this scene at startup? For example to send an message when HC2 restart and boot again?

     

    I try to run this scene at startup and also add a line to send me notification on iPhone. Notification is received but pop up missing. In debug nothing show and when I test its run ok, but after restart not work.

     

    --[[
    %% autostart
    %% properties
    %% events
    %% globals
    --]]


    local sourceTrigger = fibaro:getSourceTrigger();
    if (sourceTrigger["type"] == "autostart") 
    then
     
    fibaro:call(1454, "sendDefinedPushNotification", "1575");

    local popTitle     = "FIBARO reboot"
    local popContTitle = "FIBARO 1 was rebooted!"
    local popBody      = "Main FIBARO HC2\n"..
                         "was rebooted.\n" ..
                         "\n" ..
                         "All is ready for use."
    local popImage     = "http://MYFIBAROID/fibaro/icons/scena/User1338.png"
    local popType      = "Info"

    -------------------------------------------
    HomeCenter.PopupService.publish({
    title        = popTitle,
    subtitle     = os.date("%H:%M:%S | %d.%m.%Y"),
    contentTitle = popContTitle,
    contentBody  = popBody,
    img          = popImage,
    type         = popType,
    buttons      = { { caption = "OK", sceneId = 0 } }
    });
      
    end

     

    thanks

    Edited by MDC
    Link to comment
    Share on other sites

    Hi @Sankotronic,

     

    just for your info (maybe you already know):

     

    I found interesting issue with interactive popups and push as well. If you choose a scene to be run that should be pin protected, it runs straightforward, no protection at all. I posted a question here:

     

    Best regards,

     

    Andrzej

     

    Link to comment
    Share on other sites

    • 6 months later...

    Hi,

    I tried the pop-up notification.

    It's working and pop's up on my devices.

    The only thing is, the scene will not be triggered.

    If I press the button the pop-up close but nothing else.

    Do I miss something?

    Here is my scene.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 2 months later...

    Can we only do 

    popButtons =  { { caption = "Disarm", sceneId = 0 }

    or can we replace sceneId with a direct action like turming a light on/off

    Link to comment
    Share on other sites

    • 2 months later...

    Hello
    I have created a seny according to the instructions, after pouring the bathroom is sent a notification Popup notifications here is the scene

     

    --[[
    %% autostart
    %% properties
    %% events
    %% globals
    --]]

    local popTitle     = "ZALANIE ŁAZIENKI "    
    local popContTitle = "ZAWÓR WODY ZOSTAŁ ZAKRĘCONY"..
                         "   "
    local popBody      = "CZY ODKRĘCIĆ ZAWÓR WODY"..
                         " "
    local popImage     = "http://192.168.1.104/fibaro/n_vicons/User1020.png"
    local popType      = "Critical"

    -------------------------------------------
    HomeCenter.PopupService.publish({
    title        = popTitle,
    subtitle     = os.date("%H:%M:%S | %d.%m.%Y."),
    contentTitle = popContTitle,
    contentBody  = popBody,
    img          = popImage,
    type         = popType,
    buttons      = { { caption = "Tak", sceneId = 177 },
                     { caption = "Nie", sceneId = 0 } }
    })
    ---------------------------------------------

    And after pressing on the tablet Yes, the stage should start, but the scene does not react, which is the reason I am asking for help.

     

     

    --[[
    %% autostart
    %% properties
    495 value
    %% weather
    %% events
    %% globals
    --]]

    local startSource = fibaro:getSourceTrigger();
    if (
     ( tonumber(fibaro:getValue(495, "value")) == 0 )
    or
    startSource["type"] == "other"
    )
    then
        fibaro:call(495, "turnOn");
    end

     

     

     

    Link to comment
    Share on other sites

    • 2 months later...

    Brilliant Sir, i have been looking for two days for solutions to this. Fantastic.

    Copy image address to url wad a pain to figure out..

    Great..

    Link to comment
    Share on other sites

    One question, like Kage mentioned - is there a way i can replace sceneId with device Id ? . tnx

    Edited by MARCUSP.I.L
    Link to comment
    Share on other sites

    3 hours ago, MARCUSP.I.L said:

    One question, like Kage mentioned - is there a way i can replace sceneId with device Id ? . tnx

    I don’t know, but would be interested too. 

    But I guess it won’t work. 

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...