Combine 3 modbus registers with one gpio input to make a logic

Hello
I'm new here, first of all for my poor english! I'm studying to do a simple logic where I read some value as temperature, heat/cool value and one gpio input and I'm trying to combine in this way:
If heat and gpio is up copy the set point and add 2 degree to set point command if heating mode and till gpio is up, after gpio become down send the previous value read before gpio input was up.
the opposite for calling mode. This is a simple logic for connect the photovoltaic to climate.
thank you in advance and best regards
luca