Page 1 of 1

Combining Domoticz and Homecenter 3 (Zwave, QuickApps, FibaroLink)

Posted: Friday 29 January 2021 17:18
by JeroenL
Dear all,

Over time, my Z-wave network with domoticz became unstable, and finally caused my Z-wave configuration to crash (Aeotec Z-Stick Gen5 on Raspberry Pi 2 B). All nodes were gone, and I only managed to recover some of them after a week. Probably, as a consequence Domoticz became unstable, and crashed regularly as well.
As an (expensive) solution I bought a Homecenter 3 (HC3) from Fibaro, also anticipating future expansions to come. But more importantly, with the objective to make my curent system more robust (i.e. having a redundant Z-wave controller) and still make use of my LUA scripts in Domoticz as I did not fancy porting them to Fibaro.

I did not find a lot of information on how to do this, but what I have working now hopefully helps other. It is not overly complex, and I hope it might create further ideas on how to improve and better integrate the two systems. Thanks upfront, for any ideas you might have.

Summary of my Domoticz/HC3 setup:
  • Fibaro HC3 is the primary Zwave controller
  • Domoticz with an Aeotec Z-wave Stick Gen5 works as a secondary controller
  • Other devices share their status using FibaroLink through global variables in Fibaro
  • A simple "QuickApp" is used to control Domoticz (non Z-wave) devices from within Fibaro
The steps I followed:

1) Set-up Fibaro HC3
  • Set-up all the basic stuff in your HC3 configuration
  • Add all Z-wave devices you want to include to the Devices / Z-wave section
  • Test if all your Z-wave devices are working properly from HC3
Note: Do not forget to exclude the devices first, I used my Aeotec Stick for this, excluding every device just before including in HC3. All in all this is the most time consuming part, especially if you have a lot of wall switches. I was not bothered removing them from Domoticz, as we will have to delete / reset everything later anyway.]

2) Prepare Domoticz
  • If you used your Z-wave stick outside the Raspberry Pi, time to put it back in domoticz, and activate the hardware
  • Make a back-up just in case, always good practice
  • In the hardware management page go to the settings of your Z-wave controller
  • In the Node-management menu choose "Controller Hard reset" or whatever it is called in English
  • This should bring back your Z-wave stick to it's factory settings
  • Go to the Devices menu, filter on Z-Wave and delete ALL Z-wave devices you have
  • Open a command shell window and stop domoticz from running (and monit first if you use it). [sudo service domoticz stop]
  • Remove the open zwave cache file from the Config directory [sudo rm ~/domoticz/Config/ozwcache* ]
  • Restart domoticz by rebooting or restarting the service
Make now sure that Domoticz can receive new Hardware/devices (General settings) so it is ready to receive the configuration from HC3.
So,
  • Set the Fibaro HC3 into learning mode (Devices / Zwave / Add devices with the + icon)
  • In the Z-Wave settings page (Hardware section), in the Node management menu select: "Receive configuration from other controller"

A minute or so later, you should see the Domoticz Aeotec Z-wave stick controller popping up in Fibaro. Unfortunately in my case, the Z-wave device did not fully configure (additional verification in the diagnostics page in HC3 showed the same). In domoticz, I could not see the devices appearing either :(

Maybe there are other ways, but what worked for me was using the Simplicity Studio tool on my Windows laptop to fix the issue.
  • De-activate Z-wave hardware in Domoticz, and move the stick to your Windows computer
  • Start the Simplicity Studio 5 software, and in the Tools menu, you can find the "PC Z-wave controller" module. I found it difficult to find, in settings select the right COM port ofcourse.
  • In this tool I could see that all my nodes where somehow present in the stick and that Domoticz was indeed a secondary controller. In the summary section, I saw the message 32 nodes.
  • Next, in the Fibaro HC3, I selected "re-configure" device, whilst my stick was still in the lap-top
  • This did the trick (I believe) and I got the green checkmarks, and "Z-wave fully configured" in the Diagnostics page.
  • As a finishing touch, I added the Domoticz icon to my controller
domoticz_controller.PNG
domoticz_controller.PNG (37.93 KiB) Viewed 3057 times
  • Time to move the stick back to Domoticz and activate the hardware again
  • About 10 min. later I could see the node list in the Hardware section, and over a 100 Z-wave devices were added to the device list
From the device list, add those devices you want to use to your Domoticz set-up. I used the same names as I have before, to ensure all my LUA scripts will keep working. In Blockly, you will have to re-select the right Device ID.

I have not yet found a fool-proof way to identify which Z-wave device is which in Z-wave device list. I have the impression not all decimal ID's match the HEX IDs in the node-list. So it was a bit of trial-and-error to get it right. Any tips on how to do this, appreciated!

Congratulations as the most challenging part is done here. You can control both your Z-wave devices from both Domoticz and Homecenter 3


3) Controlling HC3 devices from within Domoticz

