How do I automatically add attributes showing the temperature difference?

Hi,
I have different types of thermostats in the house and would like to add comparable heating_needed and difference_to_outside_temp attributes that I can use in automations (some thermostats state they are in heat mode although the room temperature is abover the desired temperature). I’m just not getting it to work. Do I need to create new entities or can I add attributes to the existing thermostats? Can someone help me for this example:

(this thermostat is in heat mode, although it should not be. So I want to have a new value always showing “current_temperature - temperature” that I use in automations instead of the entity state itself (heat/off)…


hvac_modes: heat, off
min_temp: 8
max_temp: 28
preset_modes: eco, comfort
current_temperature: 19.5
temperature: 18
preset_mode: null
battery_low: false
battery_level: 60
holiday_mode: false
summer_mode: false
window_open: false
friendly_name: Zimmer 2 hinten
supported_features: 17

Thanks!
Jork

Manual customization allows you to add custom attributes to an existing entity. However, it’s not useful for your application because a custom attribute’s value can only be static (you want it to be calculated).

You will need to create a separate entity that allows you to compute the value of its state and its attributes. Those requirements are fulfilled by a Template Sensor.

I suggest creating a Template Sensor for each parameter you wish to compute.