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


  • 0

[VD] Scene & VD Debug Watchdog 1.1


AutoFrank

Question

Hi 

 

UPDATED 1.1

 

UPDATED THIS VD FROM A SCENE WATCHDOG TO A SCENE & VIRTUAL DEVICE WATCHDOG

Hopefully this will be a useful little VD to some users

It was inspired by a comment made by @tinman (I think) 

 

This VD Enables a user to scan all scene and virtual device DEBUG MESSAGES and trigger on predefined key words in the debug messages.

This may be useful to see if a scene develops an error or perhaps you are just looking for a keyword for a different reason

  • All scenes and virtual devices are included by default
  • Specific scenes and virtual device id's can be flagged to exclusion
  • Separate watch lists for scenes and virtual devices
  • A watchdog report is sent for all matches identified.
  • Can be sent via email or smart message hub
  • You get one email or message per id flagged ( not per watch word)
  • It will send message if no match in either vd or scene is found (added in v 1.1)
  • Suggested icon included below
  •  

              

Please login or register to see this image.

/monthly_2017_07/watchdog.png.053d2b2b2433c2a01bf526af79058585.png" alt="watchdog.png.053d2b2b2433c2a01bf526af79058585.png" />

 

Note: If you use the Smart Message Hub please add that scene ID into the exclusion list as that scene will be 
flagged by the watchdog after the first use.
  
This can be run on demand or on a schedule using Main Scene by @Sankotronic or similar.
I run it on a schedule once per day

 

Installation 

  • Import the VD
  • Configure the following as required

Please login or register to see this code.

  • Place on a scheduler if required

 

The VD has a status label and when it was last run

 

 watch.PNG.3ba1125c1bf4c5cba0c2c5b4aa2036df.PNGwatch1.PNG.b31653c26fea066e89d95fea10dbf911.PNGwatch2.PNG.07ad9270adbd029e6bfb9fb4d6a46d4e.PNG       

 

and this is what the report looks like on pushover

 

Please login or register to see this attachment.

 

VD attached

 

 

 

 

 

Please login or register to see this attachment.

Edited by AutoFrank
Link to comment
Share on other sites

Recommended Posts

  • 0

Hi @AutoFrank,

 

I was playing a lot with HTML flags and e-mails but never get it to work. It shows properly in debug window but in email on several different mail clients HTML tags are always shown as normal text with extra backslashes. I even manage to show picture in debug window but never get it in an e-mail! Maybe I ask stupid question but can that URL encode function be of any help?

Link to comment
Share on other sites

  • 0
9 minutes ago, Sankotronic said:

Hi @AutoFrank,

 

I was playing a lot with HTML flags and e-mails but never get it to work. It shows properly in debug window but in email on several different mail clients HTML tags are always shown as normal text with extra backslashes. I even manage to show picture in debug window but never get it in an e-mail! Maybe I ask stupid question but can that URL encode function be of any help?

 

I see two complaints regarding somewhat related subjects on this forum. Encoding of international characters fails on pushing/mailing/displaying and e-mail message corrupt or failed on special characters.  I can't help but think that things got worse recently. I have a script that mails something like this:

 

"Window K & P open".

 

I'm pretty certain that arrived intact, until 4.130-ish. Now I get:

 

"Window K"

 

So, I guessed the "&" was the culprit and I tried some workarounds, including "urlencode". Regarding UTF-8 I've tried "NCR" (Numeric character reference) and while that seems to work in a browser, it doesn't help fixing e-mail messages, probably because... you may have guessed it... NCR use an ampersand to start encoding.

 

Please login or register to see this link.

Edited by petergebruers
Link to comment
Share on other sites

  • 0

@AutoFrankYes, this version seems to solve the problem. Thanks. Don't apologize, I'm glad I could help :-)
Thanks again for the VD. I'll schedule execution soon and do some more testing as well integrating of the VD test.

 

@petergebruers

honestly, I noticed the formatting issue but I was not suprised to see it. I didn't expect to see correct html formatting while sending strings from a VD via SMsgH to a thunderbird e-mail client :-)

I'll think about your proposal but I'm used now to this debug in all my scene's that I probably will keep using it.

 

Link to comment
Share on other sites

  • 0
12 minutes ago, wpeeters said:

(...)

honestly, I noticed the formatting issue but I was not suprised to see it. I didn't expect to see correct html formatting while sending strings from a VD via SMsgH to a thunderbird e-mail client :-)

