Skip to content

Commit

Permalink
Changes to make room unit emulation work with version 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fredlcore committed Nov 20, 2024
1 parent 3c47622 commit 22b94eb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
/*
* Emulation of presence buttons for room units as well as DHW/TWW push functionality on selected pins.
* Buttons need to be connected to the pins defined in variable "button_on_pin" in BSB_LAN_custom_global.h
* Parameters 10102, 10103 and 10104 need to be copied from version 2.2.1's BSB_LAN_custom_defs.h and added to current BSB_LAN_custom_defs.h
* If these parameter numbers are already in use, changes need to be made to the parameter numbers in BSB_LAN_custom.h
* Note regarding to pins: On Arduino Due any Digital pins can be selected excluding 12, 16-21, 31, 33, 53.
* On ESP32, this depends on the model used.
* Make sure you aren't using pins which are already in use for sensors or change them accordingly.
*/

if (PressedButtons) {
for (uint8_t i = 0; i < 8; i++) {
switch (PressedButtons & (0x01 << i)) {
case TWW_PUSH_BUTTON_PRESSED:
strcpy(decodedTelegram.value, "1");
set(1603, decodedTelegram.value, true);
PressedButtons &= ~TWW_PUSH_BUTTON_PRESSED;
break;
case ROOM1_PRESENCE_BUTTON_PRESSED:
switchPresenceState(701, 10102);
PressedButtons &= ~ROOM1_PRESENCE_BUTTON_PRESSED;
break;
case ROOM2_PRESENCE_BUTTON_PRESSED:
switchPresenceState(1001, 10103);
PressedButtons &= ~ROOM2_PRESENCE_BUTTON_PRESSED;
break;
case ROOM3_PRESENCE_BUTTON_PRESSED:
switchPresenceState(1301, 10104);
PressedButtons &= ~ROOM3_PRESENCE_BUTTON_PRESSED;
break;
default: PressedButtons &= ~(0x01 << i); break; //clear unknown state
}
if (PressedButtons) {
for (uint8_t i = 0; i < 8; i++) {
switch (PressedButtons & (0x01 << i)) {
case TWW_PUSH_BUTTON_PRESSED:
set(10019, "1", true);
PressedButtons = PressedButtons & ~TWW_PUSH_BUTTON_PRESSED;
break;
case ROOM1_PRESENCE_BUTTON_PRESSED:
switchPresenceState(10110, 0);
PressedButtons = PressedButtons & ~ROOM1_PRESENCE_BUTTON_PRESSED;
break;
case ROOM2_PRESENCE_BUTTON_PRESSED:
switchPresenceState(10111, 1);
PressedButtons = PressedButtons & ~ROOM2_PRESENCE_BUTTON_PRESSED;
break;
case ROOM3_PRESENCE_BUTTON_PRESSED:
switchPresenceState(10112, 2);
PressedButtons = PressedButtons & ~ROOM3_PRESENCE_BUTTON_PRESSED;
break;
default: PressedButtons = PressedButtons & ~(0x01 << i); break; //clear unknown state
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* Emulation of presence buttons for room units as well as DHW/TWW push functionality on selected pins.
* Buttons need to be connected to the pins defined in variable "button_on_pin" in BSB_LAN_custom_global.h
* Parameters 10102, 10103 and 10104 need to be copied from version 2.2.1's BSB_LAN_custom_defs.h and added to current BSB_LAN_custom_defs.h
* If these parameter numbers are already in use, changes need to be made to the parameter numbers in BSB_LAN_custom.h
* Note regarding to pins: On Arduino Due any Digital pins can be selected excluding 12, 16-21, 31, 33, 53.
* On ESP32, this depends on the model used.
* Make sure you aren't using pins which are already in use for sensors or change them accordingly.
*/

uint8_t button_on_pin[4] = {0, 0, 0, 0}; // Order: TWW push, presence ROOM1, presence ROOM2, presence ROOM3

volatile byte PressedButtons = 0;
Expand All @@ -16,36 +15,28 @@ volatile byte PressedButtons = 0;
#define ROOM3_PRESENCE_BUTTON_PRESSED 8

void interruptHandlerTWWPush() {
PressedButtons |= TWW_PUSH_BUTTON_PRESSED;
PressedButtons = PressedButtons | TWW_PUSH_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM1() {
PressedButtons |= ROOM1_PRESENCE_BUTTON_PRESSED;
PressedButtons = PressedButtons | ROOM1_PRESENCE_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM2() {
PressedButtons |= ROOM2_PRESENCE_BUTTON_PRESSED;
PressedButtons = PressedButtons | ROOM2_PRESENCE_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM3() {
PressedButtons |= ROOM3_PRESENCE_BUTTON_PRESSED;
PressedButtons = PressedButtons | ROOM3_PRESENCE_BUTTON_PRESSED;
}

void switchPresenceState(uint16_t set_mode, uint16_t current_state) {
//RGT1 701, 10102
//RGT2 1001, 10103
//RGT3 1301, 10104
int state = 0;
char buf[9];
unsigned int i0, i1;
query(current_state);
strcpy(buf, "%02x%02x");
if (2 != sscanf(decodedTelegram.value, buf, &i0, &i1)) return;
if (i0 != 0x01) return; // 1 = Automatic
switch (i1) {
case 0x01: state = 0x02; break; //Automatic in Reduced mode -> Automatic Reduced pushed into Comfort
case 0x02: state = 0x01; break; //Automatic in Comfort mode -> Automatic Comfort pushed into Reduced
case 0x03: state = 0x02; break; //Automatic Comfort mode, but pushed into Reduced -> Automatic Comfort
case 0x04: state = 0x01; break; //Automatic Reduced mode, but pushed into Comfort -> Automatic Reduced
void switchPresenceState(uint16_t set_mode, uint16_t current_state_index) {
byte msg[33] = { 0 }; // response buffer
byte tx_msg[33] = { 0 }; // xmit buffer
if (bus->Send(TYPE_QUR, 0x2D3D0211 + (current_state_index << 24) , msg, tx_msg, 0, 0, true) != BUS_OK) return;
if (msg[bus->getPl_start()] != 0x01) return; // 1 = Automatic
switch (msg[bus->getPl_start() + 1]) {
case 0x01: set(set_mode, "2", true); break; //Automatic in Reduced mode -> Automatic Reduced pushed into Comfort
case 0x02: set(set_mode, "1", true); break; //Automatic in Comfort mode -> Automatic Comfort pushed into Reduced
case 0x03: set(set_mode, "2", true); break; //Automatic Comfort mode, but pushed into Reduced -> Automatic Comfort
case 0x04: set(set_mode, "1", true); break; //Automatic Reduced mode, but pushed into Comfort -> Automatic Reduced
default: return;
}
sprintf_P(buf, "%d", state);
set(set_mode, buf, true);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/*
* Emulation of presence buttons for room units as well as DHW/TWW push functionality on selected pins.
* Buttons need to be connected to the pins defined in variable "button_on_pin" in BSB_LAN_custom_global.h
* Parameters 10102, 10103 and 10104 need to be copied from version 2.2.1's BSB_LAN_custom_defs.h and added to current BSB_LAN_custom_defs.h
* If these parameter numbers are already in use, changes need to be made to the parameter numbers in BSB_LAN_custom.h
* Note regarding to pins: On Arduino Due any Digital pins can be selected excluding 12, 16-21, 31, 33, 53.
* On ESP32, this depends on the model used.
* Make sure you aren't using pins which are already in use for sensors or change them accordingly.
*/

if (button_on_pin[0]) {
pinMode(button_on_pin[0], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[0]), interruptHandlerTWWPush, FALLING); //TWW push button
}
if (button_on_pin[1]) {
pinMode(button_on_pin[1], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[1]), interruptHandlerPresenceROOM1, FALLING); //Presence ROOM 1 button
}
if (button_on_pin[2]) {
pinMode(button_on_pin[2], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[2]), interruptHandlerPresenceROOM2, FALLING); //Presence ROOM 2 button
}
if (button_on_pin[3]) {
pinMode(button_on_pin[3], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[3]), interruptHandlerPresenceROOM3, FALLING); //Presence ROOM 3 button
}
if (button_on_pin[0]) {
pinMode(button_on_pin[0], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[0]), interruptHandlerTWWPush, FALLING); //TWW push-button
}
if (button_on_pin[1]) {
pinMode(button_on_pin[1], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[1]), interruptHandlerPresenceROOM1, FALLING); //Presence ROOM 1 button
}
if (button_on_pin[2]) {
pinMode(button_on_pin[2], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[2]), interruptHandlerPresenceROOM2, FALLING); //Presence ROOM 2 button
}
if (button_on_pin[3]) {
pinMode(button_on_pin[3], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_on_pin[3]), interruptHandlerPresenceROOM3, FALLING); //Presence ROOM 3 button
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Pushbutton for TWW push and presence button function

### This code is outdated from version 3 onwards. It can still work if you copy and adjust the required parameters used in function `switchPresenceState` from version 2.2.1, but there is no support from our side. ###
# Push-button for TWW push and presence button function

The GPIO pins used for connecting the pushbuttons (one pin per pushbutton) must be set in `BSB_LAN_custom_global.h`.
You have to use digital pins for the push buttons, not analogue pins. Make sure that the pins you use are not used for other purposes (sometimes a pin may be accessible, but it is used internally). For Arduino Due-users: explicitly don’t use the pins 12, 16-21, 31, 33, 53!
You have to use digital pins for the push-buttons, not analogue pins. Make sure that the pins you use are not used for other purposes (sometimes a pin may be accessible, but it is used internally). For Arduino Due-users: explicitly don’t use the pins 12, 16-21, 31, 33, 53!

The pushbuttons needs to be connected between the 3.3V pin (NOT the 5V pin!) and the respective digital input pin. Additionally, a pull-down resistor (approx. 100kOhm) needs to be connected between the digital input pin and GND.
The push-buttons need to be connected between the 3.3V pin (NOT the 5V pin!) and the respective digital input pin. Additionally, a pull-down resistor (approx. 100kOhm) needs to be connected between the digital input pin and GND.
If you are not sure how to connect a pushbutton to an microcontroller, please have a look at the internet, where you can find countless examples.

If you disconnect the pushbutton(s) (e.g. because you don’t want to use them anymore) make sure that you set the corresponding pin to “0” in `BSB_LAN_custom_global.h` again and flash the changed configuration. Otherwise the input pin may still react in undefined ways.
Expand Down
12 changes: 5 additions & 7 deletions BSB_LAN/custom_functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BSB-LAN allows to add custom functions through the following files:

In this folder, we collect scripts which add a certain functionality that is too specific to be added to the core functionality of BSB-LAN, but can be added through BSB-LAN's custom functions scripts.
To use these scripts, you have to do two things:
1. Copy the files of the example you want to use to BSB-LAN's main directory (where also BSB_LAN.ino and BSB_LAN_config.h can be found).
1. Copy the files of the example you want to use to BSB-LAN's main directory (where also `BSB_LAN.ino` and `BSB_LAN_config.h` can be found).
2. Enable the CUSTOM_COMMANDS definement by removing the to leading slashes at the beginning of the line so that it looks like this:
`#define CUSTOM_COMMANDS`

Expand All @@ -21,16 +21,14 @@ This script reads the temperatures from two DHT22 sensors (one outside and one i

## Emulation of Room Unit and Presence Buttons

_The pushbutton functionality will need adjustments and is not compatible out-of-the-box from version 3 onwards._

With the setup of the BSB-LAN adapter a room unit can be emulated if you add one or more sensors and push buttons.
With these two sets of scripts, BSB-LAN can emulate a room unit if you add one or more sensors and push-buttons.
The following functions are implemented in the code:
* Emulation of Room Unit:
* Integration fo connected sensors for measuring and transmitting the room temperature(s) to the desired heating circuit(s)
* Emulation of Presence Buttons:
* Triggering a DHW push by using a pushbutton
* Using the presence function for the heating circuits 1-3 by using a pushbutton (automatic detection of the present state with the corresponding change between comfort and reduced mode in the automatic mode).
* Triggering a DHW push by using a push-button
* Using the presence function for the heating circuits 1-3 by using a push-button (automatic detection of the present state with the corresponding change between comfort and reduced mode in the automatic mode).

More details can be found in the README file in each folder.

## Map DS18B20 sensors to custom floats
Expand Down

0 comments on commit 22b94eb

Please sign in to comment.