Either / OR script

8 replies [Last post]
kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013

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.

I have 4 script/applets (thanks to garry) running 4 different zones which work fine on their own, but this has its limitations.  

What I would like is a very simple script/applet that works as follows:-

If any relay on my RelayNode4{instance="jeenode:kema6",endpoints={relay1=1,relay2=1,relay3=1,relay4=1}, ttl=900}, -(4 ZONES)

is on, then turn on  Relay1 (dbzoo.livebox.Controller:relay.1). 

Any help whatsoever would be very much appreciated.

 Kema...

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Kema,  Did you have a look at

Kema,  Did you have a look at the sample where relays are bound together so they stay in sync?

https://github.com/dbzoo/hah/blob/master/userapps/hah/xap-plugboard/samples/bindRelaysApplet.lua

Doing more would require I wrap my head around my code and figure this out as its been a while.

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Hi Brett many thanks for your

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

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I'll fire up my trusty HAH

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.

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Brilliant

Brett fantastic, really apprechiate your help.

 

Many Thanks

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Some scripts.  Tee applet is

Some scripts.  The applet is what you want.  I'm also attaching my endpoint simulator that I used to verify the applet was working.

AttachmentSize
masterSlaveApplet.lua 1.69 KB
masterSlaveEndpointSim.lua 723 bytes
kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Hi Brett many thanks for your

 

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

 

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Those changes look correct

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.

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Hi Brett, yes I had made the

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

Hardware Info