New Commands: SH2, CS2, CH2

This Forum is about the Opentherm gateway (OTGW) from Schelte

Moderator: hvxl

Post Reply
rpav
Starting Member
Starting Member
Posts: 31
Joined: Sun Nov 15, 2015 8:55 pm

New Commands: SH2, CS2, CH2

Post by rpav »

Hi,
I believe there are a lot of boilers with two (relatively independent) heating circuits. Unfortunately, current version of OTmonitor can't control the second circuit behaviour, however it can show the sate of it properly.
We, the users of dual circuit boilers, will very appreciate if OTmonitor has three new commands:

SH2=temperature
Setpoint for Second Heating Circuit - Set the maximum heating setpoint for 2 circuit. This command is only available with boilers that support this function.
Examples: SH2=72.5, SH2=+20

CS2=temperature
Control Setpoint for Second Heating Circuit - Manipulate the control setpoint of 2 circuit being sent to the boiler. Set to 0 to pass along the value specified by the thermostat.
Example: CS2=45.8, CS2=0

CH2=state
Second Central Heating - Control the second CH enable status bit when overriding the control setpoint. By default the CH2 enable bit is set after a CS2 command with a value other than 0. With the CH2=0 and CH2=1 commands, the bit can be manipulated.
Example: CH2=0, CH2=1