I'll think about your proposal but I'm used now to this debug in all my scene's that I probably will keep using it.

 

 

The code is a replacement for your code, it just adds replacement of invalid characters.

Link to comment
Share on other sites

  • 0

@petergebruers I replaced the code in that one scene. Still I have the same output in my mail client;

 

Please login or register to see this code.

Link to comment
Share on other sites

  • 0
5 hours ago, wpeeters said:

@petergebruers I replaced the code in that one scene. Still I have the same output in my mail client;

 

Please login or register to see this code.

 

Thanks for trying! Much appreciated! I'll see if I can find an explanation for the number of backslashes. I forgot to mention one more element: whenever you do a copy paste from/to editor"/hc2 edit window"/application we get another conversion.... I've seen quite a few posts containing code that didn't run because it was copy/pasted via MS Word (if I recall correctly).

Link to comment
Share on other sites

  • 0

Hi guys, I dont know if this is the right place to ask, is it possible to press the "save" button on a plugin? 

I know the french watch dog restarts scene's and vd's by pressing save but can this be done for plugins as well?

 

I found that pressing  save on the harmony plugin updates the correct state if you start an other activity by remote.

 

Thanks,

 

Jim 

Link to comment
Share on other sites

  • 0
2 hours ago, jimicr said:

Hi guys, I dont know if this is the right place to ask, is it possible to press the "save" button on a plugin? 

I know the french watch dog restarts scene's and vd's by pressing save but can this be done for plugins as well?

 

I found that pressing  save on the harmony plugin updates the correct state if you start an other activity by remote 

 

i guess "yes", UI is UI, so click save button should work.

 

For plugins, you can as well try to restart the plugin from any scene with:

 

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0
Just now, tinman said:

 

i guess "yes", UI is UI, so click save button should work.

 

For plugins, you can as well try to restart the plugin from any scene with:

 

Please login or register to see this code.

 

Thanks @tinman will try and report back :)

Link to comment
Share on other sites

  • 0

Hi Frank,

 

Install last version, local jT in comment, run and get this error;

 

[DEBUG] 18:54:34: Checking Scene id: 18
[ERROR] 18:54:35: line 170: attempt to index global 'jT' (a nil value)
 

What I do wrong...?

