Also I need to check for an input boolean and if that is true and the case is 636, then the return value should be changed to something else instead of the case above.
A dictionary’s get method can accept a second argument that represent what to report when the specified key does not exist in the dictionary.
In the following example, if the value of states('sensor.device') does not exist in the dictionary, the get method will report unknown.
template:
- sensor:
- name: "Device sensor"
state: "{{ {'3722': 'string1', '33': 'string2'}.get(states('sensor.device'), 'unknown') }}"
^^^^^^^
This will be the result
if the value of sensor.device
is not found in the dictionary