Created At

Nov 11, 2020

Last Update

Nov 12, 2020

Platforms

HC 3 Lite, Z-box Hub, Yubii Home Pro, Yubii Home, Venture WISE, HC 3

Views

3133

Download

92

Type Quick App

Would you like to integrate the Amazon Alexa Echo with your existing Home Automation solution? With the service www.IJPUK.com you can create as many doorbells as you like, then get the Amazon Alexa Echo device to announce and or chime when your doorbell is pressed.

Perhaps your doorbell is not loud enough? Or, you sometimes find you can not hear your doorbell in certain rooms of your house? Use your Amazon Alexa as an extension and make sure you never miss your doorbell ring again!

Once you have linked your Alexa device, created a door bell or two, you can test them out to ensure that they sound your chosen chime, all free of charge.

The Amazon Alexa system can go further than this through the use of Alexa Routines. These are scenes (as shown below) that you can easily create to run when something triggers them, a doorbell press is just one of the many trigger inputs available, you could think of this, not as creating doorbells, but as creating triggers.

Trigger Actions

When you are ready to embed this into your home automation controller, you can make use of our API service.

How to set up your Alexa device

Below I present the method found and successfully tested on the Fibaro Home Center 3.
It was possible thanks to Ian (http://ijpuk.com)

Steps:
  • Open "Settings -> Devices -> Other"
  • Click "+" (add device)
  • Create a Quick App as a 'Generic Device'
  • Copy and paste the code and set your credentials accordingly.:
    -- Fibaro HC3 edition - Donated by Tony - Thank you
    
    function QuickApp:onInit()
    
        baseUrl = "https://api.ijpuk.com"
        -- Visit https://www.ijpuk.com to create an account and get your doorbell key
    
        local ijpukUserName = "Your login"
        local ijpukPassword = "Your password"
        local doorbellKey = "Your doorbell key"
    
        ---------------------- Please dont change below this line  ----------------------
        local http = net.HTTPClient({timeout=2000})
    
        -- Utility function to send requests to email bridge
        function sendRequest(url, method, headers, data, next, fail)
            http:request(baseUrl .. url, 
            { 
                options = {
                    method = method,
                    headers = headers,
                    data = data,
                    timeout = 5000,
                    checkCertificate = false 
                },
                success = function(response)
                    local status = response.status
                    if (status == 200 and next ~= nil) then
                        next(response);
                    elseif (status ~= 200 and fail ~= nil) then
                        fail(response);
                    end
                end,
                error = function(err)
                    if (fail ~= nil) then
                        fail(err);
                    end
                end
            })
        end
    
        function decode(d)
            local isError, err = pcall(
                function()                
                    error({ data = json.decode(d) }) 
                end
            )
            if isError then
                local badData = json.encode(d)
                self:debug(badData)
            end
            return err.data
        end
    
        -- Utility function to encode a string into Base64
        local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 
        function base64Enc(data) 
            return ((data:gsub('.', function(x) 
                local r, b='', x:byte() 
                for i=8, 1, -1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end 
                return r; 
            end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) 
                if (#x < 6) then return '' end 
                local c=0 
                for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end 
                return b:sub(c+1,c+1) 
            end)..({ '', '==', '=' })[#data%3+1]) 
        end 
    
        local userNamePasswordBase64Encoded = base64Enc(ijpukUserName .. ":" .. ijpukPassword)
    
        sendRequest("/api/v1/Doorbell/" .. doorbellKey, "POST", {
            ['Authorization'] = "Basic " .. userNamePasswordBase64Encoded
        }, "", function(response)        
                local result = decode(response.data)        
                if result ~= nil and result.success == true then
                    self:debug("Success response received") 
                elseif result ~= nil and result.success == false then
                    self:debug("Error occured: " .. result.error)
                end
            end, 
            function(response)
                self:debug("An error occurred")
                local status = response.status
                if status == 401 then
                    self:debug("Username or password were invalid")
                elseif status == 403 then
                    self:debug("Missing or expired Premium subscription")
                else
                    self:debug("An unknown error occurred : " .. status)
                end
            end
        )
    
    end 
    

  • Note the QA Id (Id device) which you will need later.
  • Create a global variable 'Alexa_Key'. This is used when calling the QA.
  • "Open "Settings->Scenes->Add Secene->Choose type of scene -> Lua Scene"
  • Copy the following code the left side of the Scene Lua
    --Copy in triggers/conditions (left side of script page)
    {
      conditions = { {
          isTrigger = true,
          operator = "!=",
          property = "Alexa_Key",
          type = "global-variable",
          value = " Dummy " 
        } },
      operator = "any"
    }
    
  • Copy the following code the right side of the Scene Lua
QA_ID = your QA id.
debug = false
 
function log(message)
  if debug then
   fibaro.debug("",message);
  end
end
 
--TTS message and clear it after reading
log("executed")
message= fibaro.getGlobalVariable("Alexa_Key")
log(message)
if message ~= nil and message ~= "Dummy" then
    fibaro.call(QA_ID, "onInit") --Id QA TTS read
    fibaro.sleep(1000)
    fibaro.setGlobalVariable("Alexa_Key", "Dummy") --Reset global variable
    log("done")
else log("Unvalid message")
    log(message)
end

If you want to make more notifications (DoorBell - ijpuk.com) you need to correct the value of "Alexa_key" to the new value "Alexa_kay1" in Quick App and Lua Scene

    1. The last task is to create a block scene that will trigger a given notification.

 

 

If you don't want Alexa to hear "Someone is on ..." before every notification, use the routine function in Amazon Alexa. You could create a routine that makes an Announcement, and then set this Announcement to be whatever you want.

 

Many thanks to Ian from www.ijpuk.com for support and help -

we have it all thanks to him

 

RIGHTS

  • I allow code to be reuse or change. Also labels can be translated and adjust.

 

0 Comments,  Want to add comment please login
Load more comments
© 2024. Nice-Polska Sp. z o.o.Privacy policyTerms & ConditionsFeedback