I believe it couldn't be so difficult because all of them are variant of existing commands, that are already in the code.
Unfortunately, I have absolutely no experience of TCL. :( I'm sure I will spend a tons of hours to find the right pieces of code and to modify it to implement commands described.
Schelte, please, will you have time to make a patch that implements it? Please...

Thank you,
Roman
rpav
Starting Member
Starting Member
Posts: 31
Joined: Sun Nov 15, 2015 8:55 pm

Re: New Commands: SH2, CS2, CH2

Post by rpav »

Unfortunately, implementing new commands means to modify OTGW, firmware for PIC :oops:

Now I know it is not as easy as I thought. :(

But implementing it, will be still very appreciated :)

Revision of new command proposal:
S2=temperature
Setpoint for Second Heating Circuit - Set the maximum heating setpoint for 2 circuit. This command is only available with boilers that support this function.
Examples: S2=72.5, S2=+20

C2=temperature
Control Setpoint for Second Heating Circuit - Manipulate the control setpoint of 2 circuit being sent to the boiler. Set to 0 to pass along the value specified by the thermostat.
Example: C2=45.8, C2=0

H2=state
Second Central Heating - Control the second CH enable status bit when overriding the control setpoint. By default the H2 enable bit is set after a C2 command with a value other than 0. With the H2=0 and H2=1 commands, the bit can be manipulated.
Example: H2=0, H2=1
rpav
Starting Member
Starting Member
Posts: 31
Joined: Sun Nov 15, 2015 8:55 pm

Re: New Commands: SH2, CS2, CH2

Post by rpav »

Schelte,
is there any chance you will think about implementing these new commands?
Since the code is in assembler, there is not many people which are able to do it quickly.
Thank you for your answer,

Roman
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: New Commands: SH2, CS2, CH2

Post by hvxl »

Oh I thought about it when you brought it up in January. But there's no way it'll fit in the PIC without removing some other features. So, whoever wants to have this will have to decide which existing functionality they can live without, rip that out and add this in its place. I can't do that, because there will always be people using those features.
Schelte
rpav
Starting Member
Starting Member
Posts: 31
Joined: Sun Nov 15, 2015 8:55 pm

Re: New Commands: SH2, CS2, CH2

Post by rpav »

Thank you very much for the answer.

How big the problem with memory availability is?
Is it possible to implement at least C2(control setpoint) and H2 (enable status)?

If not, what about GB=5. GB=6 and SB (GPIO funtions HOME, AWAY and SetBack temp) commands? Should those be the candidates for substitution? What is the typical user story that use it?

Thank you,
Roman
foobar
Starting Member
Starting Member
Posts: 2
Joined: Sun Jan 19, 2020 9:02 pm

Re: New Commands: SH2, CS2, CH2

Post by foobar »

Hello everyone, Schelte!

I'm in the same situation as Roman. A boiler + thermostat with two circuits, one for the floor heating, one for the radiators.
I would also appreciate having this functionality available.
Could you please explain which parts of the code need to be changed / added? Then I would try to change it myself. Since I am not a professional in assembler, this would be a huge challenge for me without a guide.

Thanks in advance,
Frank
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: New Commands: SH2, CS2, CH2

Post by hvxl »

The trick I used to save space for the command parsing is to make a jump table (SerialCmdTable) based on the XOR of the ASCII code of the two letters of the command. This calculation produces a value between 0 and 31. Once that first selection has been made, only one of the two characters still needs to be checked to know which command was given.

For example, a new 'FB' command would lead to an offset of 4 (70 ^ 66) in the jump table. So this new command would need to be handled by the code at SerialCmd04. There, checks are already in place for commands starting with 'V' (which can only be 'VR') and 'S' ('SW'). Again, XOR instructions are used to save a memory word compared to straight-forward comparisons. So you would add an "xorlw 'S' ^ 'F'" instruction just before the "retlw CommandNG" to check for the 'FB' command.

Hopefully you understand from this explanation that the command can only consist of two letters, otherwise this method will not work. Commands like C2 and H2 are therefor not possible with this scheme.

The OpenTherm messages are handled via the jump table "messagetable". For CH2 you would have to change the "goto FakeResponse" instruction at offset 8 in the table to "goto MessageID8", and provide the appropriate code labeled with MessageID8. Beware that this code will be called for both the request and the response.

To add the CH2 enable bit to the status message, you have to make some modifications to the code at the MessageID0 label.

For more information, read chapter 16 of the PIC16F88 data sheet to understand what each assembly instruction does and study the gateway source code. I have attempted to explain in the comments how things are supposed to work.
Schelte
foobar
Starting Member
Starting Member
Posts: 2
Joined: Sun Jan 19, 2020 9:02 pm

Re: New Commands: SH2, CS2, CH2

Post by foobar »

Thanks a lot for all the guidance! Will see what I can do. I already understood some parts of it.
Just one basic question: How do I know if the fw with modifications fits to the space of the PIC? You said some functionality which is now existing has to be removed to make it fit. Is it just the size of the image in bytes?
The current gateway.hex is ~23kb. What is the maximum size?

Thanks again!

Best,
Frank
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: New Commands: SH2, CS2, CH2

Post by hvxl »

When building the project, the linker will tell you if it can't fit the code in the selected PIC.

It's not the size of the hex file that is important. The critical measurement is the number of code words. Currently 3916 of the available 4096 words have been used. So there are only 180 left. Also 361 of the available 368 bytes of RAM have already been claimed.
Schelte
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: New Commands: SH2, CS2, CH2

Post by hvxl »

The C2 and H2 commands you requested have been implemented in OTGW firmware version 5.0. I didn't implement S2, mostly because I couldn't find a matching message ID for that function.
Schelte
TheSpanishInq
Starting Member
Starting Member
Posts: 6
Joined: Sun Jan 31, 2021 3:46 pm

Re: New Commands: SH2, CS2, CH2

Post by TheSpanishInq »

FYI
If anyone want's to test this with Domoticz, you can pull a separate branch. Details can be found here.
mvn23
Starting Member
Starting Member
Posts: 6
Joined: Tue Feb 02, 2021 4:13 pm

Re: New Commands: SH2, CS2, CH2

Post by mvn23 »

hvxl wrote:The C2 and H2 commands you requested have been implemented in OTGW firmware version 5.0. I didn't implement S2, mostly because I couldn't find a matching message ID for that function.
While implementing the new features into pyotgw I noticed that these new commands don't respond with the usual format (e.g. H2=1 responds with just 1 instead of H2: 1). Are there any plans to fix this in the future?
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: New Commands: SH2, CS2, CH2

Post by hvxl »

As I wasn't aware of the problem, I didn't have any plans to fix it. But I admit this should be fixed.
Schelte
Post Reply

Return to “Opentherm Gateway Forum”