Z-Wave is done now, but wouldn't it be nice, if other devices could communicate to HC3 as well. For this I used the FibaroLink option which is present in Domoticz. On different fora I read one can update a "global variable" in Homecenter, but it does not trigger a Scene in Fibaro. (Lite and HC2). I tested, and can confirm that for me it works in HC3. If I change a global variable with Domoticz, it can trigger a scene in HC3.
  • Create a "Global Variable" in Homecenter [General/variables]. I created the variable alarm_breached
  • In Domoticz, link your Domoticz Device to this variable, see below:
The attachment FibaroLink.PNG is no longer available

And in Fibaro, in the Scenes section, you can use this variable as a trigger:
The attachment FibaroVariable.PNG is no longer available
That's it concerning linking Domoticz to Fibaro.

4) Controlling Domoticz devices from within HomeCenter 3

Last part, controlling Domoticz from HC3. For this I used the QuickApp functionality which is newly introduced in HC3. In the devices section in HC3, in 'other', you can add a QuickApp. I used the 'Binary Switch" for starters, but maybe something else is more suitable.
Also the functionality below is still very basic, and looking forward to other idea's this might give to you.
In the "Edit&Preview" section of your QuickApp. Click om Edit. This brings you the Builder. On the left hand side you can define the Buttons for your QuickApp (QA) on the right hand side the LUA Code having the objects for each button.

I created a button Called "Bark" and in domoticz this command plays an mp3 of a barking dog on my Sonos system. Make sure that in the button you call your function. In my case "barkOn" [no need for ()].

Copy / Paste the below LUA script into your QA:

Code: Select all

--
-- Domoticz interface using buttons  v1.1
-- This LUA code makes a call to a Domoticz button, triggering an action in Domoticz
-- 2021-01-25 : A first version, proof of principle experimenting with LUA
-- 2021-01-26 : Script clean-up
--
-- Binary switch type should handle actions turnOn, turnOff
-- To update binary switch state, update property "value" with boolean

local domoticz_ip = "192.168.178.55:8080"
local bark_idx    = 601

function QuickApp:turnOn()
    self:debug("Barking dog turned on")
    self:updateProperty("value", true)
    -- fibaro.call (self.id, "fcCommands", "On")
end

--
-- TurnOff not used in this script. 
-- 

function QuickApp:turnOff()
    self:debug("Barking dog turned off")
    self:updateProperty("value", false)    
    -- fibaro.call (self.id, "fcCommands", "Off")
end

-- 
-- Function that corresponds to "Bark" button 
-- 
function QuickApp:barkOn()
    self:debug("Barking dog turned on in Domoticz")
    self:updateProperty("value", true)
    fibaro.call (self.id, "fcCommands", bark_idx, "On")
end

-- 
-- Concept of QuickApp use found here: https://forum.fibaro.com/topic/51076-url-commands-to-domoticz-hc3/
-- 
function QuickApp: fcCommands(idx, cmd)
   --
   -- URL To be used: http://192.168.178.55:8080/json.htm?type=command&param=switchlight&idx=601&switchcmd=On&level=0&passcode=
   --
   local address = "http://" ..domoticz_ip.. "/json.htm?type=command&param=switchlight&idx=" ..idx.. "&switchcmd=" ..cmd  .."&level=0&passcode="
   self:debug("Calling http request")
  
   self.http:request(address, {
        options={
            headers = { 
                Accept = "application/json"
            },
            checkCertificate = true,
            method = 'GET'
        },
        success = function(response)
            self:debug("response status:", response.status) 
            self:debug("headers:", response.headers["Content-Type"]) 
            local data = json.decode(response.data)
        end,
        error = function(error)
            self:debug('error: ' .. json.encode(error))
        end
    }) 
end

function QuickApp:onInit()
    self:debug("onInit")
    self.http = net.HTTPClient({timeout=3000})
end
-- This is QuickApp initial method. It is called right after your QuickApp starts (after each save or on gateway startup). 
-- Here you can set some default values, setup http connection or get QuickApp variables.
-- To learn more, please visit: 
--    * https://manuals.fibaro.com/home-center-3/
--    * https://manuals.fibaro.com/home-center-3-quick-apps/
Builder.PNG
Builder.PNG (9.74 KiB) Viewed 3057 times
Save your QA and it is now ready to be used in Scenes. Going forward I intend to add more buttons to the QuickApp, allowing only one Device to activate multiple device in Domoticz by using multiple buttons.

In a Scene you can activate the Button as follows:
Button.PNG
Button.PNG (12.93 KiB) Viewed 3057 times
As said in the beginning, I really hope this helps others, but most of all inspires to further ideas to improve.

On my wish-list today:
  • Keep on using Domoticz for all my scripts and timers, as it has better random and sunset/rise functions. However, if for whatever reason Domoticz crashes, let Fibaro take over. For this I want to use the Profile feature. e.g. Create a profile "Domoticz down" which turns on a number of Scenes in Fibaro.

