Trigger based on result of comparison

HI,
I am trying to trigger a fan, eventually, but for now am trying to switch a lamp on based on the result of subtracting one humidity sensor from another.
I am using an Aeotec multi sensor in the bathroom and a Nest thermostat in the hallway (which does not seem to update very often) to determine if the humidity in the bathroom is higher than expected.
The code below has been used and does not show any config errors but the automation does not trigger.

alias: Bathroom high humidity
hide_entity: False
initial_state: ‘on’
trigger:
platform: template
value_template: “{{ states.bathroom_multisensor_relative_humidity.state | float - states.sensor.hallway_thermostat_humidity.state | float > 15 }}”
condition:
- condition: time
after: ‘05:30:00’
before: ‘23:00:00’
action:
service: scene.turn_on
entity_id: scene.spot1_colorloop

The formatting does not display correctly here but I cannot understand why this does not work, Can anyone out there help?

Thanks

Try creating a template binary sensor:

binary_sensor:
  - platform: template
    sensors:
      bathroom_high_humidity:
        friendly_name: "Bathroom high humidity"
        value_template: >-
          {{ (states.bathroom_multisensor_relative_humidity.state | float - states.sensor.hallway_thermostat_humidity.state | float) > 15  }}

You can then use that in the automation in the trigger. It’ll also avoid draining the performance of your system - template triggers without an entity_id are evaluated every time any entity updates - so multiple times per second.

Thanks, will give it a go.

Thanks for the help,
I have tried your suggestion but the binary sensors are not triggering. Have also tried to add a slider in to allow me to work out the best values for the automation.

Does anyone have any idea of what I am doing wrong here? Humidity normal is showing as permanently triggered while humidity high never triggers.

Thanks for any help offered.

binary_sensor:
  - platform: template
    sensors:
      bathroom_humidity_high:
        friendly_name: "Bathroom Humidity High"
        value_template: >-
          {{ (states.bathroom_multisensor_relative_humidity.state | float - states.sensor.hallway_thermostat_humidity.state | float) > states.input_number.fan_on | int  }}    
      bathroom_humidity_normal:
        friendly_name: "Bathroom Humidity Normal"
        value_template: >-
          {{ (states.bathroom_multisensor_relative_humidity.state | float - states.sensor.hallway_thermostat_humidity.state | float) < states.input_number.fan_off | int  }}

You even quoted the bit about formatting it correctly:

indent preformatted text by 4 spaces

Can you try editing and doing just that - or select the block of text and push the </> button on the text bar.

Finally got the formatting!
I have spotted one error in that I did not have the states.sensor.xxxxx before the bathroom multisensor.
Giving it a try now.

I think you need .state on the end of .fan_on and .fan_off

Thanks, its all a learning curve for me at the minute. But I am getting there slowly.

Appreciate your help, finally got it working as required.