Sensor template based on other sensor value

Consider the following:

The sensor below will have the values 0,1,2 or 3.

  • platform: mqtt
    state_topic: “thermostat”
    name: “Thermostat Operating Mode”
    value_template: “{{ value_json.tmode}”

0: off
1: heat
2: cool
3: auto

Based on the value of the sensor above, I want to create another sensor to tell me the set point of the current mode. If the thermostat is in cool mode, it will publish a message with a json key of tcool. Conversely, heat will produce theat.

I want to have one standard “thermostat set point” sensor that produces the set point regardless of whether cool or heat mode is selected. Any ideas? Does this make sense?

I was thinking something with a template sensor might work, but am unsure.

OR simply:

If the mode sensor == cool, the “Thermostat Setpoint” value template will be “{{ value_json.t_cool }}”

If the mode sensor == heat, the “Thermostat Setpoint” value template will be “{{ value_json.t_heat }}”