Re: Combining Domoticz and Homecenter 3 (Zwave, QuickApps, FibaroLink)

Posted: Thursday 18 February 2021 19:25
by JeroenL
Topic: Domoticz watchdog: Monitoring domoticz from Homecenter 3, and take-over in case of failure

Dear all,
In addition to above topic, herewith lua QuickApp code that monitors the status of domoticz at a given interval. If domoticz goes down, Homecenter 3 would take-over by activating a number of scenes defined in the profile "Domoticz off".
Any further suggestions more than welcome, as these are my first experiments. Hopefully useful for some, who like to have redundancy on their system.

Code: Select all

-- QuickApp Domoticz status, by J. Lindhout
-- Version 1.0 -- First working version (18th February 2021)
-- Version 1.1 -- Added push notification to iPhone and iPad 
--
-- Based on: https://forum.fibaro.com/topic/51264-read-a-json-with-hc3/

function QuickApp:onInit()
    __TAG = "DOMOTICZ_STATUS_"..plugin.mainDeviceId
    self:debug("-- Starting QuickApp: Domoticz Status --") 
    self.http = net.HTTPClient({timeout=3000})
    self:loop("")
end

function QuickApp:loop(text) 
    -- 
    -- URL to make a call to domoticz. If it returns values, assuming that domoticz is up and running. If not, domoticz must be down
    --
    local url      = "http://192.168.178.55:8080/json.htm?type=command&param=getversion"
    local interval = 7200                                                                       -- Every n seconds,  7200 = every 2 hrs
    
    -- self:debug("OnInit")

    self.http:request(url, {
        options={
            headers = {Accept = "application/json"}, method = 'GET'}, success = function(response)
            -- self:debug("response status:", response.status) 
            -- self:debug("headers:", response.headers["Content-Type"]) 
            apiResult = response.data

            --self:debug("Full apiResult: ",apiResult)

            jsonTable = json.decode(apiResult) -- JSON decode from api to lua-table
            --self:debug("jsonTable: ",jsonTable)

                        -- Typical output from above URL

	                    --  "DomoticzUpdateURL" : "https://www.domoticz.com/download.php?channel=stable&type=release&system=linux&machine=armv7l",
	                    -- 	"HaveUpdate" : false,
	                    -- 	"Revision" : 0,
	                    -- 	"SystemName" : "linux",
	                    -- 	"UseUpdate" : true,
	                    -- 	"build_time" : "2020-04-26 13:47:55",
	                    -- 	"dzvents_version" : "3.0.2",
	                    -- 	"hash" : "b63341bc0",
	                    -- 	"python_version" : "3.7.3 (default, Jul 25 2020, 13:03:44) \n[GCC 8.3.0]",
	                    -- 	"status" : "OK",
	                    -- 	"title" : "GetVersion",
	                    --  "version" : "2020.2"

            local status     = jsonTable.status                          -- Get the status value, other values not used in this script
            -- local HaveUpdate = jsonTable.HaveUpdate 
            -- local version    = jsonTable.version
            -- local SystemName = jsonTable.SystemName

            self:debug("Status: "    , status)
            -- self:debug("SystemName: ", SystemName)
            -- self:debug("Version: "   , version)
            -- self:debug("HaveUpdate: ", HaveUpdate)

             if jsonTable.status ~= "OK" then
                  self:debug("-- Status: Offline  ---  Activating profile: DOMOTICZ OFF -- ") 
                  fibaro.alert('push', {[1] = 28, [2] = 29, }, 'Domoticz off-line!', false)
                  fibaro.profile("activateProfile", 5)                    -- Please note that in the HC3 lua manual this is wrong, i.e. the other way around [@ 18/2/2021]
                                                                          -- https://manuals.fibaro.com/home-center-3-lua-scenes/
                                                                          --
                                                                          -- In the DOMOTICZ OFF profile, I activate scenes which are normally managed by domoticz
                                                                          -- One could do an automatic switch back if domoticz comes back online, for now I did not,
                                                                          -- as I want to know why domoticz went off-line 
             end
             -- self:debug("--------------------- END --------------------") 

        end,
            error = function(error)
            self:debug('error: ' .. json.encode(error))
        end
    }) 

        fibaro.setTimeout(tonumber(interval)*1000, function() -- Checks every n seconds for new data
        self:loop(text)
    end)
end 

Re: Combining Domoticz and Homecenter 3 (Zwave, QuickApps, FibaroLink)

Posted: Monday 09 August 2021 12:08
by tinytomos
Dear Jeroenl

In the first place thank you very much for your post on the Forum.
I followed your lead and indeed after 20 minutes i saw the zwave devices in the Domoticz in the hardware section/Aeon zwave ZW090 stick/settings
However i see none of the zwave-devices in the devicestab so i cannot bring them to dashboard and therefore i cannot control them in domoticz.
Please advice

Info Domoticz (Last Beta update with Python from Jadahl) running on a Synology DS220 Plus and Fibaro HC3L