Edited by twanve
Link to comment
Share on other sites

  • 0
  • Inquirer
  • 23 minutes ago, twanve said:

    Hi Frank,

     

    Install last version, local jT in comment, run and get this error;

     

    [DEBUG] 18:54:34: Checking Scene id: 18
    [ERROR] 18:54:35: line 170: attempt to index global 'jT' (a nil value)
     

    What I do wrong...?

    Hi @twanve

    Sorry, I don't have access to the code at the moment but it looks like you need to comment out the reference to  jT if you don't use a hometable 

    Edited by AutoFrank
    Link to comment
    Share on other sites

    • 0
    22 hours ago, AutoFrank said:

    Hi @twanve

    Sorry, I don't have access to the code at the moment but it looks like you need to comment out the reference to  jT if you don't use a hometable 

     

    Hi Frank,

     

    I have this line in comment, I don't use a home table.

    Link to comment
    Share on other sites

    • 0
    53 minutes ago, AutoFrank said:

    @twanve

     

    Is it working or do you still have errors ? 

     

    Still the same error

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks @twanve

    I don't have access to the code as I am away 

     

    Would you mind posting the full code and I can take a look ...

    Link to comment
    Share on other sites

    • 0
    3 minutes ago, AutoFrank said:

    Thanks @twanve

    I don't have access to the code as I am away 

     

    Would you mind posting the full code and I can take a look ...

     

    --[[
        
      ** ScVD Dbg Watchdog v1.0d **
      Scene and VirtualDevice Debug Watchdog v 1.0c release (Autofrank - June 21st 2017).
       
      1.0d 0- fixed but in 1.0c where it missed one match 
       
      Enables a user to scan all scenes and virtual devices and trigger on predefined key words in the debug messages
      Specific scenes can be flagged to exclusion
      A watchdog report is sent for all scenes identified. Can be sent via email or smart message hub
      Note: If you use the Smart Message Hub please add that scene ID into the exclusion list or you will get a
      circular reference as the reports get sent out.
      
      HomeTable is only used to run smart message hub.
      The scenes and the deug messages are retrieved via the api
      
      This can be run on demand or on a schedule using Main Scene by @sankotronic or similar.
      I run it on a schedule once per day
      
    --]]

    local device, localhost, port = fibaro:getSelfId(), '127.0.0.1', 11111
    local watchReport = ""
    local sendFlag    = ""
    local title       = ""
    local v1          = ""
    local scStatus    = ""
    local vdStatus    = ""
    local scCount     = "0"    
    local vdCount     = "0"    
    local scanType    = ""

    -- user configurable
    --local jT    = json.decode(fibaro:getGlobalValue("HomeTable")) -- comment out if HomeTable is not used
    watchListSC = {"CRITICAL", "error", "line334", "line74", "concatinate", "Assertion failed"} -- words that you want to watch in scenes
    watchListVD = {"expected", "unfinished"} -- words that you want to watch in virtual devices
    excludeList = {"15"}        -- scene and virtual device id's that you would like to exclude from watching 
    SMsgH       = true          -- set to false if you don't use smart message hub
    SMsgHtarget = "pushover"    -- set to preferred medium if you use smart message hub
    deBug       = false         -- enable for greater debug verbosity

    -- end of user configuration section

    function checkScenes()

      sc = Net.FHttp(localhost, port)
      response, error = sc:GET("/api/scenes")
      if error == "200" or error == "201" then
        jS = json.decode(response)
        for k,v in pairs(jS) do
          Id, Name = v.id, v.name
          runStatus = "Starting to check Scenes..."
          fibaro:sleep(1000)
          runStatus = "Checking Scene id: "..Id..""
          fibaro:debug(runStatus)
          fibaro:call(device, "setProperty", "ui.lblstatusSC.value", runStatus)
          fibaro:call(device, "setProperty", "ui.lblstatusVD.value", "")
          sendFlag = "true"
          for k1,v1 in pairs(excludeList) do
            if string.match(v1, Id) ~= v1 and sendFlag == "true" then
              if deBug then fibaro:debug("no match found "..v1.."") end
            else
              if deBug then fibaro:debug("match FOUND so exclude: "..v1.."") end
              sendFlag = "false"
            end  
          end
          if sendFlag == "true" then
            fibaro:sleep(500)
            sc = Net.FHttp(localhost, port)
            --response, error = sc:GET("/api/scenes/DebugMessages?id="..Id.."")
            response, error = sc:GET("/api/scenes/"..Id.."/debugMessages")
            if error == "200" or error == "201" then
              jW = json.decode(response)
              fibaro:debug(JW)
              for k2,v2 in pairs(jW) do
                for k3,v3 in pairs(v2) do
                  if v2.type == "DEBUG" and k3 == "txt" then
                    for k4,v4 in pairs(watchListSC) do
                      if string.match(v2.txt, v4) == v4 then
                        scCount = scCount + 1
                        if watchReport == "" then 
                          watchReport = ""..watchReport.." \n Scene: "..Name..", ID: "..Id..". \nWatch Flags..\n"..v2.txt.."\n" 
                        else
                          watchReport = ""..watchReport..""..v2.txt.."\n"
                        end
                      end
                    end
                  end
                end
              end
            end
            scanType = "scene"
            sendReport()
                   
          end    
        end
      end
    end


    function checkVirtualDevices()

      sc = Net.FHttp(localhost, port)
      response, error = sc:GET("/api/virtualDevices")
      if error == "200" or error == "201" then
        jS = json.decode(response)
        for k,v in pairs(jS) do
          Id, Name = v.id, v.name
          runStatus = "Starting to check VD's..."
          fibaro:sleep(1000)
          runStatus = "Checking VD id: "..Id..""
          fibaro:debug(runStatus)
          fibaro:call(device, "setProperty", "ui.lblstatusVD.value", runStatus)
          sendFlag = "true"
          for k1,v1 in pairs(excludeList) do
            if string.match(v1, Id) ~= v1 and sendFlag == "true" then
              if deBug then fibaro:debug("no match found "..v1.."") end
            else
              if deBug then fibaro:debug("match FOUND so exclude: "..v1.."") end
              sendFlag = "false"
            end  
          end
          if sendFlag == "true" then
            fibaro:sleep(500)
            sc = Net.FHttp(localhost, port)
            --response, error = sc:GET("/api/scenes/DebugMessages?id="..Id.."")
            response, error = sc:GET("/api/virtualDevices/"..Id.."/debugMessages")
            if error == "200" or error == "201" then
              jW = json.decode(response)
              for k2,v2 in pairs(jW) do
                for k3,v3 in pairs(v2) do
                  if v2.type == "DEBUG" and k3 == "txt" then
                    for k4,v4 in pairs(watchListVD) do
                      if string.match(v2.txt, v4) == v4 then
                        vdCount = vdCount + 1
                        if watchReport == "" then 
                          watchReport = ""..watchReport.." \n VD: "..Name..", ID: "..Id..". \nWatch Flags..\n"..v2.txt.."\n" 
                        else
                          watchReport = ""..watchReport..""..v2.txt.."\n"
                        end
                      end
                    end
                  end
                end
              end
            end
            scanType = "VD"
            sendReport()
               
          end    
        end
      end
    end

    function sendReport()
      -- compose title
      if watchReport ~= "" and scanType == "scene" then
        title = "Watchdog Report: Scene"
      end
      
      if watchReport ~= "" and scanType == "VD" then
        title = "Watchdog Report. VD"
      end
      
      -- send report
      if SMsgH then
        if SMsgHtarget == "hc2popup" then
          fibaro:startScene(jT.sc.SMsgH, {watchReport, SMsgHtarget, "", title, popType})
        else
          fibaro:startScene(jT.sc.SMsgH, {watchReport, SMsgHtarget, "", title})
        end
      else
        fibaro:call(2, "sendEmail", title, watchReport)
      end
      watchReport = ""    
    end


    function updateSClables()
      
      -- update labels
      if scanType == "scene" then
        if tonumber(scCount) > 0 then
          scStatus = ""..scCount.." matches were found"
        else
          scStatus = "No matches were found"
        end  
        fibaro:call(device, "setProperty", "ui.lblstatusSC.value", scStatus)
      end

    end
      
    function updateVDlables()
      
      if scanType == "VD" then
        if tonumber(vdCount) > 0 then
          vdStatus = ""..vdCount.." matches were found"
        else
          vdStatus = "No matches were found"
        end  
        fibaro:call(device, "setProperty", "ui.lblstatusVD.value", vdStatus)
      end
      
      if deBug then fibaro:debug(watchReport) end
      
      -- notify that watchdog was run as schedule if no matches were found
      if tonumber(scCount) == 0 and tonumber(vdCount) == 0 then
        title = "Watchdog check complete"
        report = "No matches found in either virtual devices or scenes"
        if SMsgH then
          if SMsgHtarget == "hc2popup" then
            fibaro:startScene(jT.sc.SMsgH, {report, SMsgHtarget, "", title, popType})
          else
            fibaro:startScene(jT.sc.SMsgH, {report, SMsgHtarget, "", title})
          end
        else
          fibaro:call(2, "sendEmail", title, report)
        end
      fibaro:debug("Watchdog check complete - no reports sent..")
      else
      fibaro:debug("Watchdog reports sent..")
      end
      
      

      local upt = ""..os.date("%d").." "..os.date("%B").." @ "..os.date("%H:%M")..""
      fibaro:log("Last update: "..upt)
      fibaro:call(device, "setProperty", "ui.lblupdate.value", "Last update: "..upt)

    end

    function main()
      
      checkScenes()
      updateSClables()
      checkVirtualDevices()
      updateVDlables()

    end

    main()

    Link to comment
    Share on other sites

    • 0
    Just now, AutoFrank said:

    Thanks @twanve

     

    Are you using the smart message hub ? 

     

     

     

    no

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Okay .. Thanks @twanve

     

    So you need to set SMsgH = false 

    This is about 4 lines down from the hometable reference 

     

    Also 2 lines under that set deBug  = true 

    This will give you a ittle more debug messages ...

     

    Make those two changes, save and see what happens..

    Tell me what you what you see in the debug window 

     

    Edited by AutoFrank
    Link to comment
    Share on other sites

    • 0
    4 minutes ago, AutoFrank said:

    Okay .. Thanks @twanve

     

    So you need to set SMsgH = false 

    This is about 4 lines down from the hometable reference 

     

    Also 2 lines under that set deBug  = true 

    This will give you a ittle more debug messages ...

     

    Make those two changes, save and see what happens..

     

     

    Yup, this is the solution, all works fine now.

    Thx for you support....!

    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
    Answer this question...

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