Using sensor output in a value template within an automation

I have a simple automation for my bathroom fan that it turns the fan on above a fixed humidity value and off below a different fixed humidity value. It was raining today and, the ambient humidity having gone up, the fan wouldn’t shut off. So I should use the humidity from my home thermostat as a baseline to turn the fan on and off and it would appear that a value_template is the way to do it within the automation in the GUI.

But I’m stuck on the syntax for asking to trigger on a minimum difference between two sensors.

The humidity in the bathroom is given by the entity sensor.aqara_th_mb_humidity whereas the house humidity is given by sensor.bedrooms_hallway_humidity

Should this work? I don’t seem to be able to test it in Developer Tools → Template and am afraid to put it into the automations.yaml without testing

    value_template: '{{sensor.aqara_th_mb_humidity - sensor.bedrooms_hallway_humidity}}'
    above: '10'

This should work:

trigger:
  - platform: numeric_state
    entity_id: sensor.aqara_th_mb_humidity
    value_template: '{{ state.state|float - 10 }}'
    above: sensor.bedrooms_hallway_humidity

I’ve put it into the automation and will test it during my morning shower!

Thanks

@Didgeridrew

It took me a while to test this since I had to rebuild my HA instance but it worked!

Thanks