Creating a sensor whose value is synthesised from other sensors

I want to be able to reference a numeric calculation based on multiple numeric sensors in triggers and conditions. For example:

numeric_sensor_a, numeric_sensor_b and numeric_sensor_c

I want to be able to trigger if (a - b - c ) > some value (or <, = some value) and to also perform a similar check in a condition. Ideally I’d like to be able to define a synthetic sensor D which returns the value (a - b - c) which I can then use as required.

I’m sure this must be possible; can anyone give me any pointers or even where to look in the documentation?

A Template Sensor is meant for that purpose.

You can define one via YAML or the UI as a Template Sensor helper.

Alternately, you can use a Template Trigger if the sole purpose of the calculation is to trigger an automation.

Here’s an example of how to use Home Assistant’s templating language (Jinja2) to perform calculations.

{% set a = states('sensor.one') | float(0) %}
{% set b = states('sensor.two') | float(0) %}
{% set c = states('sensor.three') | float(0) %}
{{ 50 < a - b - c <= 100 }}