Reflex conditionals to create a Holiday Mode temperatue setting

We've had an Idratek temperature module (DTS) and relay module (DRB) operating for the past few months as a replacement for the traditional heating thermostat. Whilst this is very very much using only a fraction of what the equipment can do, this was a way to "test the water" so to speak.

They have been operating in "reflex" mode most of the time -- where each module has it's own simple 'program' of triggers & events - in our case, the temperature module has events programmed to turn the relay on or off based on temperatue triggers ... so temp goes high, relay goes off; temp goes low, relay goes on. Of course, the relay is connected to the heating's 'call for heat'.

When we're away, there is no point heating the house to the usual 18.5C. Via the PC & Cortex I can change the set temperature but I wanted a way to do this without needing a PC. What I wanted, was to press a button to set the house into "unoccupied" mode where it would heat to a set temperature (say 14C). Another press of the button would return the settings to normal.

The temperature module (DTS) already has a reflex program to tell the heating control relay module (DRB) to turn on when the temperature is below threshold and off again when it gets above. Trial and error showed me to set set the triggers at least 0.25C apart - so in normal operation they are set at below 18.0 to turn on the heating and above 18.5 to turn off.

So rather than do any temperature setting, this "Holiday Mode" program simply needs to manipulate the threshold values on the DTS to adjust them from 18.0/18.5 to 14.0/14.5 and vica versa.

The DRB module will be set up so that a button on the DRB triggers this by sending new threshold value to the DTS.

First, the DRB needs to become "stateful" - ie it needs to 'know' (and remember) if it is set into "Normal Mode" or "Holiday Mode". This 'state' can be held in the UDRCF byte in the DRB. This seems to be a user-available 8-bit byte that can be written to and also evaluated. The evaluation will be important later, but first how to write to it:

The following
0C = Reflex Related / Modify UDRCF
3 = Op = Toggle (0 = write, 1 = set, 2 = clear)
0 = "Group 0 available only"
01 = Modify bit 0

This packet can be tested from Cortex using the Communications pane command line - before entering the above instructions, you need to enter a header to send the packet to a DRB module:
ie:
FA = Packet to Network Implicit ID
90 = Point-to-Point
XXXX = Select DRB from the list (where XXXX is the network address of your DRB)
0400 = No Ack Required
..... Packet as above .....

Everytime the selected button is pressed on the DRB, the reflex action should include to toggle the UDRCF... Normal mode -> Holiday mode -> Normal mode -> Holiday mode etc,...

So this provides the "statefulness". Now to apply this to send the correct set of threshold temperatures to the DTS:

Sending the correct threshold values to the DTS

If you're familiar with any kind of software language then you would recognise the idea of the pseudo code for what we want to achieve:

1] IF (UDRCF is set) SEND "Holiday mode" thresholds
2] IF (UDRCF is not set) SEND "Normal mode" thresholds
3] TOGGLE UDRCF <------- (this is the bit we did in the first step)

The IF conditionals are achieved with the instructions E2 and E3 followed by Par1 and Par2.

If the conditional is TRUE, the remainder of the packet is executed. If the conditional is FALSE, the remainder of the packet is skipped.
E2 = Bitwise AND: ((Par 1) AND Par 2 = Par 2)
E3 = NOT Bitwise AND: ((Par 1) AND Par 2 = Par 2)

For both, Par 1 is given as the "address of the byte to be tested". At this point, Cortex (v22 & v23) offers the value 2E as the UDRCF address, which is apparently incorrect, value 00 should be used for Par 1 instead. Par 2 is given as 01 (bit 0, the same bit we selected to 'toggle').

The conditional "Bitwise AND: ((Par 1) AND Par 2 = Par 2)" operates as a mask so th effect is to be TRUE (and execute the remainder of the packet) if the bit selected in Par 2 is present in the UDRCF, otherwise FALSE.

Going back to our pseudo code for the two IFs, we can now replace the IFs with these E2/E3 conditionals:

1] IF (UDRCF is set) SEND "Holiday mode" thresholds
becomes
E2 00 01 < SEND "Normal mode" thresholds >

2] IF (UDRCF is not set) SEND "Normal mode" thresholds
becomes
E3 00 01 < SEND "Holiday mode" thresholds >

Now, if you're smart you'll have realised that each mode requires two thresholds - the Above and Below thresholds so we should re-write the pseudo code:

1] IF (UDRCF is set) SEND "Holiday mode" BELOW threshold
2] IF (UDRCF is set) SEND "Holiday mode" ABOVE threshold
3] IF (UDRCF is not set) SEND "Normal mode" BELOW threshold
4] IF (UDRCF is not set) SEND "Normal mode" ABOVE threshold
5] TOGGLE UDRCF <------- (this is the bit we did in the first step)

The next step is to define the actual packets to be sent by the DRB to the DTS. As before, this packet can be derived & tested via the command line in Cortex:
FF = Send to network, Explicit
90 = Point-to-point (hint, not broadcast to all!)
FFFF = Source node address (apparently with FFFF, the sending module will insert it's own address, saving us some work)
XXXX = Destination node address -- the address of the DTS we are re-setting
4400 = Ack
12 = Parameter, Set Parameter
07 = Temperature functions
0 = Write
2 = <= threshold (other options include the >= threshold)
0E00 = Actual threshold value (14C)

Okay, so there's a lot here. The first 6 lines are setting up the packet - point to point, source, destination etc,. The last 5 are the specific and interesting parts. To work out the hex value for the temperature I cheated and used the Reflex dialog which has a decimal entry box and an adjacent display of the hex.

So the packet to conditionally set "Holiday mode" for the <= threshold becomes:
E20001 FF 90 FFFF XXXX 4400 12 07 0 2 0E00 {equated to Pseudo code line 1}

You can see how the other 3 conditionals will be very similar ....

E20001 FF 90 FFFF XXXX 4400 12 07 0 3 0E80 {Pseudo code line 2}
E30001 FF 90 FFFF XXXX 4400 12 07 0 2 1200 {Pseudo code line 3}
E30001 FF 90 FFFF XXXX 4400 12 07 0 3 1280 {Pseudo code line 4}

For a little embelishment I wanted the LED adjacent to the button to reflect if "holiday mode" was enabled, so I added a further two packets:
E20001 3C 01 02 {Set LED2}
E30001 3C 02 02 {Clear LED2}

So the final reflex program that is triggered by the "Holiday mode" button being pressed becomes:
E20001 FF 90 FFFF XXXX 4400 12 07 0 2 0E00 {Holiday mode below threshold}
E20001 FF 90 FFFF XXXX 4400 12 07 0 3 0E80 {Holiday mode above threshold}
E30001 FF 90 FFFF XXXX 4400 12 07 0 2 1200 {Normal mode below threshold}
E30001 FF 90 FFFF XXXX 4400 12 07 0 3 1280 {Normal mode above threshold}
E20001 3C 01 02 {Set LED2}
E30001 3C 02 02 {Clear LED2}
0C3001 {Toggle UDRCF}

The packet ordering isn't important -- so long as the Toggle packet is either at the start or the end of the list.

With the packets "designed", the final stage was to define them in Cortex and the program the DRB module. This was done the usual way by defining each packet individually, giving it a name, then building the DRB button's reflex to call each packets in turn.

Et Voila ! "Holiday mode" button !!