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

Run scene on power outage notification powerplug


Question

Posted

Hi,

 

I have bought an Nodon smart plug (ASP 3-1-10)  which is capable to send a notification about a poweroutage.

My HC2 is behind a UPS so it gets the notification.

To gracefully shutdown the HC2 i need a scene which can react to the text given through the API

 

This is what i get when looking at http://HC2/api/notificationCenter

 

Please login or register to see this code.

so the plug is working ok...

I've tried serveral attemts to make a lua script but it's a bridge to far for me because i'm no pro programmer.

Can sombody help me to make the right scene for this ?

 

Regards,

Ronald

 

2 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    I have already the following code which i can use.

    But i don't know how to let it detect the "title" or "text" in the notification table

    If i debug the notification.created or notification.priority i get the expected values back , but how to read the title or text in the second "data" table ?

    so that ik can compare it with a local value to become true and start the shutdown action ?

     

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

    local notificationtype = 'GenericDeviceNotification'

    function poweroutage()
      local notifications = api.get('/notificationCenter')
     
      for _, notification in ipairs(notifications) do
        if notification.type == notificationtype then
          
          fibaro:debug("Gracefully shutdown HC2 " .. notification.id)
          HomeCenter.SystemService.shutdown()
          api.delete('/notificationCenter/' .. notification.id)
          
        else
          fibaro:debug("there are no more notification with type: " .. notificationtype)
        end
      end
    end

    poweroutage()

    • 0
  • Inquirer
  • Posted

    I have managed to make a good functioning script but how to trigger it through the notificationcenter ????

    Somebody ?

     

    Grtz,

    Msonic

     

     

    --[[
    %% properties
    %% events
    300 GenericDeviceNotification
    --]]

    --scenebeperking
    if (fibaro:countScenes()>1) then fibaro:debug("Scenebeperking > 1 ... Abort");fibaro:abort() end -- Run only one scene


    local debug = 1 --debug on/off
    local timer = 60
    local counter = timer
    local valuedisconnected = 'AC mains disconnected'
    local valueconnected = 'Power reconnected'
    local table = api.get('/notificationCenter')
    local notificationtype = 'GenericDeviceNotification'


    for k, v in ipairs(table) do --first table
      if v.type == notificationtype then
        for k2, v2 in pairs(v.data) do -- second table
            if v2 == valuedisconnected then
               print("start")
               -- begin loop
               while counter > 0 do
                counter = counter -1
                fibaro:sleep(1*1000)
                  if debug == 1 then fibaro:debug("Counter = ".. counter) end
                    for k3, v3 in ipairs(api.get('/notificationCenter')) do --first table
                      if v3.type == notificationtype then
                       for k4, v4 in pairs(v3.data) do -- second table
                        if v4 == valueconnected then
                        print("abort at power return when waiting to shutdown")
                          if v.type == notificationtype then
                          api.delete('/notificationCenter/' .. v.id) end
                        fibaro:abort()
                        end
                       end
                      end
                     end       
                    end    
            
              -- stop scene
              if v.type == notificationtype then
              api.delete('/notificationCenter/' .. v.id) end
              print("run shutdown command")

              HomeCenter.SystemService.Shutdown()
             
       end
      end
     end       
    end

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