Either / OR script

Hi to everyone who still visits the forum.

After a number of years of using the HAH to manage our central heating amongst other things, we have made a number of building changes to our house and would like to zone our central heating.

Member for

13 years 4 months

kema01

7 years ago

Hi Brett many thanks for your lighteningly fast reply.

Yes I did look at the bindings applet in the samples folder, unfortunatley my lua skills are very limited and was not able to work out the changes to be made to suit my requirements.

I have trolled all through the forum and cannot find anything close that I think I could adapt.

Many Thanks

Member for

16 years 10 months

brett

7 years ago

I'll fire up my trusty HAH development VM and see if I can whip you up something.  It might be a day or two if you can bear with me.

Member for

13 years 4 months

kema01

7 years ago

Brett fantastic, really apprechiate your help.

 

Many Thanks

Member for

13 years 4 months

kema01

6 years 12 months ago

 

Hi Brett many thanks for your help with the master / slave applet, unfortunately I am struggling with what I should substitute for my set up.

I would like my master relay to be “relay.1” so I have substituted

local masterRelay = "dbzoo.livebox.Master:relay.1"

for

local masterRelay = "dbzoo.livebox.Controller:relay.1"

Hopefully this is correct.

 

My slave relays are controlled via a jeenode with 4 relays

source=dbzoo.livebox.jeenode:kema6.relay1

source=dbzoo.livebox.jeenode:kema6.relay2

source=dbzoo.livebox.jeenode:kema6.relay3

source=dbzoo.livebox.jeenode:kema6.relay4

 

I am not sure what I should change  

f:add("xap-header","source","dbzoo.livebox.Slave:relay.*")

The following does not work

f:add("xap-header","source"," dbzoo.livebox.jeenode:kema6.relay.*”)

 

Many Thanks

 

Member for

16 years 10 months

brett

6 years 12 months ago

Those changes look correct there where two places to change the dbzoo.livebox.Slave.relay.* filter string I assume you did both.  You might want to put in debugging print statements in the callback to see if its getting in there.  Sounds like its not for some reason which would imply a filter issue.  The trick is understanding what I've given you so you can see the path forward.

Member for

13 years 4 months

kema01

6 years 12 months ago

Hi Brett, yes I had made the 3 changes, see below for complete applet.

Many thanks for your pointers, I will delve deeper as to what the problem is, unfortunatley my software skills are very limited so may take a while. Not sure how to implement the debug but will look back through the forum for help.


--[[

If any SLAVE relay is on then the MASTER relay should be on too.

Assumption: 

When the script starts all slaves are OFF

The script will update that assumption as events are received.

--]]


module(...,package.seeall)


require("xap")

require("xap.bsc")


info={

   version="1.0", description="any slave on, master on"

}


slaveStates={'off','off','off','off'}

masterState="off"


local function has_value (tab, val)

   for index, value in ipairs(tab) do

        if value == val then

            return true

        end

   end

   return false

end


-- Filter Callback

local function anyOn(master)

   -- Strip the Relay ID from the source and record the state

   local id = xap.getValue("xap-header","source"):sub(-1)

   slaveStates[tonumber(id)] = xap.getValue("output.state","state")


   -- Is any slave relay on?

   if has_value(slaveStates,'on') then

      newState='on'

   else

      newState='off'

   end


   if masterState ~= newState then

      bsc.sendState(master, newState)

      masterState = newState

   end

end


function init()

--local masterRelay = "dbzoo.livebox.Master:relay.1"

  local masterRelay = "dbzoo.livebox.Controller:relay.1"

  f = xap.Filter()

--f:add("xap-header","source","dbzoo.livebox.Slave:relay.*")

  f:add("xap-header","source","dbzoo.livebox.jeenode:kema6.relay.*")

  f:add("xap-header","class","xapbsc.event")

  f:callback(function() anyOn(masterRelay) end)


  -- Make sure we always have the correct state.

  -- Handle HAH reset with master/slaves still on

  f = xap.Filter()

  f:add("xap-header","source",masterRelay)

  f:add("xap-header","class","xapbsc.info")

  f:callback(function() masterState = xap.getValue("output.state","state") end)


  f = xap.Filter()

--f:add("xap-header","source", "dbzoo.livebox.Slave:relay.*")

  f:add("xap-header","source", "dbzoo.livebox.jeenode:kema6.relay.*")

  f:add("xap-header","class", "xapbsc.info")

  f:callback(function() anyOn(masterRelay) end)

end